diff --git a/modules/xfeatures2d/src/freak.cpp b/modules/xfeatures2d/src/freak.cpp index 8761c12ac..1d881cd15 100644 --- a/modules/xfeatures2d/src/freak.cpp +++ b/modules/xfeatures2d/src/freak.cpp @@ -334,8 +334,7 @@ void FREAK_Impl::compute( InputArray _image, std::vector& keypoints, O // Convert to gray if not already Mat grayImage = image; -// if( image.channels() > 1 ) -// cvtColor( image, grayImage, COLOR_BGR2GRAY ); + CV_Assert(grayImage.channels() == 1); // Use 32-bit integers if we won't overflow in the integral image if ((image.depth() == CV_8U || image.depth() == CV_8S) && @@ -682,10 +681,7 @@ imgType FREAK_Impl::meanIntensity( InputArray _image, InputArray _integral, ret_val += integral.at(y_top,x_left); ret_val -= integral.at(y_top,x_right); const int area = (x_right - x_left) * (y_bottom - y_top); - if(ret_val > 0) - ret_val = (ret_val + area/2) / area; - else - ret_val = (ret_val - area/2) / area; + ret_val = (ret_val + area/2) / area; //~ std::cout<(ret_val); } diff --git a/modules/xfeatures2d/test/test_features2d.cpp b/modules/xfeatures2d/test/test_features2d.cpp index 0bd756fa1..8ff50f0a8 100644 --- a/modules/xfeatures2d/test/test_features2d.cpp +++ b/modules/xfeatures2d/test/test_features2d.cpp @@ -298,8 +298,8 @@ public: typedef typename Distance::ResultType DistanceType; CV_DescriptorExtractorTest( const string _name, DistanceType _maxDist, const Ptr& _dextractor, - Distance d = Distance() ): - name(_name), maxDist(_maxDist), dextractor(_dextractor), distance(d) {} + int imgMode = IMREAD_COLOR, Distance d = Distance()): + name(_name), maxDist(_maxDist), dextractor(_dextractor), imgLoadMode(imgMode), distance(d) {} protected: virtual void createDescriptorExtractor() {} @@ -356,7 +356,10 @@ protected: ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); } - image.create( 50, 50, CV_8UC3 ); + if(imgLoadMode == IMREAD_GRAYSCALE) + image.create( 50, 50, CV_8UC1 ); + else + image.create( 50, 50, CV_8UC3 ); try { dextractor->compute( image, keypoints, descriptors ); @@ -389,7 +392,7 @@ protected: // Read the test image. string imgFilename = string(ts->get_data_path()) + FEATURES2D_DIR + "/" + IMAGE_FILENAME; - Mat img = imread( imgFilename ); + Mat img = imread( imgFilename, imgLoadMode ); if( img.empty() ) { ts->printf( cvtest::TS::LOG, "Image %s can not be read.\n", imgFilename.c_str() ); @@ -493,6 +496,7 @@ protected: string name; const DistanceType maxDist; Ptr dextractor; + int imgLoadMode; Distance distance; private: @@ -1021,7 +1025,7 @@ TEST( Features2d_DescriptorExtractor_FREAK, regression ) { // TODO adjust the parameters below CV_DescriptorExtractorTest test( "descriptor-freak", (CV_DescriptorExtractorTest::DistanceType)12.f, - FREAK::create() ); + FREAK::create(), IMREAD_GRAYSCALE ); test.safe_run(); } diff --git a/modules/xfeatures2d/test/test_rotation_and_scale_invariance.cpp b/modules/xfeatures2d/test/test_rotation_and_scale_invariance.cpp index d9e311a00..9cb5fc514 100644 --- a/modules/xfeatures2d/test/test_rotation_and_scale_invariance.cpp +++ b/modules/xfeatures2d/test/test_rotation_and_scale_invariance.cpp @@ -318,11 +318,12 @@ public: DescriptorRotationInvarianceTest(const Ptr& _featureDetector, const Ptr& _descriptorExtractor, int _normType, - float _minDescInliersRatio) : + float _minDescInliersRatio, int imgLoad = IMREAD_COLOR) : featureDetector(_featureDetector), descriptorExtractor(_descriptorExtractor), normType(_normType), - minDescInliersRatio(_minDescInliersRatio) + minDescInliersRatio(_minDescInliersRatio), + imgLoadMode(imgLoad) { CV_Assert(featureDetector); CV_Assert(descriptorExtractor); @@ -335,7 +336,7 @@ protected: const string imageFilename = string(ts->get_data_path()) + IMAGE_TSUKUBA; // Read test data - Mat image0 = imread(imageFilename), image1, mask1; + Mat image0 = imread(imageFilename, imgLoadMode), image1, mask1; if(image0.empty()) { ts->printf(cvtest::TS::LOG, "Image %s can not be read.\n", imageFilename.c_str()); @@ -398,6 +399,7 @@ protected: Ptr descriptorExtractor; int normType; float minDescInliersRatio; + int imgLoadMode; }; @@ -696,6 +698,16 @@ TEST(Features2d_RotationInvariance_Descriptor_BRIEF_16, regression) test.safe_run(); } +TEST(Features2d_RotationInvariance_Descriptor_FREAK, regression) +{ + Ptr f2d = FREAK::create(); + DescriptorRotationInvarianceTest test(SURF::create(), + f2d, + f2d->defaultNorm(), + 0.9f, IMREAD_GRAYSCALE); + test.safe_run(); +} + /* * Detector's scale invariance check */