-
如果有报警告cuda相关可暂时不管,或者是将cuda/bin软连接添加进去(具体看colmap的issue)
-
colmap 编译和安装:
cmake .. -GNinja \ -DCMAKE_CUDA_ARCHITECTURES=xx #xx可在invidia根据gpu型号查询 ninja sudo ninja install
-
重建时需要处理数据,自己的数据可以在colmap文件夹下的dataset.py中生成对应的database,需要自己写一个数据填写脚本:
def kitti_usage(): # KITTI data has 0-n images, poses is one to one import os import argparse from scipy.spatial.transform import Rotation as R parser = argparse.ArgumentParser() parser.add_argument("--database_path", default="database.db") parser.add_argument("--kitti_path", default="") # parser.add_argument("--image_num", type=int, default=-1) args = parser.parse_args() db_path = os.path.join(args.kitti_path, args.database_path) if os.path.exists(db_path): print("ERROR: database path already exists -- will not modify it.") # return # Open the database. db = COLMAPDatabase.connect(db_path) # For convenience, try creating all the tables upfront. db.create_tables() # Create dummy cameras. model1, model_type1, width1, height1, params1 = ( 1, 'PINHOLE', 1226, 370, np.array((7.070912e+02, 7.070912e+02, 6.018873e+02, 1.831104e+02)), ) # model2, width2, height2, params2 = ( # 2, # 1024, # 768, # np.array((1024.0, 512.0, 384.0, 0.1)), # ) camera_id1 = db.add_camera(model1, width1, height1, params1) # camera_id2 = db.add_camera(model2, width2, height2, params2) camera_head = "# Camera list with one line of data per camera:\n# CAMERA_ID, MODEL, WIDTH, HEIGHT, PARAMS[]\n# Number of cameras: 1\n" outlist = [model1, model_type1, width1, height1] + [p for p in params1.tolist()] cameras_txt_path = os.path.join(args.kitti_path, "model/cameras.txt") with open(cameras_txt_path, "w") as f: f.write(camera_head) f.write(" ".join([f'{out}' for out in outlist])) # Create dummy images. image_ids = [[], []] truth_file = os.path.join(args.kitti_path, "07.txt") poses = None with open(truth_file, "r") as f: poses = f.readlines() image_num = 0 image_path = os.path.join(args.kitti_path, 'image_2') file_list = os.listdir(image_path) for f in file_list: if f.endswith('.png'): image_num+=1 print(f"Total {image_num} in dir {image_path}") for i in range(image_num): image_id1 = db.add_image("{:06d}.png".format(i), camera_id1) # image_id2 = db.add_image(os.path.join(args.kitti_path, "image2/{:06d}.png".format(i)), camera_id2) image_ids[0].append(image_id1) # image_ids[1].append(image_id2) db.commit() # Commit the data to the file. image_file_content = [] for i in range(image_num): pose_line = poses[i] pose_line= list(map(float, pose_line.strip().split())) rotation_matrix= np.array([[pose_line[0], pose_line[1], pose_line[2]], [pose_line[4], pose_line[5], pose_line[6]], [pose_line[8], pose_line[9], pose_line[10]]]) t = np.array([pose_line[3], pose_line[7], pose_line[11]]) rotation_matrix = rotation_matrix.T t = -rotation_matrix @ t r = R.from_matrix(rotation_matrix).as_quat() r_w = r[-1] r[1:] = r[:-1] r[0] = r_w rt = np.concatenate([r, t]) pose_line = " ".join([f"{image_ids[0][i]}"]+[f"{rt_data}" for rt_data in rt.tolist()] + ["{:} {:06d}.png\n\n".format(camera_id1, i)]) image_file_content.append(pose_line) image_txt_path = os.path.join(args.kitti_path, "model/images.txt") with open(image_txt_path, 'w') as f: for line in image_file_content: f.write(line) # Read and check cameras. rows = db.execute("SELECT * FROM cameras") camera_id, model, width, height, params, prior = next(rows) params = blob_to_array(params, np.float64) assert camera_id == camera_id1 assert model == model1 and width == width1 and height == height1 assert np.allclose(params, params1) # camera_id, model, width, height, params, prior = next(rows) # params = blob_to_array(params, np.float64) # assert camera_id == camera_id2 # assert model == model2 and width == width2 and height == height2 # assert np.allclose(params, params2) db.close()
ColMap安装指南
于 2024-08-03 14:32:57 首次发布