diff --git a/modules/calib3d/src/fundam.cpp b/modules/calib3d/src/fundam.cpp index 75d3456595..4c8d511a93 100644 --- a/modules/calib3d/src/fundam.cpp +++ b/modules/calib3d/src/fundam.cpp @@ -414,6 +414,11 @@ cv::Mat cv::findHomography( InputArray _points1, InputArray _points2, if( result && npoints > 4 && method != RHO) { + // save the original points before compressing + const int npoints_input = npoints; + const Mat src_input = src.clone(); + const Mat dst_input = dst.clone(); + compressElems( src.ptr(), tempMask.ptr(), 1, npoints ); npoints = compressElems( dst.ptr(), tempMask.ptr(), 1, npoints ); if( npoints > 0 ) @@ -427,6 +432,16 @@ cv::Mat cv::findHomography( InputArray _points1, InputArray _points2, Mat H8(9, 1, CV_64F, H.ptr()); LMSolver::create(makePtr(src, dst), 10)->run(H8); H.convertTo(H, H.type(), scaleFor(H.at(2,2))); + + // find new inliers + const float thr_sqr = static_cast(ransacReprojThreshold * ransacReprojThreshold); + cv::Mat errors; + cb->computeError(src_input, dst_input, H, errors); + uchar* maskptr = tempMask.ptr(); + const float * const errors_ptr = errors.ptr(); + for (int i = 0; i < npoints_input; i++) { + maskptr[i] = static_cast(errors_ptr[i] <= thr_sqr); + } } }