MCPcopy Create free account
hub / github.com/XiaoBaiiiiii/colmap-pcd / read_images_binary

Function read_images_binary

scripts/python/read_write_model.py:224–256  ·  view source on GitHub ↗

see: src/base/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

222
223
224def read_images_binary(path_to_model_file):
225 """
226 see: src/base/reconstruction.cc
227 void Reconstruction::ReadImagesBinary(const std::string& path)
228 void Reconstruction::WriteImagesBinary(const std::string& path)
229 """
230 images = {}
231 with open(path_to_model_file, "rb") as fid:
232 num_reg_images = read_next_bytes(fid, 8, "Q")[0]
233 for _ in range(num_reg_images):
234 binary_image_properties = read_next_bytes(
235 fid, num_bytes=64, format_char_sequence="idddddddi")
236 image_id = binary_image_properties[0]
237 qvec = np.array(binary_image_properties[1:5])
238 tvec = np.array(binary_image_properties[5:8])
239 camera_id = binary_image_properties[8]
240 image_name = ""
241 current_char = read_next_bytes(fid, 1, "c")[0]
242 while current_char != b"\x00": # look for the ASCII 0 entry
243 image_name += current_char.decode("utf-8")
244 current_char = read_next_bytes(fid, 1, "c")[0]
245 num_points2D = read_next_bytes(fid, num_bytes=8,
246 format_char_sequence="Q")[0]
247 x_y_id_s = read_next_bytes(fid, num_bytes=24*num_points2D,
248 format_char_sequence="ddq"*num_points2D)
249 xys = np.column_stack([tuple(map(float, x_y_id_s[0::3])),
250 tuple(map(float, x_y_id_s[1::3]))])
251 point3D_ids = np.array(tuple(map(int, x_y_id_s[2::3])))
252 images[image_id] = Image(
253 id=image_id, qvec=qvec, tvec=tvec,
254 camera_id=camera_id, name=image_name,
255 xys=xys, point3D_ids=point3D_ids)
256 return images
257
258
259def write_images_text(images, path):

Callers 1

read_modelFunction · 0.85

Calls 2

read_next_bytesFunction · 0.85
ImageClass · 0.70

Tested by

no test coverage detected