Commit 4b00e414 authored by Vladislav Sovrasov's avatar Vladislav Sovrasov

Check that image is gray in FREAK

parent b1346e5a
...@@ -334,8 +334,7 @@ void FREAK_Impl::compute( InputArray _image, std::vector<KeyPoint>& keypoints, O ...@@ -334,8 +334,7 @@ void FREAK_Impl::compute( InputArray _image, std::vector<KeyPoint>& keypoints, O
// Convert to gray if not already // Convert to gray if not already
Mat grayImage = image; Mat grayImage = image;
// if( image.channels() > 1 ) CV_Assert(grayImage.channels() == 1);
// cvtColor( image, grayImage, COLOR_BGR2GRAY );
// Use 32-bit integers if we won't overflow in the integral image // Use 32-bit integers if we won't overflow in the integral image
if ((image.depth() == CV_8U || image.depth() == CV_8S) && if ((image.depth() == CV_8U || image.depth() == CV_8S) &&
...@@ -682,10 +681,7 @@ imgType FREAK_Impl::meanIntensity( InputArray _image, InputArray _integral, ...@@ -682,10 +681,7 @@ imgType FREAK_Impl::meanIntensity( InputArray _image, InputArray _integral,
ret_val += integral.at<iiType>(y_top,x_left); ret_val += integral.at<iiType>(y_top,x_left);
ret_val -= integral.at<iiType>(y_top,x_right); ret_val -= integral.at<iiType>(y_top,x_right);
const int area = (x_right - x_left) * (y_bottom - y_top); const int area = (x_right - x_left) * (y_bottom - y_top);
if(ret_val > 0) ret_val = (ret_val + area/2) / area;
ret_val = (ret_val + area/2) / area;
else
ret_val = (ret_val - area/2) / area;
//~ std::cout<<integral.step[1]<<std::endl; //~ std::cout<<integral.step[1]<<std::endl;
return static_cast<imgType>(ret_val); return static_cast<imgType>(ret_val);
} }
......
...@@ -298,8 +298,8 @@ public: ...@@ -298,8 +298,8 @@ public:
typedef typename Distance::ResultType DistanceType; typedef typename Distance::ResultType DistanceType;
CV_DescriptorExtractorTest( const string _name, DistanceType _maxDist, const Ptr<DescriptorExtractor>& _dextractor, CV_DescriptorExtractorTest( const string _name, DistanceType _maxDist, const Ptr<DescriptorExtractor>& _dextractor,
Distance d = Distance() ): int imgMode = IMREAD_COLOR, Distance d = Distance()):
name(_name), maxDist(_maxDist), dextractor(_dextractor), distance(d) {} name(_name), maxDist(_maxDist), dextractor(_dextractor), imgLoadMode(imgMode), distance(d) {}
protected: protected:
virtual void createDescriptorExtractor() {} virtual void createDescriptorExtractor() {}
...@@ -356,7 +356,10 @@ protected: ...@@ -356,7 +356,10 @@ protected:
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); 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 try
{ {
dextractor->compute( image, keypoints, descriptors ); dextractor->compute( image, keypoints, descriptors );
...@@ -389,7 +392,7 @@ protected: ...@@ -389,7 +392,7 @@ protected:
// Read the test image. // Read the test image.
string imgFilename = string(ts->get_data_path()) + FEATURES2D_DIR + "/" + IMAGE_FILENAME; string imgFilename = string(ts->get_data_path()) + FEATURES2D_DIR + "/" + IMAGE_FILENAME;
Mat img = imread( imgFilename ); Mat img = imread( imgFilename, imgLoadMode );
if( img.empty() ) if( img.empty() )
{ {
ts->printf( cvtest::TS::LOG, "Image %s can not be read.\n", imgFilename.c_str() ); ts->printf( cvtest::TS::LOG, "Image %s can not be read.\n", imgFilename.c_str() );
...@@ -493,6 +496,7 @@ protected: ...@@ -493,6 +496,7 @@ protected:
string name; string name;
const DistanceType maxDist; const DistanceType maxDist;
Ptr<DescriptorExtractor> dextractor; Ptr<DescriptorExtractor> dextractor;
int imgLoadMode;
Distance distance; Distance distance;
private: private:
...@@ -1021,7 +1025,7 @@ TEST( Features2d_DescriptorExtractor_FREAK, regression ) ...@@ -1021,7 +1025,7 @@ TEST( Features2d_DescriptorExtractor_FREAK, regression )
{ {
// TODO adjust the parameters below // TODO adjust the parameters below
CV_DescriptorExtractorTest<Hamming> test( "descriptor-freak", (CV_DescriptorExtractorTest<Hamming>::DistanceType)12.f, CV_DescriptorExtractorTest<Hamming> test( "descriptor-freak", (CV_DescriptorExtractorTest<Hamming>::DistanceType)12.f,
FREAK::create() ); FREAK::create(), IMREAD_GRAYSCALE );
test.safe_run(); test.safe_run();
} }
......
...@@ -318,11 +318,12 @@ public: ...@@ -318,11 +318,12 @@ public:
DescriptorRotationInvarianceTest(const Ptr<FeatureDetector>& _featureDetector, DescriptorRotationInvarianceTest(const Ptr<FeatureDetector>& _featureDetector,
const Ptr<DescriptorExtractor>& _descriptorExtractor, const Ptr<DescriptorExtractor>& _descriptorExtractor,
int _normType, int _normType,
float _minDescInliersRatio) : float _minDescInliersRatio, int imgLoad = IMREAD_COLOR) :
featureDetector(_featureDetector), featureDetector(_featureDetector),
descriptorExtractor(_descriptorExtractor), descriptorExtractor(_descriptorExtractor),
normType(_normType), normType(_normType),
minDescInliersRatio(_minDescInliersRatio) minDescInliersRatio(_minDescInliersRatio),
imgLoadMode(imgLoad)
{ {
CV_Assert(featureDetector); CV_Assert(featureDetector);
CV_Assert(descriptorExtractor); CV_Assert(descriptorExtractor);
...@@ -335,7 +336,7 @@ protected: ...@@ -335,7 +336,7 @@ protected:
const string imageFilename = string(ts->get_data_path()) + IMAGE_TSUKUBA; const string imageFilename = string(ts->get_data_path()) + IMAGE_TSUKUBA;
// Read test data // Read test data
Mat image0 = imread(imageFilename), image1, mask1; Mat image0 = imread(imageFilename, imgLoadMode), image1, mask1;
if(image0.empty()) if(image0.empty())
{ {
ts->printf(cvtest::TS::LOG, "Image %s can not be read.\n", imageFilename.c_str()); ts->printf(cvtest::TS::LOG, "Image %s can not be read.\n", imageFilename.c_str());
...@@ -398,6 +399,7 @@ protected: ...@@ -398,6 +399,7 @@ protected:
Ptr<DescriptorExtractor> descriptorExtractor; Ptr<DescriptorExtractor> descriptorExtractor;
int normType; int normType;
float minDescInliersRatio; float minDescInliersRatio;
int imgLoadMode;
}; };
...@@ -696,6 +698,16 @@ TEST(Features2d_RotationInvariance_Descriptor_BRIEF_16, regression) ...@@ -696,6 +698,16 @@ TEST(Features2d_RotationInvariance_Descriptor_BRIEF_16, regression)
test.safe_run(); test.safe_run();
} }
TEST(Features2d_RotationInvariance_Descriptor_FREAK, regression)
{
Ptr<Feature2D> f2d = FREAK::create();
DescriptorRotationInvarianceTest test(SURF::create(),
f2d,
f2d->defaultNorm(),
0.9f, IMREAD_GRAYSCALE);
test.safe_run();
}
/* /*
* Detector's scale invariance check * Detector's scale invariance check
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment