Perspective-n-Point[1] is the problem of estimating the pose of a calibrated camera given a set of 3D points in the world and their corresponding 2D projections in the image. The camera pose consists of 6 degrees-of-freedom (DOF) which are made up of the rotation (roll, pitch, and yaw) and 3D translation of the camera with respect to the world. This problem originates from camera calibration and has many applications in computer vision and other areas, including 3D pose estimation, robotics and augmented reality.[2] A commonly used solution to the problem exists for called P3P, and many solutions are available for the general case of . A solution for exists if feature orientations are available at the two points.[3] Implementations of these solutions are also available in open source software.
Given a set of 3D points in a world reference frame and their corresponding 2D image projections as well as the calibrated intrinsic camera parameters, determine the 6 DOF pose of the camera in the form of its rotation and translation with respect to the world. This follows the perspective projection model for cameras:
spc=K[R|T]pw
where
stylepw=\begin{bmatrix}x&y&z&1\end{bmatrix}T
stylepc=\begin{bmatrix}u&v&1\end{bmatrix}T
styleK
stylefx
fy
style\gamma
style(u0,v0)
styles
styleR
styleT
s\begin{bmatrix}u\\v\\1\end{bmatrix}=\begin{bmatrix} fx&\gamma&u0\\ 0&fy&v0\\ 0&0&1 \end{bmatrix}\begin{bmatrix} r11&r12&r13&t1\\ r21&r22&r23&t2\\ r31&r32&r33&t3\\ \end{bmatrix} \begin{bmatrix}x\\y\\z\\1\end{bmatrix}
There are a few preliminary aspects of the problem that are common to all solutions of PnP. The assumption made in most solutions is that the camera is already calibrated. Thus, its intrinsic properties are already known, such as the focal length, principal image point, skew parameter, and other parameters. Some methods, such as UPnP.[4] or the Direct Linear Transform (DLT) applied to the projection model, are exceptions to this assumption as they estimate these intrinsic parameters as well as the extrinsic parameters which make up the pose of the camera that the original PnP problem is trying to find.
For each solution to PnP, the chosen point correspondences cannot be colinear. In addition, PnP can have multiple solutions, and choosing a particular solution would require post-processing of the solution set. RANSAC is also commonly used with a PnP method to make the solution robust to outliers in the set of point correspondences. P3P methods assume that the data is noise free, most PnP methods assume Gaussian noise on the inlier set.
This following section describes two common methods that can be used to solve the PnP problem that are also readily available in open source software and how RANSAC can be used to deal with outliers in the data set.
When, the PnP problem is in its minimal form of P3P and can be solved with three point correspondences. However, with just three point correspondences, P3P yields up to four real, geometrically feasible solutions. For low noise levels a fourth correspondence can be used to remove ambiguity. The setup for the problem is as follows.
Let P be the center of projection for the camera, A, B, and C be 3D world points with corresponding images points u, v, and w. Let X = |PA|, Y = |PB|, Z = |PC|,
\alpha=\angleBPC
\beta=\angleAPC
\gamma=\angleAPB
p=2\cos\alpha
q=2\cos\beta
r=2\cos\gamma
a'=|AB|
b'=|BC|
c'=|AC|
\begin{cases} Y2+Z2-YZp-b'2&=0\\ Z2+X2-XZq-c'2&=0\\ X2+Y2-XYr-a'2&=0\\ \end{cases}
Solving the P3P system results in up to four geometrically feasible real solutions for and . The oldest published solution dates to 1841.[5] A recent algorithm for solving the problem as well as a solution classification for it is given in the 2003 IEEE Transactions on Pattern Analysis and Machine Intelligence paper by Gao, et al.[6] An open source implementation of Gao's P3P solver can be found in OpenCV's calib3d module in the solvePnP function.[7] Several faster and more accurate versions have been published since, including Lambda Twist P3P[8] which achieved state of the art performance in 2018 with a 50 fold increase in speed and a 400 fold decrease in numerical failures. Lambdatwist is available as open source in OpenMVG and at https://github.com/midjji/pnp.
Efficient PnP (EPnP) is a method developed by Lepetit, et al. in their 2008 International Journal of Computer Vision paper[9] that solves the general problem of PnP for . This method is based on the notion that each of the n points (which are called reference points) can be expressed as a weighted sum of four virtual control points. Thus, the coordinates of these control points become the unknowns of the problem. It is from these control points that the final pose of the camera is solved for.
As an overview of the process, first note that each of the reference points in the world frame,
w | |
p | |
i |
c | |
p | |
i |
w | |
c | |
j |
c | |
c | |
j |
w | |
p | |
i |
=
4 | |
\sum | |
j=1 |
{\alphaij
w | |
c | |
j} |
c | |
p | |
i |
=
4 | |
\sum | |
j=1 |
{\alphaij
c | |
c | |
j} |
4 | |
\sum | |
j=1 |
{\alphaij
img | |
s | |
i |
=
4 | |
K\sum | |
j=1 |
{\alphaij
c | |
c | |
j} |
img | |
p | |
i |
\begin{bmatrix}ui&vi&1\end{bmatrix}T
c | |
stylec | |
j |
=
c | |
\begin{bmatrix}x | |
j |
&
c | |
y | |
j |
&
T | |
z | |
j\end{bmatrix} |
4 | |
\sum | |
j=1 |
{\alphaij
c | |
f | |
j |
+\alphaij(u0-
c | |
u | |
j} |
=0
4 | |
\sum | |
j=1 |
{\alphaij
c | |
f | |
j |
+\alphaij(v0-
c | |
v | |
j} |
=0
styleMx=0
stylex=
cT | |
\begin{bmatrix}c | |
1 |
&
cT | |
c | |
2 |
&
cT | |
c | |
3 |
&
T | |
c | |
4\end{bmatrix} |
x=
N | |
\sum | |
i=1 |
{\betaivi}
N
M
vi
M
N
\betai
w | |
p | |
i |
c | |
p | |
i |
This solution has
O(n)
This method is not robust against outliers and generally compares poorly to RANSAC P3P followed by nonlinear refinement .
SQPnP was described by Terzakis and Lourakis in an ECCV 2020 paper.[11] It is a non-minimal, non-polynomial solver which casts PnP as a non-linear quadratic program. SQPnP identifies regions in the parameter space of 3D rotations (i.e., the 8-sphere) that contain unique minima with guarantees that at least one of them is the global one. Each regional minimum is computed with sequential quadratic programming that is initiated at nearest orthogonal approximation matrices.
SQPnP has similar or even higher accuracy compared to state of the art polynomial solvers, is globally optimal and computationally very efficient, being practically linear in the number of supplied points . A C++ implementation is, which has also been ported to OpenCV and included in the Camera Calibration and 3D Reconstruction module (SolvePnP function).[12]
PnP is prone to errors if there are outliers in the set of point correspondences. Thus, RANSAC can be used in conjunction with existing solutions to make the final solution for the camera pose more robust to outliers. An open source implementation of PnP methods with RANSAC can be found in OpenCV's Camera Calibration and 3D Reconstruction module in the solvePnPRansac function.[12]