cars.core.geometry.abstract_geometry
this module contains the abstract geometry class to use in the geometry plugins
Module Contents
Classes
AbstractGeometry |
Functions
|
Transform min max index to position min max |
|
Transform min max position to index min max |
- class cars.core.geometry.abstract_geometry.AbstractGeometry(geometry_plugin, dem=None, geoid=None, default_alt=None, **kwargs)
AbstractGeometry
- available_plugins: Dict
- classmethod register_subclass(short_name: str)
Allows to register the subclass with its short name :param short_name: the subclass to be registered :type short_name: string
- abstract static 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
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
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]
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
By default return the geomodel This method can be overloaded by plugins to load geomodel in memory
:param geomodel
- static matches_to_sensor_coords(grid1: Union[str, cars.data_structures.cars_dataset.CarsDataset], grid2: Union[str, cars.data_structures.cars_dataset.CarsDataset], matches: numpy.ndarray, matches_type: str, matches_msk: numpy.ndarray = None, ul_matches_shift: Tuple[int, int] = None) Tuple[numpy.ndarray, numpy.ndarray]
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.
- static sensor_position_from_grid(grid: Union[str, cars.data_structures.cars_dataset.CarsDataset], positions: numpy.ndarray) numpy.ndarray
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).
- 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).
- static epipolar_position_from_grid(grid, sensor_positions, step=30)
Compute epipolar position from grid
- Parameters
grid – epipolar grid
sensor_positions – sensor positions
step – step of grid interpolator
:return epipolar positions
- static transform_matches_from_grids(matches_array, grid_left, grid_right, new_grid_left, new_grid_right)
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
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
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
- sensors_arrangement_left_right(sensor1, sensor2, geomodel1, geomodel2, grid_left, grid_right)
Determine the arrangement of sensors, either: (double slashes represent Lines Of Sight) +———————+———————+ | Arrangement 1 | Arrangement 2 | | sensor1 sensor2 | sensor2 sensor1 | | // | // // | | // | // // | | // <– z_2 | z_1 –> // // | | // | // | | / <– z_1 | z_2 –> / | +———————+———————+ This allows to know if a lower disparity corresponds to a lower or higher hgt. It depends on the image pairing and geometrical models. A fake triangulation determines z_1 and z_2. If z_1 < z_2 then the sensors are in arrangement 1 If z_2 < z_1 then the sensors are in arrangement 2
- 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
grid1 – path or dataset for epipolar grid of sensor1
grid2 – path or dataset for epipolar grid of sensor2
- Returns
boolean indicating if sensors are in arrangement 1 or not
- image_envelope(sensor, geomodel, shp=None)
Export the image footprint to a shapefile
- Parameters
sensor – path to sensor image
geomodel – path and attributes for geometrical model
shp – Path to the output shapefile
- cars.core.geometry.abstract_geometry.min_max_to_physical_min_max(xmin, xmax, ymin, ymax, transform)
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)
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)