MCPcopy Create free account
hub / github.com/cdcseacave/openMVS / scale_depth_map

Function scale_depth_map

scripts/python/ImportDMAPs.py:66–188  ·  view source on GitHub ↗

Estimate the scale and shift of the depth map based on the scene sparse point cloud, ussing RANSAC to find the best fit: depth_map_scaled = scale * depth_map + shift Args: scene (dict): The MVS scene data. image_idx (int): The index of the image in the scene. depth_map (numpy.

(scene, image_idx, depth_map, verbose=False)

Source from the content-addressed store, hash-verified

64
65
66def scale_depth_map(scene, image_idx, depth_map, verbose=False):
67 """
68 Estimate the scale and shift of the depth map based on the scene sparse point cloud,
69 ussing RANSAC to find the best fit:
70 depth_map_scaled = scale * depth_map + shift
71 Args:
72 scene (dict): The MVS scene data.
73 image_idx (int): The index of the image in the scene.
74 depth_map (numpy.ndarray): The depth map to be scaled corresponding to the image.
75 verbose (bool): If True, print debug information.
76 Returns:
77 tuple: Scale and shift values.
78 """
79 from sklearn.linear_model import RANSACRegressor
80
81 # Collect 3D points and corresponding depth values
82 image = scene["images"][image_idx]
83 image_width = scene["platforms"][image["platform_id"]]["cameras"][image["camera_id"]]["width"]
84 image_height = scene["platforms"][image["platform_id"]]["cameras"][image["camera_id"]]["height"]
85 K = np.array(scene["platforms"][image["platform_id"]]["cameras"][image["camera_id"]]["K"])
86 R = np.array(scene["platforms"][image["platform_id"]]["poses"][image["pose_id"]]["R"])
87 C = np.array(scene["platforms"][image["platform_id"]]["poses"][image["pose_id"]]["C"])
88 K = scale_K(K, depth_map.shape[1] / image_width, depth_map.shape[0] / image_height)
89 depths_sfm = []
90 depths_dmap = []
91 mean_depth = 0
92 for vertex in scene['vertices']:
93 for view in vertex['views']:
94 if view['image_id'] == image_idx:
95 # Project the 3D point to the image plane
96 # and get the corresponding depth value
97 Xcam = R @ (vertex['X'] - C)
98 depth_sfm = float(Xcam[2])
99 if depth_sfm <= 0:
100 break
101 x = K @ Xcam
102 x = np.array([x[0]/x[2], x[1]/x[2]])
103 depth_dmap = sample_depth_map(depth_map, x)
104 if depth_dmap <= 0:
105 break
106 depths_sfm.append(depth_sfm)
107 depths_dmap.append(depth_dmap)
108 mean_depth += depth_sfm
109 break
110 if len(depths_sfm) < 2:
111 return 1.0, 0.0
112 mean_depth /= len(depths_sfm)
113 depths_sfm = np.array(depths_sfm).reshape(-1, 1)
114 depths_dmap = np.array(depths_dmap).reshape(-1, 1)
115
116 # Define the estimator, with all the functions required by RANSAC
117 class Estimator:
118 def __init__(self, scale=1.0, shift=0.0):
119 self.scale = scale
120 self.shift = shift
121
122 def fit(self, X, y):
123 # Solve for scale and shift

Callers 1

import_dmapsFunction · 0.85

Calls 7

scale_KFunction · 0.90
sample_depth_mapFunction · 0.90
EstimatorClass · 0.85
printFunction · 0.85
fitMethod · 0.80
scoreMethod · 0.80
sumMethod · 0.45

Tested by

no test coverage detected