see: src/colmap/scene/reconstruction.cc void Reconstruction::WriteCamerasBinary(const std::string& path) void Reconstruction::ReadCamerasBinary(const std::string& path)
(path_to_model_file)
| 132 | |
| 133 | |
| 134 | def read_cameras_binary(path_to_model_file): |
| 135 | """ |
| 136 | see: src/colmap/scene/reconstruction.cc |
| 137 | void Reconstruction::WriteCamerasBinary(const std::string& path) |
| 138 | void Reconstruction::ReadCamerasBinary(const std::string& path) |
| 139 | """ |
| 140 | cameras = {} |
| 141 | with open(path_to_model_file, "rb") as fid: |
| 142 | num_cameras = read_next_bytes(fid, 8, "Q")[0] |
| 143 | for _ in range(num_cameras): |
| 144 | camera_properties = read_next_bytes( |
| 145 | fid, num_bytes=24, format_char_sequence="iiQQ" |
| 146 | ) |
| 147 | camera_id = camera_properties[0] |
| 148 | model_id = camera_properties[1] |
| 149 | model_name = CAMERA_MODEL_IDS[camera_properties[1]].model_name |
| 150 | width = camera_properties[2] |
| 151 | height = camera_properties[3] |
| 152 | num_params = CAMERA_MODEL_IDS[model_id].num_params |
| 153 | params = read_next_bytes( |
| 154 | fid, |
| 155 | num_bytes=8 * num_params, |
| 156 | format_char_sequence="d" * num_params, |
| 157 | ) |
| 158 | cameras[camera_id] = Camera( |
| 159 | id=camera_id, |
| 160 | model=model_name, |
| 161 | width=width, |
| 162 | height=height, |
| 163 | params=np.array(params), |
| 164 | ) |
| 165 | assert len(cameras) == num_cameras |
| 166 | return cameras |
| 167 | |
| 168 | |
| 169 | def write_cameras_text(cameras, path): |
no test coverage detected