code: def main(args):
      import os
  
      if os.path.exists(args.database_path):
          print(
              "Error: database path already exists -- will not modify it."
          )
          exit()
  
      db = COLMAPDatabase.connect(args.database_path)
  
      #
      # for convenience, try creating all the tables upfront
      #
  
      db.initialize_tables()
  
      #
      # create dummy cameras
      #
  
      model1, w1, h1, params1 = (
          0,
          1024,
          768,
          np.array((1024.0, 512.0, 384.0)),
      )
      model2, w2, h2, params2 = (
          2,
          1024,
          768,
          np.array((1024.0, 512.0, 384.0, 0.1)),
      )
  
      db.add_camera(model1, w1, h1, params1)
      db.add_camera(model2, w2, h2, params2)
  
      #
      # create dummy images
      #
  
      db.add_image("image1.png", 0)
      db.add_image("image2.png", 0)
      db.add_image("image3.png", 2)
      db.add_image("image4.png", 2)
  
      #
      # create dummy keypoints; note that COLMAP supports 2D keypoints (x, y),
      # 4D keypoints (x, y, theta, scale), and 6D affine keypoints
      # (x, y, a_11, a_12, a_21, a_22)
      #
  
      N = 1000
      kp1 = np.random.rand(N, 2) * (1024.0, 768.0)
      kp2 = np.random.rand(N, 2) * (1024.0, 768.0)
      kp3 = np.random.rand(N, 2) * (1024.0, 768.0)
      kp4 = np.random.rand(N, 2) * (1024.0, 768.0)
  
      db.add_keypoints(1, kp1)
      db.add_keypoints(2, kp2)
      db.add_keypoints(3, kp3)
      db.add_keypoints(4, kp4)
  
      #
      # create dummy matches
      #
  
      M = 50
      m12 = np.random.randint(N, size=(M, 2))
      m23 = np.random.randint(N, size=(M, 2))
      m34 = np.random.randint(N, size=(M, 2))
  
      db.add_matches(1, 2, m12)
      db.add_matches(2, 3, m23)
      db.add_matches(3, 4, m34)
  
      #
      # check cameras
      #
  
      rows = db.execute("SELECT * FROM cameras")
  
      camera_id, model, width, height, params, prior = next(rows)
      params = blob_to_array(params, np.float32)
      assert model == model1 and width == w1 and height == h1
      assert np.allclose(params, params1)
  
      camera_id, model, width, height, params, prior = next(rows)
      params = blob_to_array(params, np.float32)
      assert model == model2 and width == w2 and height == h2
      assert np.allclose(params, params2)
  
      #
      # check keypoints
      #
  
      kps = dict(
          (image_id, blob_to_array(data, np.float32, (-1, 2)))
          for image_id, data in db.execute(
              "SELECT image_id, data FROM keypoints"
          )
      )
  
      assert np.allclose(kps[1], kp1)
      assert np.allclose(kps[2], kp2)
      assert np.allclose(kps[3], kp3)
      assert np.allclose(kps[4], kp4)
  
      #
      # check matches
      #
  
      pair_ids = [
          get_pair_id(*pair) for pair in [(1, 2), (2, 3), (3, 4)]
      ]
  
      matches = dict(
          (
              get_image_ids_from_pair_id(pair_id),
              blob_to_array(data, np.uint32, (-1, 2)),
          )
          for pair_id, data in db.execute(
              "SELECT pair_id, data FROM matches"
          )
      )
  
      assert np.all(matches[(1, 2)] == m12)
      assert np.all(matches[(2, 3)] == m23)
      assert np.all(matches[(3, 4)] == m34)
  
      #
      # clean up
      #
  
      db.close()
      os.remove(args.database_path)
  
file_path: nerfies/third_party/pycolmap/pycolmap/database.py
imports: import numpy
  import os
  import sqlite3
label_desc: Use image node_id 11 for calling a global function with example usage: main(args) without return types