BAPnP: A Barycentric Affine Invariant Linear Solver for Robust and Efficient Perspective-n-Point Pose Estimation
This repository contains the MATLAB simulations and C++ implementation for the paper:
"BAPnP: A Barycentric Affine Invariant Linear Solver for Robust and Efficient Perspective-$n$-Point Pose Estimation"
BAPnP is an efficient
supplementary.pdf in the repository root archives three reviewer-requested experiments that are not included in the main manuscript:
| Section | Content | Description |
|---|---|---|
| §2 | Localized Basis-Point Corruption | Pure-linear oDLT comparison under targeted basis-point noise (0--20 px) |
| §3 | Minimal-Configuration Analysis | Performance of all 9 PnP methods at |
| §4 | Extremal Outlier Injection | RANSAC-integrated comparison under 10%--50% synthetic periphery outliers |
The C++ sources for the supplementary experiments (main_tum_ransac.cpp, main_tum_high_ransac.cpp) and the plotting script (plot_outlier.py) are included in this repository.
If you use this code in your research, please cite the corresponding manuscript:
@article{luo2026bapnp,
title={Bapnp: a barycentric affine invariant linear solver for robust and efficient perspective-n-point pose estimation},
author={Luo, Peilin and Guo, Yang},
journal={The Visual Computer},
volume={42},
number={10},
pages={450},
year={2026},
publisher={Springer}
}The MATLAB code is located in the simulations/ directory. It includes the algorithm implementation, ablation studies, and comparisons with state-of-the-art methods.
To run the comparisons, you need to download the baseline algorithms and add them to your MATLAB path:
- MLPnP and other algorithms: Download from urbste/MLPnP_matlab_toolbox.
- CPnP: Download from LIAS-CUHKSZ/CPnP-A-Consistent-PnP-Solver.
- SRPnP: Download from (https://github.com/pingwangsky/PnP_tool)
Setup: Unzip these toolboxes and add their folders (and subfolders) to your MATLAB working path before running the experiments.
We provide unified interfaces for different solvers:
BAPnP.m: Our proposed method (Linear Initialization + Gauss-Newton Refinement).BAPnP_Coplanar.m: Our proposed methodpnp_linear_only.m: Our proposed method (Linear Initialization only).run_cpnp.m: Wrapper for the CPnP solver.- (Other wrappers included in the folder)
Use the following scripts to reproduce the figures presented in the paper:
| Figure in Paper | Description | MATLAB Script |
|---|---|---|
| Fig. 1 | Geometric Comparison (Tetrahedron Volume) | Tetrahedron.m |
| Fig. 2 | Ablation Studies | Ablation1.m, Ablation2.m |
| Fig. 3 | Robustness to Image Noise | exp1.m |
| Fig. 4 | Robustness to Point Density | exp2.m |
| Fig. 5 | Computational Efficiency Plot | plot_time.m |
| Fig. 6 | Quasi-Planar Stability & Spectral Gap Analysis | test_spectral_gap_comparison.mtest_pnp_planarity_performance.m |
The C++ source code is located in the src/ directory. It is designed for real-time performance evaluation and benchmark datasets.
src/bapnp.cpp: The C++ implementation of the BAPnP algorithm.main_benchmark.cpp: Runtime comparison against state-of-the-art implementations.main_colmap_benchmark.cpp: Evaluation on the South Building Dataset.main_tum.cpp: Raw evaluation on the TUM RGB-D Dataset (without outlier rejection).main_tum_ransac.cpp: RANSAC-integrated evaluation on the TUM RGB-D Dataset (500 iterations, 6-pt sampling, 2 px threshold).main_tum_high_ransac.cpp: RANSAC evaluation with synthetic extremal outlier injection (10%--50% ratios), testing robustness under adversarial periphery outliers.
Before running the real-world benchmarks, please download the required datasets. Due to size constraints, they are not included in this repository.
-
South Building Dataset:
- Download: Visit COLMAP Datasets and download "South Building".
- Setup: Extract the dataset and ensure the path matches the configuration in
main_colmap_benchmark.cpp.
-
TUM RGB-D Dataset:
- Download: Visit TUM RGB-D Benchmark.
- Sequence: We use the
freiburg1_desksequence for evaluation. - Setup: Download the sequence and place it in the working directory or update the path in
main_tum.cpp.
Ensure you have a C++ compiler (supports C++11 or higher) and CMake installed.
Build:
mkdir build
cd build
cmake ..
make -jRuntime Benchmark:
./run_benchmarkTUM RGB-D Experiment:
./run_tumTUM RANSAC Experiment:
./run_tum_ransacTUM RANSAC with Extremal Outlier Injection:
./run_tum_high_ransac [outlier_ratio]
# e.g., ./run_tum_high_ransac 0.3 for 30% injected outliersSouth Building (COLMAP) Experiment:
./run_colmap_bench