Commit aa5281c1 authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

Merge pull request #784 from sovrasov:freak_input_fix

parents da7cc66c 4b00e414
......@@ -334,8 +334,7 @@ void FREAK_Impl::compute( InputArray _image, std::vector<KeyPoint>& 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<iiType>(y_top,x_left);
ret_val -= integral.at<iiType>(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<<integral.step[1]<<std::endl;
return static_cast<imgType>(ret_val);
}
......
......@@ -298,8 +298,8 @@ public:
typedef typename Distance::ResultType DistanceType;
CV_DescriptorExtractorTest( const string _name, DistanceType _maxDist, const Ptr<DescriptorExtractor>& _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<DescriptorExtractor> dextractor;
int imgLoadMode;
Distance distance;
private:
......@@ -1021,7 +1025,7 @@ TEST( Features2d_DescriptorExtractor_FREAK, regression )
{
// TODO adjust the parameters below
CV_DescriptorExtractorTest<Hamming> test( "descriptor-freak", (CV_DescriptorExtractorTest<Hamming>::DistanceType)12.f,
FREAK::create() );
FREAK::create(), IMREAD_GRAYSCALE );
test.safe_run();
}
......
......@@ -318,11 +318,12 @@ public:
DescriptorRotationInvarianceTest(const Ptr<FeatureDetector>& _featureDetector,
const Ptr<DescriptorExtractor>& _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> 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<Feature2D> f2d = FREAK::create();
DescriptorRotationInvarianceTest test(SURF::create(),
f2d,
f2d->defaultNorm(),
0.9f, IMREAD_GRAYSCALE);
test.safe_run();
}
/*
* 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