Algorithm Search⌘K

Problemcore

Perspective-n-point

Also called PnP, absolute pose problem, camera pose estimation.

Find the pose of a calibrated camera from n known 3D points and their image projections.

The perspective-n-point problem (PnP) asks for the position and orientation of a camera with known intrinsic matrix KK, given nn points Xi\mathbf{X}_i whose coordinates are known in a world frame and their images xi\mathbf{x}_i. The answer is a rigid motion (R,t)(R, \mathbf{t}), so that Xc=RXi+t\mathbf{X}_c = R\mathbf{X}_i + \mathbf{t} is the point in the camera frame and xi∼K(RXi+t)\mathbf{x}_i \sim K(R\mathbf{X}_i + \mathbf{t}). The pose has 6 degrees of freedom and each point gives 2 equations, so three points are the minimum. Three points give up to four poses, solved by P3P; more points fix the pose and average the noise, as in EPnP. With wrong matches, a minimal solver runs inside RANSAC, and the best pose is refined by minimizing the reprojection error. If KK is not known, the problem becomes camera resectioning.

In plain words

You have a photo, and you know where some objects in it are in the real world, for example the corners of a building on a map. You also know the lens of the camera. You want to know where the camera stood and in which direction it pointed. Each known point seen in the photo gives a line of sight that must pass through it. Three points are enough to fix the camera, but they can allow up to four answers. A fourth point usually tells which answer is right. With many points, small errors in the photo matter less.

Definition

Input. World points X1,…,Xn∈R3\mathbf{X}_1, \ldots, \mathbf{X}_n \in \mathbb{R}^3, their image points xi\mathbf{x}_i, and the intrinsic matrix KK. Then the normalized image points yi=K−1xi\mathbf{y}_i = K^{-1}\mathbf{x}_i are known. Some matches may be wrong.

Output. A rotation R∈SO(3)R \in SO(3) and a translation t∈R3\mathbf{t} \in \mathbb{R}^3 such that each correct match satisfies yi∼RXi+t\mathbf{y}_i \sim R\mathbf{X}_i + \mathbf{t} with positive depth (RXi+t)3>0(R\mathbf{X}_i + \mathbf{t})_3 > 0. The camera center is C=−RTtC = -R^{\mathsf T}\mathbf{t}. With noise, the output minimizes a chosen cost:

  • Reprojection error. ∑id(xi,Kπ(RXi+t))2\sum_i d(\mathbf{x}_i, K\pi(R\mathbf{X}_i + \mathbf{t}))^2, where π(X,Y,Z)=(X/Z,Y/Z)\pi(X, Y, Z) = (X/Z, Y/Z). Under independent Gaussian image noise this is the maximum likelihood estimate.
  • Object space error. The sum of the squared distances from RXi+tR\mathbf{X}_i + \mathbf{t} to the ray of yi\mathbf{y}_i. It has no image meaning, but it treats near and far points alike and gives simpler algebra.
  • Algebraic error. A linear residual such as yi×(RXi+t)\mathbf{y}_i \times (R\mathbf{X}_i + \mathbf{t}), used to get a starting pose.

Ambiguities. Unlike relative pose, there is no free scale: the world points fix the units. For n=3n = 3 several poses fit exactly, and positive depth is part of the problem.

Variants

  • Minimal case, P3P. n=3n = 3 gives a polynomial of degree 4 and up to four poses; see P3P.
  • Planar scenes. If all points lie on one plane, the image of the plane is a homography H∼K[r1 r2 t]H \sim K[\mathbf{r}_1\ \mathbf{r}_2\ \mathbf{t}], and four points in general position on the plane give the pose by homography decomposition.
  • Unknown focal length. With only the focal length unknown, the problem has 7 unknowns and needs four points.
  • Unknown calibration. With KK fully unknown, the 3×43 \times 4 matrix P=K[R∣t]P = K[R \mid \mathbf{t}] has 11 degrees of freedom and six points are needed; see DLT camera resectioning and camera matrix decomposition.
  • Generalized cameras. Rays that do not pass through one center, as in a multi-camera rig, give the generalized pose problem; see generalized camera model.
  • Lines and points. Known 3D lines and their images give more equations and can replace points.
  • Known rotation. If RR is known, for example from an inertial sensor, each point gives two linear equations in t\mathbf{t}, and two points are enough.

Examples

Two poses from three points. Take the world points (0,0,0)(0, 0, 0), (1,0,0)(1, 0, 0) and (0,1,0)(0, 1, 0), and the camera R=IR = I, t=(0.5,−0.3,4)\mathbf{t} = (0.5, -0.3, 4). The normalized images are (0.125,−0.075)(0.125, -0.075), (0.375,−0.075)(0.375, -0.075) and (0.125,0.175)(0.125, 0.175). P3P finds two poses with positive depths: the true one, with depths (4,4,4)(4, 4, 4), and a second one, turned by about 4444 degrees, with t=(0.4906,−0.2944,3.9248)\mathbf{t} = (0.4906, -0.2944, 3.9248) and depths (3.9248,3.2356,4.0107)(3.9248, 3.2356, 4.0107). Both fit the three images exactly.

A fourth point decides. The point (1,1,1)(1, 1, 1) has the image (0.3,0.14)(0.3, 0.14) under the true pose and (0.4739,0.1693)(0.4739, 0.1693) under the second one, so its observed image selects the true pose.

Non-example. If all points lie on one line, every rotation about that line fits as well as any other, and the pose is not determined.

Known algorithms

algorithm points output notes
P3P, Grunert's method and its variants 3 up to 4 poses minimal; used inside RANSAC; a fourth point selects
EPnP 4 or more one pose Θ(n)\Theta(n) time; four virtual control points
DLT camera resectioning 6 or more PP, then KK, RR, t\mathbf{t} does not use the known KK; linear
homography decomposition 4 or more on a plane one pose for planar targets
nonlinear refinement all inliers one pose Levenberg-Marquardt on the reprojection error, from any of the above

The usual pipeline is: match image features to known 3D points, run P3P inside RANSAC to find the inliers, compute EPnP on the inliers, and refine with Levenberg-Marquardt on the reprojection error.

AlgorithmTimeSpacePropertiesCode
EPnPΘ(n) worst · average · bestΘ(n) extradeterministicexactofflineiterative1 language
P3PΘ(n) worst · average · bestΘ(1) extradeterministicexactofflineiterative1 language

Bounds

  • Degrees of freedom. 3 for RR and 3 for t\mathbf{t}, so 6. Each point gives 2 equations, so 3 points are the minimum.
  • Number of solutions. Three points not on a line give at most four poses with positive depths, the real positive roots of a quartic; up to four can occur.
  • Uniqueness. Four or more points on a plane, no three on a line, give a unique pose. Six or more points in general position give a unique pose by the linear method, even without KK.
  • Time. Any method must read the nn points, so Ω(n)\Omega(n) time is needed. EPnP reaches Θ(n)\Theta(n); the minimal solvers take constant time.
  • Degenerate cases. Points on a line never fix the pose. For three points, poses near the danger cylinder, the cylinder through the three points perpendicular to their plane, are unstable, because two solutions meet there.

Reductions

  • To absolute orientation. Once the depths of the points are known, the camera frame coordinates RXi+tR\mathbf{X}_i + \mathbf{t} are known, and (R,t)(R, \mathbf{t}) follows by aligning two point sets, the Kabsch algorithm, a form of Wahba's problem. P3P and EPnP both end this way.
  • From resectioning. With KK known, a camera matrix PP from DLT resectioning gives K−1P∼[R∣t]K^{-1}P \sim [R \mid \mathbf{t}], but the left 3×33 \times 3 block must then be forced to be a rotation.
  • Dual of triangulation. Point triangulation finds a point from known cameras; PnP finds a camera from known points. Bundle adjustment refines both.
  • Relation to relative pose. Relative pose works from 2D to 2D matches and leaves the scale free; PnP works from 3D to 2D matches and fixes it.

Applications

  • Structure from motion. Each new image in incremental structure from motion is registered by PnP against the points already reconstructed.
  • Visual odometry and SLAM. Tracking the camera against a local map, as in visual odometry.
  • Calibration. The pose of a calibration target in each image, as in Zhang's calibration method, is a planar PnP problem.
  • Augmented reality and robotics. Placing virtual objects on a known marker, or finding the pose of a known object for a robot to grasp.
  • Localization. Finding where a photo was taken from matches with a 3D model of a place.

References

  1. Martin A. Fischler and Robert C. Bolles, Random sample consensus, a paradigm for model fitting with applications to image analysis and automated cartography, Communications of the ACM 24(6), 1981, 381-395, the location determination problem, its minimal case with three points, and its solution inside RANSAC
  2. Robert M. Haralick, Chung-Nan Lee, Karsten Ottenberg and Michael Nolle, Review and analysis of solutions of the three point perspective pose estimation problem, International Journal of Computer Vision 13(3), 1994, 331-356, the review of the classical three-point solutions and their numerical stability
  3. Vincent Lepetit, Francesc Moreno-Noguer and Pascal Fua, EPnP: An Accurate O(n) Solution to the PnP Problem, International Journal of Computer Vision 81(2), 2009, 155-166, the problem for n points, the survey of earlier methods and the linear-time solution
  4. Richard Szeliski, Computer Vision, Algorithms and Applications, second edition, Springer, 2022, Section 11.2, Pose estimation

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a contract.yaml