mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 22:44:02 +08:00
SOLVEPNP_* flags
This commit is contained in:
parent
90b3086f4a
commit
afdb67b462
@ -562,7 +562,7 @@ solvePnP
|
||||
------------
|
||||
Finds an object pose from 3D-2D point correspondences.
|
||||
|
||||
.. ocv:function:: bool solvePnP( InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, OutputArray rvec, OutputArray tvec, bool useExtrinsicGuess=false, int flags=ITERATIVE )
|
||||
.. ocv:function:: bool solvePnP( InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, OutputArray rvec, OutputArray tvec, bool useExtrinsicGuess=false, int flags=SOLVEPNP_ITERATIVE )
|
||||
|
||||
.. ocv:pyfunction:: cv2.solvePnP(objectPoints, imagePoints, cameraMatrix, distCoeffs[, rvec[, tvec[, useExtrinsicGuess[, flags]]]]) -> retval, rvec, tvec
|
||||
|
||||
@ -584,10 +584,10 @@ Finds an object pose from 3D-2D point correspondences.
|
||||
|
||||
:param flags: Method for solving a PnP problem:
|
||||
|
||||
* **ITERATIVE** Iterative method is based on Levenberg-Marquardt optimization. In this case the function finds such a pose that minimizes reprojection error, that is the sum of squared distances between the observed projections ``imagePoints`` and the projected (using :ocv:func:`projectPoints` ) ``objectPoints`` .
|
||||
* **P3P** Method is based on the paper of X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang "Complete Solution Classification for the Perspective-Three-Point Problem". In this case the function requires exactly four object and image points.
|
||||
* **EPNP** Method has been introduced by F.Moreno-Noguer, V.Lepetit and P.Fua in the paper "EPnP: Efficient Perspective-n-Point Camera Pose Estimation".
|
||||
* **DLS** Method is based on the paper of Joel A. Hesch and Stergios I. Roumeliotis. "A Direct Least-Squares (DLS) Method for PnP".
|
||||
* **SOLVEPNP_ITERATIVE** Iterative method is based on Levenberg-Marquardt optimization. In this case the function finds such a pose that minimizes reprojection error, that is the sum of squared distances between the observed projections ``imagePoints`` and the projected (using :ocv:func:`projectPoints` ) ``objectPoints`` .
|
||||
* **SOLVEPNP_P3P** Method is based on the paper of X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang "Complete Solution Classification for the Perspective-Three-Point Problem". In this case the function requires exactly four object and image points.
|
||||
* **SOLVEPNP_EPNP** Method has been introduced by F.Moreno-Noguer, V.Lepetit and P.Fua in the paper "EPnP: Efficient Perspective-n-Point Camera Pose Estimation".
|
||||
* **SOLVEPNP_DLS** Method is based on the paper of Joel A. Hesch and Stergios I. Roumeliotis. "A Direct Least-Squares (DLS) Method for PnP".
|
||||
|
||||
The function estimates the object pose given a set of object points, their corresponding image projections, as well as the camera matrix and the distortion coefficients.
|
||||
|
||||
@ -599,7 +599,7 @@ solvePnPRansac
|
||||
------------------
|
||||
Finds an object pose from 3D-2D point correspondences using the RANSAC scheme.
|
||||
|
||||
.. ocv:function:: bool solvePnPRansac( InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, OutputArray rvec, OutputArray tvec, bool useExtrinsicGuess=false, int iterationsCount = 100, float reprojectionError = 8.0, double confidence = 0.99, OutputArray inliers = noArray(), int flags = ITERATIVE )
|
||||
.. ocv:function:: bool solvePnPRansac( InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, OutputArray rvec, OutputArray tvec, bool useExtrinsicGuess=false, int iterationsCount = 100, float reprojectionError = 8.0, double confidence = 0.99, OutputArray inliers = noArray(), int flags = SOLVEPNP_ITERATIVE )
|
||||
|
||||
.. ocv:pyfunction:: cv2.solvePnPRansac(objectPoints, imagePoints, cameraMatrix, distCoeffs[, rvec[, tvec[, useExtrinsicGuess[, iterationsCount[, reprojectionError[, minInliersCount[, inliers[, flags]]]]]]]]) -> rvec, tvec, inliers
|
||||
|
||||
|
@ -55,10 +55,10 @@ enum { LMEDS = 4, //!< least-median algorithm
|
||||
RANSAC = 8 //!< RANSAC algorithm
|
||||
};
|
||||
|
||||
enum { ITERATIVE = 0,
|
||||
EPNP = 1, // F.Moreno-Noguer, V.Lepetit and P.Fua "EPnP: Efficient Perspective-n-Point Camera Pose Estimation"
|
||||
P3P = 2, // X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang; "Complete Solution Classification for the Perspective-Three-Point Problem"
|
||||
DLS = 3 // Joel A. Hesch and Stergios I. Roumeliotis. "A Direct Least-Squares (DLS) Method for PnP"
|
||||
enum { SOLVEPNP_ITERATIVE = 0,
|
||||
SOLVEPNP_EPNP = 1, // F.Moreno-Noguer, V.Lepetit and P.Fua "EPnP: Efficient Perspective-n-Point Camera Pose Estimation"
|
||||
SOLVEPNP_P3P = 2, // X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang; "Complete Solution Classification for the Perspective-Three-Point Problem"
|
||||
SOLVEPNP_DLS = 3 // Joel A. Hesch and Stergios I. Roumeliotis. "A Direct Least-Squares (DLS) Method for PnP"
|
||||
};
|
||||
|
||||
enum { CALIB_CB_ADAPTIVE_THRESH = 1,
|
||||
@ -152,7 +152,7 @@ CV_EXPORTS_W void projectPoints( InputArray objectPoints,
|
||||
CV_EXPORTS_W bool solvePnP( InputArray objectPoints, InputArray imagePoints,
|
||||
InputArray cameraMatrix, InputArray distCoeffs,
|
||||
OutputArray rvec, OutputArray tvec,
|
||||
bool useExtrinsicGuess = false, int flags = ITERATIVE );
|
||||
bool useExtrinsicGuess = false, int flags = SOLVEPNP_ITERATIVE );
|
||||
|
||||
//! computes the camera pose from a few 3D points and the corresponding projections. The outliers are possible.
|
||||
CV_EXPORTS_W bool solvePnPRansac( InputArray objectPoints, InputArray imagePoints,
|
||||
@ -160,7 +160,7 @@ CV_EXPORTS_W bool solvePnPRansac( InputArray objectPoints, InputArray imagePoint
|
||||
OutputArray rvec, OutputArray tvec,
|
||||
bool useExtrinsicGuess = false, int iterationsCount = 100,
|
||||
float reprojectionError = 8.0, double confidence = 0.99,
|
||||
OutputArray inliers = noArray(), int flags = ITERATIVE );
|
||||
OutputArray inliers = noArray(), int flags = SOLVEPNP_ITERATIVE );
|
||||
|
||||
//! initializes camera matrix from a few 3D points and the corresponding projections.
|
||||
CV_EXPORTS_W Mat initCameraMatrix2D( InputArrayOfArrays objectPoints,
|
||||
|
@ -10,7 +10,7 @@ using namespace perf;
|
||||
using std::tr1::make_tuple;
|
||||
using std::tr1::get;
|
||||
|
||||
CV_ENUM(pnpAlgo, ITERATIVE, EPNP /*, P3P*/)
|
||||
CV_ENUM(pnpAlgo, SOLVEPNP_ITERATIVE, SOLVEPNP_EPNP /*, P3P*/)
|
||||
|
||||
typedef std::tr1::tuple<int, pnpAlgo> PointsNum_Algo_t;
|
||||
typedef perf::TestBaseWithParam<PointsNum_Algo_t> PointsNum_Algo;
|
||||
@ -20,7 +20,7 @@ typedef perf::TestBaseWithParam<int> PointsNum;
|
||||
PERF_TEST_P(PointsNum_Algo, solvePnP,
|
||||
testing::Combine(
|
||||
testing::Values(/*4,*/ 3*9, 7*13), //TODO: find why results on 4 points are too unstable
|
||||
testing::Values((int)ITERATIVE, (int)EPNP)
|
||||
testing::Values((int)SOLVEPNP_ITERATIVE, (int)SOLVEPNP_EPNP)
|
||||
)
|
||||
)
|
||||
{
|
||||
@ -93,7 +93,7 @@ PERF_TEST(PointsNum_Algo, solveP3P)
|
||||
|
||||
TEST_CYCLE_N(1000)
|
||||
{
|
||||
solvePnP(points3d, points2d, intrinsics, distortion, rvec, tvec, false, P3P);
|
||||
solvePnP(points3d, points2d, intrinsics, distortion, rvec, tvec, false, SOLVEPNP_P3P);
|
||||
}
|
||||
|
||||
SANITY_CHECK(rvec, 1e-6);
|
||||
|
@ -60,7 +60,7 @@ bool cv::solvePnP( InputArray _opoints, InputArray _ipoints,
|
||||
_tvec.create(3, 1, CV_64F);
|
||||
Mat cameraMatrix = _cameraMatrix.getMat(), distCoeffs = _distCoeffs.getMat();
|
||||
|
||||
if (flags == EPNP)
|
||||
if (flags == SOLVEPNP_EPNP)
|
||||
{
|
||||
cv::Mat undistortedPoints;
|
||||
cv::undistortPoints(ipoints, undistortedPoints, cameraMatrix, distCoeffs);
|
||||
@ -71,7 +71,7 @@ bool cv::solvePnP( InputArray _opoints, InputArray _ipoints,
|
||||
cv::Rodrigues(R, rvec);
|
||||
return true;
|
||||
}
|
||||
else if (flags == P3P)
|
||||
else if (flags == SOLVEPNP_P3P)
|
||||
{
|
||||
CV_Assert( npoints == 4);
|
||||
cv::Mat undistortedPoints;
|
||||
@ -84,7 +84,7 @@ bool cv::solvePnP( InputArray _opoints, InputArray _ipoints,
|
||||
cv::Rodrigues(R, rvec);
|
||||
return result;
|
||||
}
|
||||
else if (flags == ITERATIVE)
|
||||
else if (flags == SOLVEPNP_ITERATIVE)
|
||||
{
|
||||
CvMat c_objectPoints = opoints, c_imagePoints = ipoints;
|
||||
CvMat c_cameraMatrix = cameraMatrix, c_distCoeffs = distCoeffs;
|
||||
@ -94,7 +94,7 @@ bool cv::solvePnP( InputArray _opoints, InputArray _ipoints,
|
||||
&c_rvec, &c_tvec, useExtrinsicGuess );
|
||||
return true;
|
||||
}
|
||||
else if (flags == DLS)
|
||||
else if (flags == SOLVEPNP_DLS)
|
||||
{
|
||||
cv::Mat undistortedPoints;
|
||||
cv::undistortPoints(ipoints, undistortedPoints, cameraMatrix, distCoeffs);
|
||||
@ -117,7 +117,7 @@ class PnPRansacCallback : public PointSetRegistrator::Callback
|
||||
|
||||
public:
|
||||
|
||||
PnPRansacCallback(Mat _cameraMatrix=Mat(3,3,CV_64F), Mat _distCoeffs=Mat(4,1,CV_64F), int _flags=cv::ITERATIVE,
|
||||
PnPRansacCallback(Mat _cameraMatrix=Mat(3,3,CV_64F), Mat _distCoeffs=Mat(4,1,CV_64F), int _flags=cv::SOLVEPNP_ITERATIVE,
|
||||
bool _useExtrinsicGuess=false, Mat _rvec=Mat(), Mat _tvec=Mat() )
|
||||
: cameraMatrix(_cameraMatrix), distCoeffs(_distCoeffs), flags(_flags), useExtrinsicGuess(_useExtrinsicGuess),
|
||||
rvec(_rvec), tvec(_tvec) {}
|
||||
@ -203,7 +203,7 @@ bool cv::solvePnPRansac(InputArray _opoints, InputArray _ipoints,
|
||||
Ptr<PointSetRegistrator::Callback> cb; // pointer to callback
|
||||
cb = makePtr<PnPRansacCallback>( cameraMatrix, distCoeffs, flags, useExtrinsicGuess, rvec, tvec);
|
||||
|
||||
int model_points = flags == P3P ? 4 : 6; // minimum of number of model points
|
||||
int model_points = flags == SOLVEPNP_P3P ? 4 : 6; // minimum of number of model points
|
||||
double param1 = reprojectionError; // reprojection error
|
||||
double param2 = confidence; // confidence
|
||||
int param3 = iterationsCount; // number maximum iterations
|
||||
|
@ -54,10 +54,10 @@ class CV_solvePnPRansac_Test : public cvtest::BaseTest
|
||||
public:
|
||||
CV_solvePnPRansac_Test()
|
||||
{
|
||||
eps[ITERATIVE] = 1.0e-2;
|
||||
eps[EPNP] = 1.0e-2;
|
||||
eps[P3P] = 1.0e-2;
|
||||
eps[DLS] = 1.0e-2;
|
||||
eps[SOLVEPNP_ITERATIVE] = 1.0e-2;
|
||||
eps[SOLVEPNP_EPNP] = 1.0e-2;
|
||||
eps[SOLVEPNP_P3P] = 1.0e-2;
|
||||
eps[SOLVEPNP_DLS] = 1.0e-2;
|
||||
totalTestsCount = 10;
|
||||
}
|
||||
~CV_solvePnPRansac_Test() {}
|
||||
@ -193,10 +193,10 @@ class CV_solvePnP_Test : public CV_solvePnPRansac_Test
|
||||
public:
|
||||
CV_solvePnP_Test()
|
||||
{
|
||||
eps[ITERATIVE] = 1.0e-6;
|
||||
eps[EPNP] = 1.0e-6;
|
||||
eps[P3P] = 1.0e-4;
|
||||
eps[DLS] = 1.0e-6;
|
||||
eps[SOLVEPNP_ITERATIVE] = 1.0e-6;
|
||||
eps[SOLVEPNP_EPNP] = 1.0e-6;
|
||||
eps[SOLVEPNP_P3P] = 1.0e-4;
|
||||
eps[SOLVEPNP_DLS] = 1.0e-6;
|
||||
totalTestsCount = 1000;
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ double confidence = 0.95; // ransac successful confidence.
|
||||
int minInliersKalman = 30; // Kalman threshold updating
|
||||
|
||||
// PnP parameters
|
||||
int pnpMethod = cv::ITERATIVE;
|
||||
int pnpMethod = cv::SOLVEPNP_ITERATIVE;
|
||||
|
||||
|
||||
/** Functions headers **/
|
||||
|
@ -166,7 +166,7 @@ int main()
|
||||
std::vector<cv::Point3f> list_points3d = registration.get_points3d();
|
||||
|
||||
// Estimate pose given the registered points
|
||||
bool is_correspondence = pnp_registration.estimatePose(list_points3d, list_points2d, cv::ITERATIVE);
|
||||
bool is_correspondence = pnp_registration.estimatePose(list_points3d, list_points2d, cv::SOLVEPNP_ITERATIVE);
|
||||
if ( is_correspondence )
|
||||
{
|
||||
std::cout << "Correspondence found" << std::endl;
|
||||
|
Loading…
Reference in New Issue
Block a user