MCPcopy Create free account
hub / github.com/ai4ce/RAP / read_images_binary

Function read_images_binary

utils/read_write_model.py:247–293  ·  view source on GitHub ↗

see: src/colmap/scene/reconstruction.cc void Reconstruction::ReadImagesBinary(const std::string& path) void Reconstruction::WriteImagesBinary(const std::string& path)

(path_to_model_file)

Source from the content-addressed store, hash-verified

245
246
247def read_images_binary(path_to_model_file):
248 """
249 see: src/colmap/scene/reconstruction.cc
250 void Reconstruction::ReadImagesBinary(const std::string& path)
251 void Reconstruction::WriteImagesBinary(const std::string& path)
252 """
253 images = {}
254 with open(path_to_model_file, "rb") as fid:
255 num_reg_images = read_next_bytes(fid, 8, "Q")[0]
256 for _ in range(num_reg_images):
257 binary_image_properties = read_next_bytes(
258 fid, num_bytes=64, format_char_sequence="idddddddi"
259 )
260 image_id = binary_image_properties[0]
261 qvec = np.array(binary_image_properties[1:5])
262 tvec = np.array(binary_image_properties[5:8])
263 camera_id = binary_image_properties[8]
264 image_name = ""
265 current_char = read_next_bytes(fid, 1, "c")[0]
266 while current_char != b"\x00": # look for the ASCII 0 entry
267 image_name += current_char.decode("utf-8")
268 current_char = read_next_bytes(fid, 1, "c")[0]
269 num_points2D = read_next_bytes(
270 fid, num_bytes=8, format_char_sequence="Q"
271 )[0]
272 x_y_id_s = read_next_bytes(
273 fid,
274 num_bytes=24 * num_points2D,
275 format_char_sequence="ddq" * num_points2D,
276 )
277 xys = np.column_stack(
278 [
279 tuple(map(float, x_y_id_s[0::3])),
280 tuple(map(float, x_y_id_s[1::3])),
281 ]
282 )
283 point3D_ids = np.array(tuple(map(int, x_y_id_s[2::3])))
284 images[image_id] = Image(
285 id=image_id,
286 qvec=qvec,
287 tvec=tvec,
288 camera_id=camera_id,
289 name=image_name,
290 xys=xys,
291 point3D_ids=point3D_ids,
292 )
293 return images
294
295
296def write_images_text(images, path):

Callers 1

read_modelFunction · 0.85

Calls 2

read_next_bytesFunction · 0.70
ImageClass · 0.70

Tested by

no test coverage detected