colmap的相机类型可以参考models.h文件。
主要有以下几种相机类型:
SimplePinhole:
内参格式:f, cx, cy
实际用的时候:fx=fy=f
Pinhole:
内参格式:fx, fy, cx, cy
其他可以自行查看models.h文件。
内参存放在images.bin, 外参存放在cameras.bin中
def read_colmap(path):
try:
cameras_extrinsic_file = os.path.join(path, "sparse/0", "images.bin")
cameras_intrinsic_file = os.path.join(path, "sparse/0", "cameras.bin")
cam_extrinsics = read_extrinsics_binary(cameras_extrinsic_file)
cam_intrinsics = read_intrinsics_binary(cameras_intrinsic_file)
except:
cameras_extrinsic_file = os.path.join(path, "sparse/0", "images.txt")
cameras_intrinsic_file = os.path.join(path, "sparse/0", "cameras.txt")
cam_extrinsics = read_extrinsics_text(cameras_extrinsic_file)
cam_intrinsics = read_intrinsics_text(cameras_intrinsic_file)
extr = cam_extrinsics[key]
intr = cam_intrinsics[extr.camera_id]
R = qvec2rotmat(extr.qvec)
t = np.array(extr.tvec)
#world to camera
T = np.zeros((4, 4))
T[:3, :3] = R
T[:3, 3] = t
T[3, 3] = 1.0
def qvec2rotmat(qvec):
return np.array([
[1 - 2 * qvec[2]**2 - 2 * qvec[3]**2,
2 * qvec[1] * qvec[2] - 2 * qvec[0] * qvec[3],
2 * qvec[3] * qvec[1] + 2 * qvec[0] * qvec[2]],
[2 * qvec[1] * qvec[2] + 2 * qvec[0] * qvec[3],
1 - 2 * qvec[1]**2 - 2 * qvec[3]**2,
2 * qvec[2] * qvec[3] - 2 * qvec[0] * qvec[1]],
[2 * qvec[3] * qvec[1] - 2 * qvec[0] * qvec[2],
2 * qvec[2] * qvec[3] + 2 * qvec[0] * qvec[1],
1 - 2 * qvec[1]**2 - 2 * qvec[2]**2]])
如果是SimplePinhole,
那么,fx = fy = intr[0], cx = intr[1], cy = intr[2]
其他类推。