From 9f295b2c9125b7c6c894f49ccbf0be5ffbef70c9 Mon Sep 17 00:00:00 2001 From: Tiago De Gaspari Date: Tue, 6 Apr 2021 22:11:03 -0300 Subject: [PATCH] Expose maxIters in findEssentialMat Lets the user choose the maximum number of iterations the robust estimator runs for, similary to findFundamentalMat and findHomography functions. --- modules/calib3d/include/opencv2/calib3d.hpp | 15 +++++++++++++ modules/calib3d/src/five-point.cpp | 25 +++++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/modules/calib3d/include/opencv2/calib3d.hpp b/modules/calib3d/include/opencv2/calib3d.hpp index b48c928d82..6df79fa7b5 100644 --- a/modules/calib3d/include/opencv2/calib3d.hpp +++ b/modules/calib3d/include/opencv2/calib3d.hpp @@ -2241,6 +2241,7 @@ final fundamental matrix. It can be set to something like 1-3, depending on the point localization, image resolution, and the image noise. @param mask Output array of N elements, every element of which is set to 0 for outliers and to 1 for the other points. The array is computed only in the RANSAC and LMedS methods. +@param maxIters The maximum number of robust method iterations. This function estimates essential matrix based on the five-point algorithm solver in @cite Nister03 . @cite SteweniusCFS is also a related. The epipolar geometry is described by the following equation: @@ -2251,6 +2252,12 @@ where \f$E\f$ is an essential matrix, \f$p_1\f$ and \f$p_2\f$ are corresponding second images, respectively. The result of this function may be passed further to decomposeEssentialMat or recoverPose to recover the relative pose between cameras. */ +CV_EXPORTS_W Mat findEssentialMat( InputArray points1, InputArray points2, + InputArray cameraMatrix, int method, + double prob, double threshold, + int maxIters, OutputArray mask = noArray() ); + +/** @overload */ CV_EXPORTS_W Mat findEssentialMat( InputArray points1, InputArray points2, InputArray cameraMatrix, int method = RANSAC, double prob = 0.999, double threshold = 1.0, @@ -2274,6 +2281,7 @@ point localization, image resolution, and the image noise. confidence (probability) that the estimated matrix is correct. @param mask Output array of N elements, every element of which is set to 0 for outliers and to 1 for the other points. The array is computed only in the RANSAC and LMedS methods. +@param maxIters The maximum number of robust method iterations. This function differs from the one above that it computes camera intrinsic matrix from focal length and principal point: @@ -2285,6 +2293,13 @@ f & 0 & x_{pp} \\ 0 & 0 & 1 \end{bmatrix}\f] */ +CV_EXPORTS_W Mat findEssentialMat( InputArray points1, InputArray points2, + double focal, Point2d pp, + int method, double prob, + double threshold, int maxIters, + OutputArray mask = noArray() ); + +/** @overload */ CV_EXPORTS_W Mat findEssentialMat( InputArray points1, InputArray points2, double focal = 1.0, Point2d pp = Point2d(0, 0), int method = RANSAC, double prob = 0.999, diff --git a/modules/calib3d/src/five-point.cpp b/modules/calib3d/src/five-point.cpp index 5909c2e2e3..dbdd294c7e 100644 --- a/modules/calib3d/src/five-point.cpp +++ b/modules/calib3d/src/five-point.cpp @@ -403,7 +403,8 @@ protected: // Input should be a vector of n 2D points or a Nx2 matrix cv::Mat cv::findEssentialMat( InputArray _points1, InputArray _points2, InputArray _cameraMatrix, - int method, double prob, double threshold, OutputArray _mask) + int method, double prob, double threshold, + int maxIters, OutputArray _mask) { CV_INSTRUMENT_REGION(); @@ -442,20 +443,36 @@ cv::Mat cv::findEssentialMat( InputArray _points1, InputArray _points2, InputArr Mat E; if( method == RANSAC ) - createRANSACPointSetRegistrator(makePtr(), 5, threshold, prob)->run(points1, points2, E, _mask); + createRANSACPointSetRegistrator(makePtr(), 5, threshold, prob, maxIters)->run(points1, points2, E, _mask); else - createLMeDSPointSetRegistrator(makePtr(), 5, prob)->run(points1, points2, E, _mask); + createLMeDSPointSetRegistrator(makePtr(), 5, prob, maxIters)->run(points1, points2, E, _mask); return E; } +cv::Mat cv::findEssentialMat( InputArray _points1, InputArray _points2, InputArray _cameraMatrix, + int method, double prob, double threshold, + OutputArray _mask) +{ + return cv::findEssentialMat(_points1, _points2, _cameraMatrix, method, prob, threshold, 1000, _mask); +} + +cv::Mat cv::findEssentialMat( InputArray _points1, InputArray _points2, double focal, Point2d pp, + int method, double prob, double threshold, int maxIters, OutputArray _mask) +{ + CV_INSTRUMENT_REGION(); + + Mat cameraMatrix = (Mat_(3,3) << focal, 0, pp.x, 0, focal, pp.y, 0, 0, 1); + return cv::findEssentialMat(_points1, _points2, cameraMatrix, method, prob, threshold, maxIters, _mask); +} + cv::Mat cv::findEssentialMat( InputArray _points1, InputArray _points2, double focal, Point2d pp, int method, double prob, double threshold, OutputArray _mask) { CV_INSTRUMENT_REGION(); Mat cameraMatrix = (Mat_(3,3) << focal, 0, pp.x, 0, focal, pp.y, 0, 0, 1); - return cv::findEssentialMat(_points1, _points2, cameraMatrix, method, prob, threshold, _mask); + return cv::findEssentialMat(_points1, _points2, cameraMatrix, method, prob, threshold, 1000, _mask); } int cv::recoverPose( InputArray E, InputArray _points1, InputArray _points2,