Estimate camera pose from 3-D to 2-D point correspondences
returns the pose of a calibrated camera in a world coordinate system. The input
worldPoints must be defined in the world coordinate system.
This function solves the perspective-n-point (PnP) problem using the perspective-three-point (P3P) algorithm . The function eliminates spurious outlier correspondences using the M-estimator sample consensus (MSAC) algorithm. The inliers are the correspondences between image points and world points that are used to compute the camera pose.
returns the indices of the inliers used to compute the camera pose, in addition to the
arguments from the previous syntax.
additionally returns a status code to indicate whether there were enough points.
status] = estworldpose(
[___] = estworldpose(___,
uses additional options specified by one or more name-value arguments, using any of the
Determine Camera Pose from World-to-Image Correspondences
Load previously calculated world-to-image correspondences.
load("worldToImageCorrespondences.mat"); cameraParams.ImageSize = [128 128]; intrinsics = cameraParams.Intrinsics;
Estimate the world camera pose.
worldPose = estworldpose(imagePoints,worldPoints,intrinsics);
Plot the world points.
pcshow(worldPoints,VerticalAxis="Y",VerticalAxisDir="down", ... MarkerSize=30); hold on plotCamera(Size=10,Orientation=worldPose.R', ... Location=worldPose.Translation); hold off
imagePoints — Coordinates of undistorted image points
Coordinates of undistorted image points, specified as an M-by-2 array of [x, y] coordinates. The number of image points, M, must be at least four.
The function does not account for lens distortion. You can either undistort the
images using the
undistortImage function before detecting
the image points, or you can undistort the image points themselves using the
worldPoints — Coordinates of world points
Coordinates of world points, specified as an M-by-3 array of [x, y, z] coordinates.
intrinsics — Camera intrinsics
Camera intrinsics, specified as a
Specify optional pairs of arguments as
the argument name and
Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
MaxNumTrials — Maximum number of random trials
1000 (default) | positive integer scalar
Maximum number of random trials, specified as a positive integer scalar. The
actual number of trials depends on the number of image and world points, and the
values for the
Confidence properties. Increasing the number of trials improves
the robustness of the output at the expense of additional computation.
Confidence — Confidence for finding maximum number of inliers
99 (default) | scalar in the range (0, 100)
Confidence for finding maximum number of inliers, specified as a scalar in the range (0, 100). Increasing this value improves the robustness of the output at the expense of additional computation.
MaxReprojectionError — Reprojection error threshold
1 (default) | positive numeric scalar
Reprojection error threshold for finding outliers, specified as a positive numeric
scalar in pixels. Increasing this value makes the algorithm converge faster, but can
reduce the accuracy of the result. Correspondences with a reprojection error larger
MaxReprojectionError are considered outliers, and are
not used to compute the camera pose.
worldPose — Camera pose
Camera pose in world coordinates, returned as a
R and the
Translation properties of
the object represent the orientation and location of the camera.
inlierIdx — Indices of inlier points
M-by-1 logical vector
Indices of inlier points, returned as an M-by-1 logical vector. A
logical true value in the vector corresponds to inliers represented in
status — Status code
Status code, returned as
|Not enough inliers found. A minimum of 4 inliers are required.|
This function does not account for lens distortion. You can undistort the images using the
undistortImagefunction before detecting the image points. You can undistort the image points themselves using the
 Gao, X.-S., X.-R. Hou, J. Tang, and H.F. Cheng. "Complete Solution Classification for the Perspective-Three-Point Problem." IEEE Transactions on Pattern Analysis and Machine Intelligence. Volume 25,Issue 8, pp. 930–943, August 2003.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
Use in a MATLAB Function block is not supported.
Version HistoryIntroduced in R2022b
R2022b: Recommended over
Starting in R2022b, most Computer Vision Toolbox™ functions create and perform geometric transformations using the premultiply
convention. However, the
estimateWorldCameraPose function uses the
postmultiply convention. Although there are no plans to remove
estimateWorldCameraPose at this time, you can streamline your
geometric transformation workflows by switching to the
function, which supports the premultiply convention. For more information, see Migrate Geometric Transformations to Premultiply Convention.