Import depth maps from EXR files and save them as DMAP files. Args: scene_file (str): Path to the MVS scene file. input_dir (str): Directory containing the depth files. ext (str): Extension of the depth files to load (e.g., '.npy' or '.depth.exr'). output_file (str): Directory t
(scene_file, input_dir, ext, output_file, rescale=True, verbose=False)
| 189 | |
| 190 | |
| 191 | def import_dmaps(scene_file, input_dir, ext, output_file, rescale=True, verbose=False): |
| 192 | """ |
| 193 | Import depth maps from EXR files and save them as DMAP files. |
| 194 | Args: |
| 195 | scene_file (str): Path to the MVS scene file. |
| 196 | input_dir (str): Directory containing the depth files. |
| 197 | ext (str): Extension of the depth files to load (e.g., '.npy' or '.depth.exr'). |
| 198 | output_file (str): Directory to save the DMAP files. |
| 199 | verbose (bool): If True, print debug information. |
| 200 | """ |
| 201 | # Load the MVS scene |
| 202 | scene = loadMVSInterface(scene_file) |
| 203 | if verbose: |
| 204 | print(f"Scene {scene_file} loaded: {len(scene['images'])} images") |
| 205 | |
| 206 | os.makedirs(output_file, exist_ok=True) |
| 207 | |
| 208 | for idx, image in tqdm(enumerate(scene["images"]), desc="Importing depth-maps", total=len(scene["images"])): |
| 209 | image_name_ext = os.path.basename(image["name"]) |
| 210 | image_name = os.path.splitext(image_name_ext)[0] |
| 211 | depth_file_path = os.path.join(input_dir, image_name + ext) |
| 212 | if not os.path.exists(depth_file_path): |
| 213 | print(f"Warning: Depth file not found for {depth_file_path}") |
| 214 | continue |
| 215 | |
| 216 | # Load the depth map from the corresponding file |
| 217 | if depth_file_path.endswith(".npy"): |
| 218 | depth_map = load_depth_npy(depth_file_path) |
| 219 | else: |
| 220 | depth_map = load_depth_exr(depth_file_path) |
| 221 | if depth_map is None: |
| 222 | print(f"Warning: Could not load depth map for {image_name}") |
| 223 | continue |
| 224 | |
| 225 | if rescale: |
| 226 | # Scale and shift the depth map |
| 227 | scale, shift = scale_depth_map(scene, idx, depth_map, verbose) |
| 228 | depth_map[depth_map != 0] = scale * depth_map[depth_map != 0] + shift |
| 229 | |
| 230 | # Create DMAP data |
| 231 | dmap_data = { |
| 232 | "has_normal": False, |
| 233 | "has_conf": False, |
| 234 | "has_views": False, |
| 235 | "image_width": scene["platforms"][image["platform_id"]]["cameras"][image["camera_id"]]["width"], |
| 236 | "image_height": scene["platforms"][image["platform_id"]]["cameras"][image["camera_id"]]["height"], |
| 237 | "depth_width": depth_map.shape[1], |
| 238 | "depth_height": depth_map.shape[0], |
| 239 | "depth_min": np.min(depth_map[depth_map > 0]) if np.any(depth_map > 0) else 0, |
| 240 | "depth_max": np.max(depth_map), |
| 241 | "file_name": image["name"], |
| 242 | "reference_view_id": image["id"], |
| 243 | "neighbor_view_ids": [], |
| 244 | "K": scene["platforms"][image["platform_id"]]["cameras"][image["camera_id"]]["K"], |
| 245 | "R": scene["platforms"][image["platform_id"]]["poses"][image["pose_id"]]["R"], |
| 246 | "C": scene["platforms"][image["platform_id"]]["poses"][image["pose_id"]]["C"], |
| 247 | "depth_map": depth_map, |
| 248 | } |
no test coverage detected