Skip to content

Commit

Permalink
Merge branch '972-ajout-de-donnees-auxiliaire-depuis-le-lidar' into '…
Browse files Browse the repository at this point in the history
…master'

Resolve "Ajout de données auxiliaire depuis le lidar"

Closes #972

See merge request 3d/cars-park/cars!804
  • Loading branch information
dyoussef committed Feb 19, 2025
2 parents 1c5fa59 + 00e5026 commit c0d3435
Show file tree
Hide file tree
Showing 8 changed files with 356 additions and 23 deletions.
143 changes: 139 additions & 4 deletions cars/applications/ground_truth_reprojection/direct_localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@
import cars.orchestrator.orchestrator as ocht
from cars.applications.ground_truth_reprojection import (
ground_truth_reprojection,
ground_truth_reprojection_tools,
)
from cars.applications.ground_truth_reprojection import (
ground_truth_reprojection_tools as gnd_truth_tools,
)

# CARS imports
from cars.core import constants as cst
from cars.core import inputs
from cars.core.utils import safe_makedirs
from cars.data_structures import cars_dataset
from cars.pipelines.parameters import sensor_inputs_constants as sens_cst
Expand Down Expand Up @@ -122,6 +125,8 @@ def run( # noqa: C901
geom_plugin,
geom_plugin_dem_median,
disp_to_alt_ratio,
auxiliary_values,
auxiliary_interp,
orchestrator=None,
pair_folder=None,
pair_key="PAIR_0",
Expand Down Expand Up @@ -248,6 +253,46 @@ def run( # noqa: C901
cars_ds_name="epipolar_disparity_ground_truth",
)

# Save all file that are in inputs
if auxiliary_values is not None:
for key in auxiliary_values.keys():
if key in (cst.DSM_COLOR, cst.DSM_WEIGHTS_SUM):
option = False
else:
option = True

out_file_left_name = os.path.join(
pair_folder, key + "_left_epipolar.tif"
)

orchestrator.add_to_save_lists(
out_file_left_name,
key,
epi_disparity_ground_truth_left,
dtype=inputs.rasterio_get_dtype(auxiliary_values[key]),
nodata=inputs.rasterio_get_nodata(
auxiliary_values[key]
),
cars_ds_name=key,
optional_data=option,
)

out_file_right_name = os.path.join(
pair_folder, key + "_right_epipolar.tif"
)

orchestrator.add_to_save_lists(
out_file_right_name,
key,
epi_disp_ground_truth_right,
dtype=inputs.rasterio_get_dtype(auxiliary_values[key]),
nodata=inputs.rasterio_get_nodata(
auxiliary_values[key]
),
cars_ds_name=key,
optional_data=option,
)

# Get saving infos in order to save tiles when they are computed
[saving_infos_epi_left] = self.orchestrator.get_saving_infos(
[epi_disparity_ground_truth_left]
Expand Down Expand Up @@ -283,6 +328,8 @@ def run( # noqa: C901
"epipolar",
full_saving_info_left,
epi_disparity_ground_truth_left.tiling_grid[row, col],
auxiliary_values,
auxiliary_interp,
geom_plugin_dem_median=geom_plugin_dem_median,
window_dict=(
epi_disparity_ground_truth_left.get_window_as_dict(
Expand All @@ -303,6 +350,8 @@ def run( # noqa: C901
"epipolar",
full_saving_info_right,
epi_disp_ground_truth_right.tiling_grid[row, col],
auxiliary_values,
auxiliary_interp,
geom_plugin_dem_median=geom_plugin_dem_median,
reverse=True,
window_dict=(
Expand Down Expand Up @@ -342,6 +391,46 @@ def run( # noqa: C901
cars_ds_name="sensor_dsm_ground_truth_right",
)

# Save all file that are in inputs
if auxiliary_values is not None:
for key in auxiliary_values.keys():
if key in (cst.DSM_COLOR, cst.DSM_WEIGHTS_SUM):
option = False
else:
option = True

out_file_left_name = os.path.join(
pair_folder, key + "_left_sensor.tif"
)

orchestrator.add_to_save_lists(
out_file_left_name,
key,
sensor_dsm_gt_left,
dtype=inputs.rasterio_get_dtype(auxiliary_values[key]),
nodata=inputs.rasterio_get_nodata(
auxiliary_values[key]
),
cars_ds_name=key,
optional_data=option,
)

out_file_right_name = os.path.join(
pair_folder, key + "_right_sensor.tif"
)

orchestrator.add_to_save_lists(
out_file_right_name,
key,
sensor_dsm_gt_right,
dtype=inputs.rasterio_get_dtype(auxiliary_values[key]),
nodata=inputs.rasterio_get_nodata(
auxiliary_values[key]
),
cars_ds_name=key,
optional_data=option,
)

# Get saving infos in order to save tiles when they are computed
[saving_infos_sensor_left] = self.orchestrator.get_saving_infos(
[sensor_dsm_gt_left]
Expand All @@ -368,6 +457,8 @@ def run( # noqa: C901
"sensor",
full_saving_info_left,
sensor_dsm_gt_left.tiling_grid[row, col],
auxiliary_values,
auxiliary_interp,
raster_profile=raster_profile_left,
window_dict=sensor_dsm_gt_left.get_window_as_dict(
row, col
Expand All @@ -392,6 +483,8 @@ def run( # noqa: C901
"sensor",
full_saving_info_right,
sensor_dsm_gt_right.tiling_grid[row, col],
auxiliary_values,
auxiliary_interp,
raster_profile=raster_profile_right,
window_dict=sensor_dsm_gt_right.get_window_as_dict(
row, col
Expand All @@ -407,6 +500,8 @@ def maps_generation_wrapper(
target,
saving_infos,
window,
auxiliary_values,
auxiliary_interp,
raster_profile=None,
geom_plugin_dem_median=None,
reverse=False,
Expand All @@ -415,8 +510,6 @@ def maps_generation_wrapper(
"""
Computes ground truth epipolar disparity map and sensor geometry.
:param dem: path to reference dem
:type dem: str
:param sensor_left: sensor data
Dict must contain keys: "image", "color", "geomodel",
"no_data", "mask". Paths must be absolute.
Expand All @@ -443,7 +536,7 @@ def maps_generation_wrapper(
:param window_dict: window as dict
"""

ground_truth = ground_truth_reprojection_tools.get_ground_truth(
ground_truth, direct_loc = gnd_truth_tools.get_ground_truth(
geom_plugin,
grid_left,
sensor_left,
Expand Down Expand Up @@ -475,6 +568,48 @@ def maps_generation_wrapper(
coords={cst.ROW: rows, cst.COL: cols},
)

if auxiliary_values is not None:
for key in auxiliary_values.keys():
if auxiliary_interp is not None and key in auxiliary_interp:
interpolation = auxiliary_interp[key]
else:
interpolation = "nearest"

band_description = inputs.get_descriptions_bands(
auxiliary_values[key]
)

keep_band = False
if band_description[0] is not None or len(band_description) > 1:
if len(band_description) == 1:
band_description = np.array([band_description[0]])
else:
band_description = list(band_description)

band_description = [
"band_" + str(i + 1) if v is None else v
for i, v in enumerate(band_description)
]

outputs_dataset.coords[cst.BAND_IM] = (
key,
band_description,
)
dim = [key, cst.Y, cst.X]
keep_band = True
else:
dim = [cst.Y, cst.X]

interp_value = gnd_truth_tools.resample_auxiliary_values(
direct_loc,
auxiliary_values[key],
window,
interpolation,
keep_band,
)

outputs_dataset[key] = (dim, interp_value)

# Fill datasets based on target
attributes = {}
# Return results based on target
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def run(
geom_plugin,
geom_plugin_dem_median,
disp_to_alt_ratio,
auxiliary_values,
auxiliary_interp,
orchestrator=None,
pair_folder=None,
): # noqa: C901
Expand Down
Loading

0 comments on commit c0d3435

Please sign in to comment.