Perspective-n-Point

Perspective-"n"-Point 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. 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. Implementations of these solutions are also available in open source software.
Problem Specification.
Definition.
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 project model for cameras:
where formula_2 is the homogeneous world point, formula_3 is the corresponding homogeneous image point, formula_4 is the matrix of intrinsic camera parameters, (where formula_5 and formula_6 are the scaled focal lengths, formula_7 is the skew parameter which is sometimes assumed to be 0, and formula_8 is the principal point), formula_9 is a scale factor for the image point, and formula_10 and formula_11 are the desired 3D rotation and 3D translation of the camera (extrinsic parameters) that are being calculated. This leads to the following equation for the model:
Assumptions and Data Characteristics.
There are a few preliminary aspects of the problem that are common to all solutions of P"n"P. 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 UP"n"P. 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 P"n"P problem is trying to find.
For each solution to PnP, the chosen point correspondences cannot be colinear. In addition, P"n"P can have multiple solutions, and choosing a particular solution would require post-processing of the solution set. RANSAC is also commonly used with a P"n"P 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.
Methods.
This following section describes two common methods that can be used to solve the P"n"P problem that are also readily available in open source software and how RANSAC can be used to deal with outliers in the data set.
P3P.
When , the P"n"P 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|", formula_13, formula_14, formula_15, formula_16, formula_17, formula_18, formula_19, formula_20, formula_21. This forms triangles "PBC", "PAC", and "PAB" from which we obtain a sufficient equation system for P3P:
Solving the P3P system results in up to four geometrically feasible real solutions for and . The oldest published solution dates to 1841. 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. An open source implementation of Gao's P3P solver can be found in OpenCV's "calib3d" module in the "solvePnP" function.
Several faster and more accurate versions have been published since, including Lambda Twist P3P 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.
EP"n"P.
Efficient P"n"P (EP"n"P) is a method developed by Lepetit, et al. in their 2008 International Journal of Computer Vision paper that solves the general problem of P"n"P 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, formula_23, and their corresponding image points, formula_24, are weighted sums of the four controls points, formula_25 and formula_26 respectively, and the weights are normalized per reference point as shown below. All points are expressed in homogeneous form.
From this, the derivation of the image reference points becomes
The homogeneous image control point has the form formula_31. Rearranging the image reference point equation yields the following two linear equations for each reference point:
Using these two equations for each of the reference points, the system formula_34 can be formed where formula_35. The solution for the control points exists in the null space of and is expressed as 
where formula_37 is the number of null singular values in formula_38 and each formula_39 is the corresponding right singular vector of formula_38. formula_37 can range from 0 to 4. After calculating the initial coefficients formula_42, the Gauss-Newton algorithm is used to refine them. The and matrices that minimize the reprojection error of the world reference points, formula_23, and their corresponding actual image points formula_24, are then calculated.
This solution has formula_45 complexity and works in the general case of P"n"P for both planar and non-planar control points. Open source software implementations of this method can be found in OpenCV's Camera Calibration and 3D Reconstruction module in the "solvePnP" function as well as from the code published by Lepetit, et al. at their website, CVLAB at EPFL.
This method is not robust against outliers and generally compares poorly to RANSAC P3P followed by nonlinear refinement.
Using RANSAC.
P"n"P 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 P"n"P methods with RANSAC can be found in OpenCV's Camera Calibration and 3D Reconstruction module in the "solvePnPRansac" function.