------------
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
: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.
------------------
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
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,
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,
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,
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;
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)
)
)
{
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);
_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);
cv::Rodrigues(R, rvec);
return true;
}
- else if (flags == P3P)
+ else if (flags == SOLVEPNP_P3P)
{
CV_Assert( npoints == 4);
cv::Mat undistortedPoints;
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;
&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);
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) {}
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
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() {}
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;
}
int minInliersKalman = 30; // Kalman threshold updating
// PnP parameters
-int pnpMethod = cv::ITERATIVE;
+int pnpMethod = cv::SOLVEPNP_ITERATIVE;
/** Functions headers **/
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;