MCPcopy
hub / github.com/cvg/Hierarchical-Localization / read_cameras_binary

Function read_cameras_binary

hloc/utils/read_write_model.py:130–156  ·  view source on GitHub ↗

see: src/base/reconstruction.cc void Reconstruction::WriteCamerasBinary(const std::string& path) void Reconstruction::ReadCamerasBinary(const std::string& path)

(path_to_model_file)

Source from the content-addressed store, hash-verified

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

Callers 2

read_modelFunction · 0.85

Calls 1

read_next_bytesFunction · 0.85

Tested by

no test coverage detected