#4752·colmap

[错误] 4.2.0: 从装备重构的图像 .txt 中的姿态与 image.CamFromWorld() 不匹配 (每个图像的旧姿态)

作者: adisonshadow创建于 2026年9月17日更新于 2026年9月17日
标签needs attention
  1. Build a rig dataset per doc/rigs.html (two-pass workflow, unknown sensor poses):
  • Pass 1: plain colmap mapper without rigs (trivial rigs per camera), partial model is fine.
  • colmap rig_configurator --database_path db --input_path <pass1 model> --rig_config_path rig.json (JSON omits cam_from_rig_* so poses are averaged from the pass-1 model; 448 multi-sensor frames written).
  • Pass 2: colmap mapper --Mapper.ba_refine_sensor_from_rig 0 (also reproduced with refinement enabled and with bundle_adjuster --BundleAdjustment.refine_sensor_from_rig 1).
  1. Load the final model and compare, for every image, image.CamFromWorld() against the exported images.txt:
python
import pycolmap, numpy as np
rec = pycolmap.Reconstruction("sparse/0")  # final rig model (binary)
Rig = rec.rigs[next(iter(rec.rigs))]
def R_of(r3d):
    return np.asarray(r3d.rotation.matrix())
def center(r3d):
    R = R_of(r3d); t = np.asarray(r3d.translation)
    return -R.T @ t
max_ang, n_mismatch, n = 0.0, 0, 0
for img_id, img in rec.images.items():
    cfw = img.cam_from_world()
    R_i = R_of(cfw)
    c_i = center(cfw)
    frame = rec.frames[img.frame_id()]
    R_f, t_f = (lambda r: (np.asarray(r.rotation.matrix()), np.asarray(r.translation)))(frame.rig_from_world())
    cam_id = img.camera_id
    if cam_id != Rig.ref_sensor_id.id:
        R_s, t_s = (lambda r: (np.asarray(r.rotation.matrix()), np.asarray(r.translation)))(Rig.sensor_from_rig(pycolmap.sensor_t(pycolmap.SensorType.CAMERA, cam_id)))
        R_c, t_c = R_s @ R_f, R_s @ t_f + t_s
    else:
        R_c, t_c = R_f, t_f
    # images.txt as exported by model_converter / write_text
    row = txt_rows[img.name()]  # standard COLMAP TXT parsing
    R_t = qvec_to_R(row["qvec"]); t_t = row["tvec"]
    c_t = -R_t.T @ t_t
    ang = np.degrees(np.arccos(np.clip((np.trace(R_c @ R_t.T) - 1) / 2, -1, 1)))
    if abs(ang) > max_ang:
        max_ang, n_mismatch, n = ang, n_mismatch + 1, n + 1
print("Max angle mismatch: %f, %d / %d" % (max_ang, n_mismatch, n))