cars.core.geometry.abstract_geometry

this module contains the abstract geometry class to use in the geometry plugins

Module Contents

Classes

AbstractGeometry

AbstractGeometry

Functions

min_max_to_physical_min_max(xmin, xmax, ymin, ymax, ...)

Transform min max index to position min max

min_max_to_index_min_max(xmin, xmax, ymin, ymax, transform)

Transform min max position to index min max

class cars.core.geometry.abstract_geometry.AbstractGeometry(geometry_plugin_conf, dem=None, geoid=None, default_alt=None, **kwargs)[source]

AbstractGeometry

available_plugins: Dict
classmethod register_subclass(short_name: str)[source]

Allows to register the subclass with its short name :param short_name: the subclass to be registered :type short_name: string

check_conf(conf)[source]

Check configuration

Parameters

conf (str or dict) – configuration to check

Returns

full dict

Return type

dict

abstract triangulate(sensor1, sensor2, geomodel1, geomodel2, mode: str, matches: Union[xarray.Dataset, numpy.ndarray], grid1: str, grid2: str, roi_key: Union[None, str] = None) numpy.ndarray[source]

Performs triangulation from cars disparity or matches dataset

Parameters
  • sensor1 – path to left sensor image

  • sensor2 – path to right sensor image

  • geomodel1 – path and attributes for left geomodel

  • geomodel2 – path and attributes for right geomodel

  • mode – triangulation mode (constants.DISP_MODE or constants.MATCHES)

  • matches – cars disparity dataset or matches as numpy array

  • grid1 – path to epipolar grid of img1

  • grid2 – path to epipolar grid of image 2

  • roi_key – dataset roi to use (can be cst.ROI or cst.ROI_WITH_MARGINS)

Returns

the long/lat/height numpy array in output of the triangulation

abstract static check_product_consistency(sensor: str, geomodel: str, **kwargs) bool[source]

Test if the product is readable by the geometry plugin

Parameters
  • sensor – path to sensor image

  • geomodel – path to geomodel

Returns

True if the products are readable, False otherwise

abstract generate_epipolar_grids(sensor1, sensor2, geomodel1, geomodel2, epipolar_step: int = 30) Tuple[numpy.ndarray, numpy.ndarray, List[float], List[float], List[int], float][source]

Computes the left and right epipolar grids

Parameters
  • sensor1 – path to left sensor image

  • sensor2 – path to right sensor image

  • geomodel1 – path and attributes for left geomodel

  • geomodel2 – path and attributes for right geomodel

  • epipolar_step – step to use to construct the epipolar grids

Returns

Tuple composed of :

  • the left epipolar grid as a numpy array

  • the right epipolar grid as a numpy array

  • the left grid origin as a list of float

  • the left grid spacing as a list of float

  • the epipolar image size as a list of int (x-axis size is given with the index 0, y-axis size with index 1)

  • the disparity to altitude ratio as a float

load_geomodel(geomodel: dict) dict[source]

By default return the geomodel This method can be overloaded by plugins to load geomodel in memory

:param geomodel

matches_to_sensor_coords(grid1: Union[str, cars.data_structures.cars_dataset.CarsDataset, shareloc.geofunctions.rectification_grid.RectificationGrid], grid2: Union[str, cars.data_structures.cars_dataset.CarsDataset, shareloc.geofunctions.rectification_grid.RectificationGrid], matches: numpy.ndarray, matches_type: str, matches_msk: numpy.ndarray = None, ul_matches_shift: Tuple[int, int] = None) Tuple[numpy.ndarray, numpy.ndarray][source]

Convert matches (sparse or dense matches) given in epipolar coordinates to sensor coordinates. This function is available for plugins if it requires matches in sensor coordinates to perform the triangulation.

This function returns a tuple composed of the matches left and right sensor coordinates as numpy arrays. For each original image, the sensor coordinates are arranged as follows :

  • if the matches are a vector of matching points: a numpy array of size [number of matches, 2]. The last index indicates the ‘x’ coordinate(last index set to 0) or the ‘y’ coordinate (last index set to 1).

  • if matches is a cars disparity dataset: a numpy array of size [nb_epipolar_line, nb_epipolar_col, 2]. Where [nb_epipolar_line, nb_epipolar_col] is the size of the disparity map. The last index indicates the ‘x’ coordinate (last index set to 0) or the ‘y’ coordinate (last index set to 1).

Parameters
  • grid1 – path to epipolar grid of image 1

  • grid2 – path to epipolar grid of image 2

  • matches – cars disparity dataset or matches as numpy array

  • matches_type – matches type (cst.DISP_MODE or cst.MATCHES)

  • matches_msk – matches mask to provide for cst.DISP_MODE

  • ul_matches_shift – coordinates (x, y) of the upper left corner of the matches map (for cst.DISP_MODE) in the original epipolar geometry (use this if the map have been cropped)

Returns

a tuple of numpy array. The first array corresponds to the left matches in sensor coordinates, the second one is the right matches in sensor coordinates.

sensor_position_from_grid(grid: Union[str, cars.data_structures.cars_dataset.CarsDataset, shareloc.geofunctions.rectification_grid.RectificationGrid], positions: numpy.ndarray) numpy.ndarray[source]

Interpolate the positions given as inputs using the grid

Parameters
  • grid – path to epipolar grid, or numpy array

  • positions – epipolar positions to interpolate given as a numpy array of size [number of points, 2]. The last index indicates the ‘x’ coordinate (last index set to 0) or the ‘y’ coordinate (last index set to 1).

  • interpolator – interpolator to use

Returns

sensors positions as a numpy array of size [number of points, 2]. The last index indicates the ‘x’ coordinate (last index set to 0) or the ‘y’ coordinate (last index set to 1).

epipolar_position_from_grid(grid, sensor_positions, step=30)[source]

Compute epipolar position from grid

Parameters
  • grid – epipolar grid

  • sensor_positions – sensor positions

  • step – step of grid interpolator

:return epipolar positions

transform_matches_from_grids(matches_array, grid_left, grid_right, new_grid_left, new_grid_right)[source]

Transform epipolar matches with grid transformation

Parameters
  • grid_left – path to epipolar grid of image 1

  • grid_left – path to epipolar grid of image 2

  • new_grid_left – path to epipolar grid of image 1

  • new_grid_right – path to epipolar grid of image 2

  • matches – cars disparity dataset or matches as numpy array

abstract direct_loc(sensor, geomodel, x_coord: numpy.array, y_coord: numpy.array, z_coord: numpy.array = None) numpy.ndarray[source]

For a given image points list, compute the latitudes, longitudes, altitudes

Advice: to be sure, use x,y,z list inputs only

Parameters
  • sensor – path to sensor image

  • geomodel – path and attributes for geomodel

  • x_coord – X Coordinates list in input image sensor

  • y_coord – Y Coordinate list in input image sensor

  • z_coord – Z Altitude list coordinate to take the image

Returns

Latitude, Longitude, Altitude coordinates list as a numpy array

abstract inverse_loc(sensor, geomodel, lat_coord: numpy.array, lon_coord: numpy.array, z_coord: numpy.array = None) numpy.ndarray[source]

For a given image points list, compute the latitudes, longitudes, altitudes

Advice: to be sure, use x,y,z list inputs only

Parameters
  • sensor – path to sensor image

  • geomodel – path and attributes for geomodel

  • lat_coord – latitute Coordinate list

  • lon_coord – longitude Coordinates list

  • z_coord – Z Altitude list

Returns

X / Y / Z Coordinates list in input image as a numpy array

image_envelope(sensor, geomodel, out_path=None, out_driver='ESRI Shapefile')[source]

Export the image footprint to a vector file

Parameters
  • sensor – path to sensor image

  • geomodel – path and attributes for geometrical model

  • out_path – Path to the output vector file

  • out_driver – OGR driver to use to write output file

cars.core.geometry.abstract_geometry.min_max_to_physical_min_max(xmin, xmax, ymin, ymax, transform)[source]

Transform min max index to position min max

Parameters
  • xmin (int) – xmin

  • xmax (int) – xmax

  • ymin (int) – ymin

  • ymax (int) – ymax

  • transform (Affine) – transform

Returns

xmin, xmax, ymin, ymax

Return type

list(int)

cars.core.geometry.abstract_geometry.min_max_to_index_min_max(xmin, xmax, ymin, ymax, transform)[source]

Transform min max position to index min max

Parameters
  • xmin (int) – xmin

  • xmax (int) – xmax

  • ymin (int) – ymin

  • ymax (int) – ymax

  • transform (Affine) – transform

Returns

xmin, xmax, ymin, ymax

Return type

list(int)