Overview
Pose estimation determines the transformation (rotation and translation) from the object coordinate system to the camera coordinate system. This is essential for:- Augmented reality applications
- Robot navigation and manipulation
- 3D scene reconstruction
- Object tracking and localization
Core Functions
solvePnP
Finds an object pose from 3D-2D point correspondences.InputArray
required
Array of object points in the object coordinate space, Nx3 1-channel or 1xN/Nx1 3-channel, where N is the number of points.
vector<Point3d> can also be passed.InputArray
required
Array of corresponding image points in pixel coordinates, Nx2 1-channel or 1xN/Nx1 2-channel.
vector<Point2d> can also be passed.InputArray
required
Input camera intrinsic matrix (3x3).
InputArray
required
Input vector of distortion coefficients. If the vector is NULL/empty, zero distortion coefficients are assumed.
OutputArray
required
Output rotation vector (see Rodrigues) that, together with tvec, brings points from the model coordinate system to the camera coordinate system.
OutputArray
required
Output translation vector.
bool
default:"false"
If true, the function uses the provided rvec and tvec values as initial approximations and further optimizes them (used with SOLVEPNP_ITERATIVE).
int
default:"SOLVEPNP_ITERATIVE"
Method for solving the PnP problem (see SolvePnP Methods below).
Coordinate Systems:
- Input objectPoints: 3D points in world coordinate frame
- Output rvec/tvec: Transformation from world to camera coordinate frame
- The transformation
Xc = R * Xw + tbrings world points to camera coordinates
SolvePnP Methods
Example:
solvePnPRansac
Finds object pose from 3D-2D point correspondences using RANSAC to handle outliers.int
default:"100"
Number of RANSAC iterations.
float
default:"8.0"
Inlier threshold value in pixels. The maximum allowed distance between observed and computed point projections to consider it an inlier.
double
default:"0.99"
The probability that the algorithm produces a useful result (typically 0.99).
OutputArray
Output vector that contains indices of inliers in objectPoints and imagePoints.
- Randomly selects minimal subsets of points
- Estimates pose for each subset
- Counts inliers (points within reprojectionError threshold)
- Refines final pose using all inliers
Minimal Sample Sets:
- Default method uses SOLVEPNP_EPNP for minimal sample estimation
- If you choose SOLVEPNP_P3P or SOLVEPNP_AP3P, these methods are used
- If exactly 4 input points, SOLVEPNP_P3P is automatically used
- Final pose is refined using all inliers with the method specified in flags (unless P3P/AP3P, then EPNP is used)
USAC-based solvePnPRansac
Advanced robust estimation using USAC (Universal RANSAC) framework.solvePnPGeneric
Returns all possible solutions for pose estimation (multiple solutions from P3P methods).OutputArrayOfArrays
required
Vector of output rotation vectors. P3P methods return 0-4 solutions, SOLVEPNP_IPPE returns 2 solutions, others return 1 solution.
OutputArrayOfArrays
required
Vector of output translation vectors corresponding to rvecs.
OutputArray
Optional output array of reprojection error (RMSE) for each solution.
P3P solutions are sorted by reprojection errors (lowest to highest).
solveP3P
Finds an object pose from 3 3D-2D point correspondences.InputArray
required
Array of object points, 3x3 1-channel or 1x3/3x1 3-channel. Exactly 3 points required.
InputArray
required
Array of corresponding image points, 3x2 1-channel or 1x3/3x1 2-channel. Exactly 3 points required.
int
required
Method for solving P3P:
SOLVEPNP_P3P: Based on Ding et al. 2023SOLVEPNP_AP3P: Based on Ke & Roumeliotis 2017
Pose Refinement
solvePnPRefineLM
Refines a pose using Levenberg-Marquardt optimization.InputOutputArray
required
Input/Output rotation vector. Input values used as initial solution.
InputOutputArray
required
Input/Output translation vector. Input values used as initial solution.
TermCriteria
default:"TermCriteria(EPS+COUNT, 20, FLT_EPSILON)"
Termination criteria for the iterative optimization algorithm.
solvePnPRefineVVS
Refines a pose using Virtual Visual Servoing (VVS).double
default:"1"
Gain for the virtual visual servoing control law, equivalent to the α gain in the Damped Gauss-Newton formulation.
Homography-Based Methods
findHomography
Finds a perspective transformation between two planes.InputArray
required
Coordinates of points in the original plane, CV_32FC2 or
vector<Point2f>.InputArray
required
Coordinates of points in the target plane, CV_32FC2 or
vector<Point2f>.int
default:"0"
Method for computing homography:
- 0: Regular method using all points (least squares)
RANSAC(8): RANSAC-based robust methodLMEDS(4): Least-Median robust methodRHO(16): PROSAC-based robust method
double
default:"3"
Maximum allowed reprojection error to treat a point pair as an inlier (pixels). Used in RANSAC and RHO methods.
OutputArray
Optional output mask set by robust methods. Input mask values are ignored.
int
default:"2000"
Maximum number of RANSAC iterations.
double
default:"0.995"
Confidence level, between 0 and 1.
- Finding initial intrinsic and extrinsic matrices
- Planar object tracking
- Image rectification
If H cannot be estimated, an empty matrix is returned.
USAC-based findHomography
Decomposition Methods
decomposeProjectionMatrix
Decomposes a projection matrix into rotation matrix and camera intrinsic matrix.InputArray
required
3x4 input projection matrix P.
OutputArray
required
Output 3x3 camera intrinsic matrix.
OutputArray
required
Output 3x3 external rotation matrix R.
OutputArray
required
Output 4x1 translation vector T.
OutputArray
Optional 3x3 rotation matrix around x-axis.
OutputArray
Optional 3x3 rotation matrix around y-axis.
OutputArray
Optional 3x3 rotation matrix around z-axis.
OutputArray
Optional three-element vector containing three Euler angles of rotation in degrees.
RQDecomp3x3
Computes an RQ decomposition of 3x3 matrices.InputArray
required
3x3 input matrix.
OutputArray
required
Output 3x3 upper-triangular matrix.
OutputArray
required
Output 3x3 orthogonal matrix.
Helper Functions
projectPoints
Projects 3D points to an image plane.InputArray
required
Array of object points in world coordinate frame, 3xN/Nx3 1-channel or 1xN/Nx1 3-channel.
InputArray
required
Rotation vector (Rodrigues) that performs change of basis from world to camera coordinate system.
InputArray
required
Translation vector.
OutputArray
required
Output array of image points in pixel coordinates, 1xN/Nx1 2-channel, or
vector<Point2f>.OutputArray
Optional output 2Nx(10+numDistCoeffs) Jacobian matrix of derivatives of image points with respect to rotation, translation, focal lengths, principal point, and distortion coefficients.
double
default:"0"
Optional fixed aspect ratio parameter. If not 0, the function assumes aspect ratio (fx/fy) is fixed.
drawFrameAxes
Draws axes of the world/object coordinate system from pose estimation.float
required
Length of the painted axes in the same unit as tvec (usually meters).
int
default:"3"
Line thickness of the painted axes.
- OX is drawn in red
- OY is drawn in green
- OZ is drawn in blue
See Also
- Camera Calibration - calibrateCamera for obtaining camera intrinsics
- Stereo Vision - Stereo calibration and rectification
- OpenCV samples:
plane_ar.py(planar augmented reality)
