From: Maria Dimashova Date: Fri, 20 May 2011 12:14:35 +0000 (+0000) Subject: minor changes of recall-precision output X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~7311 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=983f4f1621c750866669f689d48d375b8b340413;p=platform%2Fupstream%2Fopencv.git minor changes of recall-precision output --- diff --git a/modules/features2d/include/opencv2/features2d/features2d.hpp b/modules/features2d/include/opencv2/features2d/features2d.hpp index a6ddd91..0844092 100644 --- a/modules/features2d/include/opencv2/features2d/features2d.hpp +++ b/modules/features2d/include/opencv2/features2d/features2d.hpp @@ -2720,7 +2720,9 @@ CV_EXPORTS void evaluateFeatureDetector( const Mat& img1, const Mat& img2, const CV_EXPORTS void computeRecallPrecisionCurve( const vector >& matches1to2, const vector >& correctMatches1to2Mask, vector& recallPrecisionCurve ); + CV_EXPORTS float getRecall( const vector& recallPrecisionCurve, float l_precision ); +CV_EXPORTS int getNearestPoint( const vector& recallPrecisionCurve, float l_precision ); CV_EXPORTS void evaluateGenericDescriptorMatcher( const Mat& img1, const Mat& img2, const Mat& H1to2, vector& keypoints1, vector& keypoints2, diff --git a/modules/features2d/src/evaluation.cpp b/modules/features2d/src/evaluation.cpp index 6ab9412..0cf53a8 100644 --- a/modules/features2d/src/evaluation.cpp +++ b/modules/features2d/src/evaluation.cpp @@ -491,26 +491,35 @@ void cv::computeRecallPrecisionCurve( const vector >& matches1to2 float cv::getRecall( const vector& recallPrecisionCurve, float l_precision ) { - float recall = -1; + int nearestPointIndex = getNearestPoint( recallPrecisionCurve, l_precision ); + + float recall = -1.f; + + if( nearestPointIndex >= 0 ) + recall = recallPrecisionCurve[nearestPointIndex].y; + + return recall; +} + +int cv::getNearestPoint( const vector& recallPrecisionCurve, float l_precision ) +{ + int nearestPointIndex = -1; if( l_precision >= 0 && l_precision <= 1 ) { - int bestIdx = -1; float minDiff = FLT_MAX; for( size_t i = 0; i < recallPrecisionCurve.size(); i++ ) { float curDiff = std::fabs(l_precision - recallPrecisionCurve[i].x); if( curDiff <= minDiff ) { - bestIdx = (int)i; + nearestPointIndex = (int)i; minDiff = curDiff; } } - - recall = recallPrecisionCurve[bestIdx].y; } - return recall; + return nearestPointIndex; } void cv::evaluateGenericDescriptorMatcher( const Mat& img1, const Mat& img2, const Mat& H1to2, diff --git a/samples/cpp/descriptor_extractor_matcher.cpp b/samples/cpp/descriptor_extractor_matcher.cpp index 834b401..a950582 100644 --- a/samples/cpp/descriptor_extractor_matcher.cpp +++ b/samples/cpp/descriptor_extractor_matcher.cpp @@ -13,17 +13,16 @@ void help(char** argv) cout << "\nThis program demonstrats keypoint finding and matching between 2 images using features2d framework.\n" << " In one case, the 2nd image is synthesized by homography from the first, in the second case, there are 2 images\n" << "\n" - << "case1: second image is obtained from the first (given) image using random generated homography matrix\n" + << "Case1: second image is obtained from the first (given) image using random generated homography matrix\n" << argv[0] << " [detectorType] [descriptorType] [matcherType] [matcherFilterType] [image] [evaluate(0 or 1)]\n" << "Example of case1:\n" << "./descriptor_extractor_matcher SURF SURF FlannBased NoneFilter cola.jpg 0\n" << "\n" - << "case2: both images are given. If ransacReprojThreshold>=0 then homography matrix are calculated\n" - << "Example of case2:\n" + << "Case2: both images are given. If ransacReprojThreshold>=0 then homography matrix are calculated\n" << argv[0] << " [detectorType] [descriptorType] [matcherType] [matcherFilterType] [image1] [image2] [ransacReprojThreshold]\n" << "\n" << "Matches are filtered using homography matrix in case1 and case2 (if ransacReprojThreshold>=0)\n" - << "Example:\n" + << "Example of case2:\n" << "./descriptor_extractor_matcher SURF SURF BruteForce CrossCheckFilter cola1.jpg cola2.jpg 3\n" << "\n" << "Possible detectorType values: see in documentation on createFeatureDetector().\n" @@ -151,12 +150,16 @@ void doIteration( const Mat& img1, Mat& img2, bool isWarpPerspective, if( !H12.empty() && eval ) { - cout << "< Evaluate descriptor match..." << endl; + cout << "< Evaluate descriptor matcher..." << endl; vector curve; Ptr gdm = new VectorDescriptorMatcher( descriptorExtractor, descriptorMatcher ); evaluateGenericDescriptorMatcher( img1, img2, H12, keypoints1, keypoints2, 0, 0, curve, gdm ); - for( float l_p = 0; l_p < 1 - FLT_EPSILON; l_p+=0.1f ) - cout << "1-precision = " << l_p << "; recall = " << getRecall( curve, l_p ) << endl; + + for( float l_p = 0; l_p <= 1; l_p+=0.05f ) + { + int nearest = getNearestPoint( curve, l_p ); + cout << "1-precision = " << curve[nearest].x << "; recall = " << curve[nearest].y << endl; + } cout << ">" << endl; }