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