Performance improvement on generalized absolute pose.#4037
Merged
Conversation
ahojnnes
reviewed
Jan 20, 2026
Contributor
|
An alternative optimization could be to store the "camera_id" and then precompute the cam_from_world matrix once and reuse it for direct transformation from world to camera instead of doing two transformations. Probably depends a bit on the problem and how many cameras it contains on whether this is faster. |
ahojnnes
approved these changes
Jan 21, 2026
ahojnnes
added a commit
that referenced
this pull request
May 5, 2026
Hi I was facing an error with `pycolmap.estimate_and_refine_generalized_absolute_pose` when installing pycolmap via pip. Error: ``` *** Aborted at 1777983489 (unix time) try "date -d @1777983489" if you are using GNU date *** PC: @ 0x73ded64220cb (/local/home/akrishnan/lamar_env_fix/lib/python3.10/site-packages/pycolmap/_core.cpython-310-x86_64-linux-gnu.so+0x10220ca) Segmentation fault ``` The breaking PR was #4041. I was able to validate this by installing pycolmap from source on the commit before (#4037). The script below should work on PR #4037. Test data: [Rig_pose_data](https://drive.google.com/file/d/125Y-Pap9FhQUVCayLVfU6iTWXQSHJaS7/view?usp=sharing) Testing script: ```python import pickle, time import numpy as np import pycolmap from tqdm import tqdm PKL = '/local/home/akrishnan/Downloads/rig_pose_debug.pkl' with open(PKL, 'rb') as f: all_data = pickle.load(f) print(f'pycolmap {pycolmap.__version__} from {pycolmap.__file__}') print(f'{len(all_data)} entries') n_ok = 0 n_none = 0 t0 = time.time() for i, d in enumerate(tqdm(all_data, desc='rig PnP')): p2d_per_cam = d['p2d'] p3d_per_cam = d['p3d'] camera_dicts = d['camera_dicts'] qvecs = d['qvecs'] tvecs = d['tvecs'] thresh = float(d['thresh']) p2d_flat = np.concatenate(p2d_per_cam, axis=0).astype(np.float64) p3d_flat = np.concatenate(p3d_per_cam, axis=0).astype(np.float64) camera_idxs = [] for ci, p in enumerate(p2d_per_cam): camera_idxs.extend([ci] * len(p)) cams_from_rig = [] for q_wxyz, t in zip(qvecs, tvecs): q_xyzw = np.array([q_wxyz[1], q_wxyz[2], q_wxyz[3], q_wxyz[0]], dtype=np.float64) cams_from_rig.append(pycolmap.Rigid3d( pycolmap.Rotation3d(q_xyzw), np.asarray(t, dtype=np.float64), )) # Build cameras cameras = [ pycolmap.Camera( model=cd['model'], width=int(cd['width']), height=int(cd['height']), params=list(cd['params']), ) for cd in camera_dicts ] opts = pycolmap.RANSACOptions() opts.max_error = thresh ret = pycolmap.estimate_and_refine_generalized_absolute_pose( p2d_flat, p3d_flat, camera_idxs, cams_from_rig, cameras, estimation_options=opts, return_covariance=True, ) if ret is None: n_none += 1 else: n_ok += 1 dt = time.time() - t0 print(f'\ndone in {dt:.1f}s — succeeded: {n_ok}/{len(all_data)}, ' f'returned None: {n_none}/{len(all_data)}') ``` --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Johannes Schönberger <jsch@demuc.de>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
main (on the test case from #4023):
After precomputing rig_from_world matrix:
After precomputing cam_from_rig matrix:
Will follow up another update on generalized relative pose.
Edit: In the generalized relative pose case poselib::gen_relpose_6pt is the bottleneck, so there is not much to optimize in the colmap side.
Edit: after switching to eigen expressions: