From: edgarriba Date: Mon, 11 Aug 2014 14:28:09 +0000 (+0200) Subject: SOLVEPNP_* flags X-Git-Tag: submit/tizen_ivi/20141117.190038~2^2~165^2~18 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=afdb67b462bff1cb8a7f9ec4a7f2350aa2e793bc;p=profile%2Fivi%2Fopencv.git SOLVEPNP_* flags --- diff --git a/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst b/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst index 53b2241..f706572 100644 --- a/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst +++ b/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst @@ -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 diff --git a/modules/calib3d/include/opencv2/calib3d.hpp b/modules/calib3d/include/opencv2/calib3d.hpp index f42afad..59e033f 100644 --- a/modules/calib3d/include/opencv2/calib3d.hpp +++ b/modules/calib3d/include/opencv2/calib3d.hpp @@ -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, diff --git a/modules/calib3d/perf/perf_pnp.cpp b/modules/calib3d/perf/perf_pnp.cpp index 668a524..f12c263 100644 --- a/modules/calib3d/perf/perf_pnp.cpp +++ b/modules/calib3d/perf/perf_pnp.cpp @@ -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 PointsNum_Algo_t; typedef perf::TestBaseWithParam PointsNum_Algo; @@ -20,7 +20,7 @@ typedef perf::TestBaseWithParam 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); diff --git a/modules/calib3d/src/solvepnp.cpp b/modules/calib3d/src/solvepnp.cpp index be2b761..c4cacb4 100644 --- a/modules/calib3d/src/solvepnp.cpp +++ b/modules/calib3d/src/solvepnp.cpp @@ -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 cb; // pointer to callback cb = makePtr( 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 diff --git a/modules/calib3d/test/test_solvepnp_ransac.cpp b/modules/calib3d/test/test_solvepnp_ransac.cpp index c8765a0..167415e 100644 --- a/modules/calib3d/test/test_solvepnp_ransac.cpp +++ b/modules/calib3d/test/test_solvepnp_ransac.cpp @@ -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; } diff --git a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_detection.cpp b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_detection.cpp index 1be6715..f759e49 100644 --- a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_detection.cpp +++ b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_detection.cpp @@ -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 **/ diff --git a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_registration.cpp b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_registration.cpp index c796433..be85951 100644 --- a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_registration.cpp +++ b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_registration.cpp @@ -166,7 +166,7 @@ int main() std::vector 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;