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

Function saveDMAP

scripts/python/MvsUtils.py:132–193  ·  view source on GitHub ↗

Save a depth map (DMAP) file. Args: data (dict): A dictionary containing the depth map data. dmap_path (str): The path to save the DMAP file.

(data: dict, dmap_path: str)

Source from the content-addressed store, hash-verified

130
131
132def saveDMAP(data: dict, dmap_path: str):
133 """
134 Save a depth map (DMAP) file.
135 Args:
136 data (dict): A dictionary containing the depth map data.
137 dmap_path (str): The path to save the DMAP file.
138 """
139 assert 'depth_map' in data, 'depth_map is required'
140 assert 'image_width' in data and data['image_width'] > 0, 'image_width is required'
141 assert 'image_height' in data and data['image_height'] > 0, 'image_height is required'
142 assert 'depth_width' in data and data['depth_width'] > 0, 'depth_width is required'
143 assert 'depth_height' in data and data['depth_height'] > 0, 'depth_height is required'
144
145 assert 'depth_min' in data, 'depth_min is required'
146 assert 'depth_max' in data, 'depth_max is required'
147
148 assert 'file_name' in data, 'file_name is required'
149 assert 'reference_view_id' in data, 'reference_view_id is required'
150 assert 'neighbor_view_ids' in data, 'neighbor_view_ids is required'
151
152 assert 'K' in data, 'K is required'
153 assert 'R' in data, 'R is required'
154 assert 'C' in data, 'C is required'
155
156 content_type = 1
157 if 'normal_map' in data:
158 content_type += 2
159 if 'confidence_map' in data:
160 content_type += 4
161 if 'views_map' in data:
162 content_type += 8
163
164 with open(dmap_path, 'wb') as dmap:
165 dmap.write('DR'.encode())
166
167 dmap.write(np.array([content_type], dtype=np.uint8))
168 dmap.write(np.array([0], dtype=np.uint8))
169
170 dmap.write(np.array([data['image_width'], data['image_height']], dtype=np.uint32))
171 dmap.write(np.array([data['depth_width'], data['depth_height']], dtype=np.uint32))
172
173 dmap.write(np.array([data['depth_min'], data['depth_max']], dtype=np.float32))
174
175 file_name = data['file_name']
176 dmap.write(np.array([len(file_name)], dtype=np.uint16))
177 dmap.write(file_name.encode())
178
179 view_ids = [data['reference_view_id']] + data['neighbor_view_ids']
180 dmap.write(np.array([len(view_ids)], dtype=np.uint32))
181 dmap.write(np.array(view_ids, dtype=np.uint32))
182
183 np.array(data['K'], dtype=np.float64).tofile(dmap)
184 np.array(data['R'], dtype=np.float64).tofile(dmap)
185 np.array(data['C'], dtype=np.float64).tofile(dmap)
186
187 data['depth_map'].astype(np.float32).tofile(dmap)
188 if 'normal_map' in data:
189 data['normal_map'].astype(np.float32).tofile(dmap)

Callers 1

import_dmapsFunction · 0.90

Calls 2

openFunction · 0.85
writeMethod · 0.45

Tested by

no test coverage detected