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

Function example_usage

hloc/utils/database.py:236–356  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

234
235
236def example_usage():
237 import os
238 import argparse
239
240 parser = argparse.ArgumentParser()
241 parser.add_argument("--database_path", default="database.db")
242 args = parser.parse_args()
243
244 if os.path.exists(args.database_path):
245 print("ERROR: database path already exists -- will not modify it.")
246 return
247
248 # Open the database.
249
250 db = COLMAPDatabase.connect(args.database_path)
251
252 # For convenience, try creating all the tables upfront.
253
254 db.create_tables()
255
256 # Create dummy cameras.
257
258 model1, width1, height1, params1 = \
259 0, 1024, 768, np.array((1024., 512., 384.))
260 model2, width2, height2, params2 = \
261 2, 1024, 768, np.array((1024., 512., 384., 0.1))
262
263 camera_id1 = db.add_camera(model1, width1, height1, params1)
264 camera_id2 = db.add_camera(model2, width2, height2, params2)
265
266 # Create dummy images.
267
268 image_id1 = db.add_image("image1.png", camera_id1)
269 image_id2 = db.add_image("image2.png", camera_id1)
270 image_id3 = db.add_image("image3.png", camera_id2)
271 image_id4 = db.add_image("image4.png", camera_id2)
272
273 # Create dummy keypoints.
274 #
275 # Note that COLMAP supports:
276 # - 2D keypoints: (x, y)
277 # - 4D keypoints: (x, y, theta, scale)
278 # - 6D affine keypoints: (x, y, a_11, a_12, a_21, a_22)
279
280 num_keypoints = 1000
281 keypoints1 = np.random.rand(num_keypoints, 2) * (width1, height1)
282 keypoints2 = np.random.rand(num_keypoints, 2) * (width1, height1)
283 keypoints3 = np.random.rand(num_keypoints, 2) * (width2, height2)
284 keypoints4 = np.random.rand(num_keypoints, 2) * (width2, height2)
285
286 db.add_keypoints(image_id1, keypoints1)
287 db.add_keypoints(image_id2, keypoints2)
288 db.add_keypoints(image_id3, keypoints3)
289 db.add_keypoints(image_id4, keypoints4)
290
291 # Create dummy matches.
292
293 M = 50

Callers 1

database.pyFile · 0.85

Calls 8

blob_to_arrayFunction · 0.85
image_ids_to_pair_idFunction · 0.85
pair_id_to_image_idsFunction · 0.85
connectMethod · 0.80
add_cameraMethod · 0.80
add_imageMethod · 0.80
add_keypointsMethod · 0.80
add_matchesMethod · 0.80

Tested by

no test coverage detected