Commit 5c362968 authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #1759 from alalek:fix_contrib_1754

parents a2eae86c 9312f745
......@@ -12,3 +12,7 @@ if(NOT boost_status OR NOT vgg_status)
endif()
ocv_module_include_directories("${DOWNLOAD_DIR}")
if(TARGET opencv_test_${name})
ocv_target_include_directories(opencv_test_${name} "${OpenCV_SOURCE_DIR}/modules") # use common files from features2d tests
endif()
......@@ -42,953 +42,19 @@
#include "test_precomp.hpp"
namespace opencv_test { namespace {
const string FEATURES2D_DIR = "features2d";
const string DETECTOR_DIR = FEATURES2D_DIR + "/feature_detectors";
const string DESCRIPTOR_DIR = FEATURES2D_DIR + "/descriptor_extractors";
const string IMAGE_FILENAME = "tsukuba.png";
}} // namespace
/****************************************************************************************\
* Regression tests for feature detectors comparing keypoints. *
\****************************************************************************************/
class CV_FeatureDetectorTest : public cvtest::BaseTest
{
public:
CV_FeatureDetectorTest( const string& _name, const Ptr<FeatureDetector>& _fdetector ) :
name(_name), fdetector(_fdetector) {}
protected:
bool isSimilarKeypoints( const KeyPoint& p1, const KeyPoint& p2 );
void compareKeypointSets( const vector<KeyPoint>& validKeypoints, const vector<KeyPoint>& calcKeypoints );
void emptyDataTest();
void regressionTest(); // TODO test of detect() with mask
virtual void run( int );
string name;
Ptr<FeatureDetector> fdetector;
};
void CV_FeatureDetectorTest::emptyDataTest()
{
// One image.
Mat image;
vector<KeyPoint> keypoints;
try
{
fdetector->detect( image, keypoints );
}
catch(...)
{
ts->printf( cvtest::TS::LOG, "detect() on empty image must not generate exception (1).\n" );
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
}
if( !keypoints.empty() )
{
ts->printf( cvtest::TS::LOG, "detect() on empty image must return empty keypoints vector (1).\n" );
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
return;
}
// Several images.
vector<Mat> images;
vector<vector<KeyPoint> > keypointCollection;
try
{
fdetector->detect( images, keypointCollection );
}
catch(...)
{
ts->printf( cvtest::TS::LOG, "detect() on empty image vector must not generate exception (2).\n" );
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
}
}
bool CV_FeatureDetectorTest::isSimilarKeypoints( const KeyPoint& p1, const KeyPoint& p2 )
{
const float maxPtDif = 1.f;
const float maxSizeDif = 1.f;
const float maxAngleDif = 2.f;
const float maxResponseDif = 0.1f;
float dist = (float)cv::norm(p1.pt - p2.pt);
return (dist < maxPtDif &&
fabs(p1.size - p2.size) < maxSizeDif &&
abs(p1.angle - p2.angle) < maxAngleDif &&
abs(p1.response - p2.response) < maxResponseDif &&
p1.octave == p2.octave &&
p1.class_id == p2.class_id);
}
void CV_FeatureDetectorTest::compareKeypointSets( const vector<KeyPoint>& validKeypoints, const vector<KeyPoint>& calcKeypoints )
{
const float maxCountRatioDif = 0.01f;
// Compare counts of validation and calculated keypoints.
float countRatio = (float)validKeypoints.size() / (float)calcKeypoints.size();
if( countRatio < 1 - maxCountRatioDif || countRatio > 1.f + maxCountRatioDif )
{
ts->printf( cvtest::TS::LOG, "Bad keypoints count ratio (validCount = %d, calcCount = %d).\n",
validKeypoints.size(), calcKeypoints.size() );
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
return;
}
int progress = 0, progressCount = (int)(validKeypoints.size() * calcKeypoints.size());
int badPointCount = 0, commonPointCount = max((int)validKeypoints.size(), (int)calcKeypoints.size());
for( size_t v = 0; v < validKeypoints.size(); v++ )
{
int nearestIdx = -1;
float minDist = std::numeric_limits<float>::max();
for( size_t c = 0; c < calcKeypoints.size(); c++ )
{
progress = update_progress( progress, (int)(v*calcKeypoints.size() + c), progressCount, 0 );
float curDist = (float)cv::norm(calcKeypoints[c].pt - validKeypoints[v].pt);
if( curDist < minDist )
{
minDist = curDist;
nearestIdx = (int)c;
}
}
assert( minDist >= 0 );
if( !isSimilarKeypoints( validKeypoints[v], calcKeypoints[nearestIdx] ) )
badPointCount++;
}
ts->printf( cvtest::TS::LOG, "badPointCount = %d; validPointCount = %d; calcPointCount = %d\n",
badPointCount, validKeypoints.size(), calcKeypoints.size() );
if( badPointCount > 0.9 * commonPointCount )
{
ts->printf( cvtest::TS::LOG, " - Bad accuracy!\n" );
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
return;
}
ts->printf( cvtest::TS::LOG, " - OK\n" );
}
void CV_FeatureDetectorTest::regressionTest()
{
assert( !fdetector.empty() );
string imgFilename = string(ts->get_data_path()) + FEATURES2D_DIR + "/" + IMAGE_FILENAME;
string resFilename = string(ts->get_data_path()) + DETECTOR_DIR + "/" + string(name) + ".xml.gz";
// Read the test image.
Mat image = imread( imgFilename );
if( image.empty() )
{
ts->printf( cvtest::TS::LOG, "Image %s can not be read.\n", imgFilename.c_str() );
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA );
return;
}
FileStorage fs( resFilename, FileStorage::READ );
// Compute keypoints.
vector<KeyPoint> calcKeypoints;
fdetector->detect( image, calcKeypoints );
if( fs.isOpened() ) // Compare computed and valid keypoints.
{
// TODO compare saved feature detector params with current ones
// Read validation keypoints set.
vector<KeyPoint> validKeypoints;
read( fs["keypoints"], validKeypoints );
if( validKeypoints.empty() )
{
ts->printf( cvtest::TS::LOG, "Keypoints can not be read.\n" );
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA );
return;
}
compareKeypointSets( validKeypoints, calcKeypoints );
}
else // Write detector parameters and computed keypoints as validation data.
{
fs.open( resFilename, FileStorage::WRITE );
if( !fs.isOpened() )
{
ts->printf( cvtest::TS::LOG, "File %s can not be opened to write.\n", resFilename.c_str() );
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA );
return;
}
else
{
fs << "detector_params" << "{";
fdetector->write( fs );
fs << "}";
write( fs, "keypoints", calcKeypoints );
}
}
}
void CV_FeatureDetectorTest::run( int /*start_from*/ )
{
if( !fdetector )
{
ts->printf( cvtest::TS::LOG, "Feature detector is empty.\n" );
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA );
return;
}
emptyDataTest();
regressionTest();
ts->set_failed_test_info( cvtest::TS::OK );
}
/****************************************************************************************\
* Regression tests for descriptor extractors. *
\****************************************************************************************/
static void writeMatInBin( const Mat& mat, const string& filename )
{
FILE* f = fopen( filename.c_str(), "wb");
if( f )
{
int type = mat.type();
fwrite( (void*)&mat.rows, sizeof(int), 1, f );
fwrite( (void*)&mat.cols, sizeof(int), 1, f );
fwrite( (void*)&type, sizeof(int), 1, f );
int dataSize = (int)(mat.step * mat.rows * mat.channels());
fwrite( (void*)&dataSize, sizeof(int), 1, f );
fwrite( (void*)mat.data, 1, dataSize, f );
fclose(f);
}
}
static Mat readMatFromBin( const string& filename )
{
FILE* f = fopen( filename.c_str(), "rb" );
if( f )
{
int rows, cols, type, dataSize;
size_t elements_read1 = fread( (void*)&rows, sizeof(int), 1, f );
size_t elements_read2 = fread( (void*)&cols, sizeof(int), 1, f );
size_t elements_read3 = fread( (void*)&type, sizeof(int), 1, f );
size_t elements_read4 = fread( (void*)&dataSize, sizeof(int), 1, f );
CV_Assert(elements_read1 == 1 && elements_read2 == 1 && elements_read3 == 1 && elements_read4 == 1);
int step = dataSize / rows / CV_ELEM_SIZE(type);
CV_Assert(step >= cols);
Mat m = Mat( rows, step, type).colRange(0, cols);
size_t elements_read = fread( m.ptr(), 1, dataSize, f );
CV_Assert(elements_read == (size_t)(dataSize));
fclose(f);
return m;
}
return Mat();
}
template<class Distance>
class CV_DescriptorExtractorTest : public cvtest::BaseTest
{
public:
typedef typename Distance::ValueType ValueType;
typedef typename Distance::ResultType DistanceType;
CV_DescriptorExtractorTest( const string _name, DistanceType _maxDist, const Ptr<DescriptorExtractor>& _dextractor,
int imgMode = IMREAD_COLOR, Distance d = Distance()):
name(_name), maxDist(_maxDist), dextractor(_dextractor), imgLoadMode(imgMode), distance(d) {}
protected:
virtual void createDescriptorExtractor() {}
void compareDescriptors( const Mat& validDescriptors, const Mat& calcDescriptors )
{
if( validDescriptors.size != calcDescriptors.size || validDescriptors.type() != calcDescriptors.type() )
{
ts->printf(cvtest::TS::LOG, "Valid and computed descriptors matrices must have the same size and type.\n");
ts->printf(cvtest::TS::LOG, "Valid size is (%d x %d) actual size is (%d x %d).\n", validDescriptors.rows, validDescriptors.cols, calcDescriptors.rows, calcDescriptors.cols);
ts->printf(cvtest::TS::LOG, "Valid type is %d actual type is %d.\n", validDescriptors.type(), calcDescriptors.type());
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA );
return;
}
CV_Assert( DataType<ValueType>::type == validDescriptors.type() );
int dimension = validDescriptors.cols;
DistanceType curMaxDist = std::numeric_limits<DistanceType>::min();
for( int y = 0; y < validDescriptors.rows; y++ )
{
DistanceType dist = distance( validDescriptors.ptr<ValueType>(y), calcDescriptors.ptr<ValueType>(y), dimension );
if( dist > curMaxDist )
curMaxDist = dist;
}
std::stringstream ss;
ss << "Max distance between valid and computed descriptors " << curMaxDist;
if( curMaxDist <= maxDist )
ss << "." << endl;
else
{
ss << ">" << maxDist << " - bad accuracy!"<< endl;
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
}
ts->printf(cvtest::TS::LOG, ss.str().c_str() );
}
void emptyDataTest()
{
assert( !dextractor.empty() );
// One image.
Mat image;
vector<KeyPoint> keypoints;
Mat descriptors;
try
{
dextractor->compute( image, keypoints, descriptors );
}
catch(...)
{
ts->printf( cvtest::TS::LOG, "compute() on empty image and empty keypoints must not generate exception (1).\n");
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA );
}
if(imgLoadMode == IMREAD_GRAYSCALE)
image.create( 256, 256, CV_8UC1 );
else
image.create( 256, 256, CV_8UC3 );
try
{
dextractor->compute( image, keypoints, descriptors );
}
catch(...)
{
ts->printf( cvtest::TS::LOG, "compute() on nonempty image and empty keypoints must not generate exception (1).\n");
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA );
}
// Several images.
vector<Mat> images;
vector<vector<KeyPoint> > keypointsCollection;
vector<Mat> descriptorsCollection;
try
{
dextractor->compute( images, keypointsCollection, descriptorsCollection );
}
catch(...)
{
ts->printf( cvtest::TS::LOG, "compute() on empty images and empty keypoints collection must not generate exception (2).\n");
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA );
}
}
void regressionTest()
{
assert( !dextractor.empty() );
// Read the test image.
string imgFilename = string(ts->get_data_path()) + FEATURES2D_DIR + "/" + IMAGE_FILENAME;
Mat img = imread( imgFilename, imgLoadMode );
if( img.empty() )
{
ts->printf( cvtest::TS::LOG, "Image %s can not be read.\n", imgFilename.c_str() );
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA );
return;
}
vector<KeyPoint> keypoints;
FileStorage fs( string(ts->get_data_path()) + FEATURES2D_DIR + "/keypoints.xml.gz", FileStorage::READ );
if( fs.isOpened() )
{
read( fs.getFirstTopLevelNode(), keypoints );
Mat calcDescriptors;
double t = (double)getTickCount();
#ifdef HAVE_OPENCL
if(cv::ocl::useOpenCL())
{
cv::UMat uimg;
img.copyTo(uimg);
dextractor->compute(uimg, keypoints, calcDescriptors);
}
else
#endif
{
dextractor->compute(img, keypoints, calcDescriptors);
}
t = getTickCount() - t;
ts->printf(cvtest::TS::LOG, "\nAverage time of computing one descriptor = %g ms.\n", t/((double)getTickFrequency()*1000.)/calcDescriptors.rows );
if( calcDescriptors.rows != (int)keypoints.size() )
{
ts->printf( cvtest::TS::LOG, "Count of computed descriptors and keypoints count must be equal.\n" );
ts->printf( cvtest::TS::LOG, "Count of keypoints is %d.\n", (int)keypoints.size() );
ts->printf( cvtest::TS::LOG, "Count of computed descriptors is %d.\n", calcDescriptors.rows );
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
return;
}
if( calcDescriptors.cols != dextractor->descriptorSize() || calcDescriptors.type() != dextractor->descriptorType() )
{
ts->printf( cvtest::TS::LOG, "Incorrect descriptor size or descriptor type.\n" );
ts->printf( cvtest::TS::LOG, "Expected size is %d.\n", dextractor->descriptorSize() );
ts->printf( cvtest::TS::LOG, "Calculated size is %d.\n", calcDescriptors.cols );
ts->printf( cvtest::TS::LOG, "Expected type is %d.\n", dextractor->descriptorType() );
ts->printf( cvtest::TS::LOG, "Calculated type is %d.\n", calcDescriptors.type() );
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
return;
}
// TODO read and write descriptor extractor parameters and check them
Mat validDescriptors = readDescriptors();
if( !validDescriptors.empty() )
compareDescriptors( validDescriptors, calcDescriptors );
else
{
if( !writeDescriptors( calcDescriptors ) )
{
ts->printf( cvtest::TS::LOG, "Descriptors can not be written.\n" );
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA );
return;
}
}
}
else
{
ts->printf( cvtest::TS::LOG, "Compute and write keypoints.\n" );
fs.open( string(ts->get_data_path()) + FEATURES2D_DIR + "/keypoints.xml.gz", FileStorage::WRITE );
if( fs.isOpened() )
{
Ptr<SURF> fd = SURF::create();
fd->detect(img, keypoints);
write( fs, "keypoints", keypoints );
}
else
{
ts->printf(cvtest::TS::LOG, "File for writting keypoints can not be opened.\n");
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA );
return;
}
}
}
void run(int)
{
createDescriptorExtractor();
if( !dextractor )
{
ts->printf(cvtest::TS::LOG, "Descriptor extractor is empty.\n");
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA );
return;
}
emptyDataTest();
regressionTest();
ts->set_failed_test_info( cvtest::TS::OK );
}
virtual Mat readDescriptors()
{
Mat res = readMatFromBin( string(ts->get_data_path()) + DESCRIPTOR_DIR + "/" + string(name) );
return res;
}
virtual bool writeDescriptors( Mat& descs )
{
writeMatInBin( descs, string(ts->get_data_path()) + DESCRIPTOR_DIR + "/" + string(name) );
return true;
}
string name;
const DistanceType maxDist;
Ptr<DescriptorExtractor> dextractor;
int imgLoadMode;
Distance distance;
private:
CV_DescriptorExtractorTest& operator=(const CV_DescriptorExtractorTest&) { return *this; }
};
/*template<typename T, typename Distance>
class CV_CalonderDescriptorExtractorTest : public CV_DescriptorExtractorTest<Distance>
{
public:
CV_CalonderDescriptorExtractorTest( const char* testName, float _normDif, float _prevTime ) :
CV_DescriptorExtractorTest<Distance>( testName, _normDif, Ptr<DescriptorExtractor>(), _prevTime )
{}
protected:
virtual void createDescriptorExtractor()
{
CV_DescriptorExtractorTest<Distance>::dextractor =
new CalonderDescriptorExtractor<T>( string(CV_DescriptorExtractorTest<Distance>::ts->get_data_path()) +
FEATURES2D_DIR + "/calonder_classifier.rtc");
}
};*/
/****************************************************************************************\
* Algorithmic tests for descriptor matchers *
\****************************************************************************************/
class CV_DescriptorMatcherTest : public cvtest::BaseTest
{
public:
CV_DescriptorMatcherTest( const string& _name, const Ptr<DescriptorMatcher>& _dmatcher, float _badPart ) :
badPart(_badPart), name(_name), dmatcher(_dmatcher)
{}
protected:
static const int dim = 500;
static const int queryDescCount = 300; // must be even number because we split train data in some cases in two
static const int countFactor = 4; // do not change it
const float badPart;
virtual void run( int );
void generateData( Mat& query, Mat& train );
//void emptyDataTest();
void matchTest( const Mat& query, const Mat& train );
void knnMatchTest( const Mat& query, const Mat& train );
void radiusMatchTest( const Mat& query, const Mat& train );
string name;
Ptr<DescriptorMatcher> dmatcher;
private:
CV_DescriptorMatcherTest& operator=(const CV_DescriptorMatcherTest&) { return *this; }
};
#if 0 // not used
void CV_DescriptorMatcherTest::emptyDataTest()
{
assert( !dmatcher.empty() );
Mat queryDescriptors, trainDescriptors, mask;
vector<Mat> trainDescriptorCollection, masks;
vector<DMatch> matches;
vector<vector<DMatch> > vmatches;
try
{
dmatcher->match( queryDescriptors, trainDescriptors, matches, mask );
}
catch(...)
{
ts->printf( cvtest::TS::LOG, "match() on empty descriptors must not generate exception (1).\n" );
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
}
try
{
dmatcher->knnMatch( queryDescriptors, trainDescriptors, vmatches, 2, mask );
}
catch(...)
{
ts->printf( cvtest::TS::LOG, "knnMatch() on empty descriptors must not generate exception (1).\n" );
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
}
try
{
dmatcher->radiusMatch( queryDescriptors, trainDescriptors, vmatches, 10.f, mask );
}
catch(...)
{
ts->printf( cvtest::TS::LOG, "radiusMatch() on empty descriptors must not generate exception (1).\n" );
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
}
try
{
dmatcher->add( trainDescriptorCollection );
}
catch(...)
{
ts->printf( cvtest::TS::LOG, "add() on empty descriptors must not generate exception.\n" );
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
}
try
{
dmatcher->match( queryDescriptors, matches, masks );
}
catch(...)
{
ts->printf( cvtest::TS::LOG, "match() on empty descriptors must not generate exception (2).\n" );
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
}
try
{
dmatcher->knnMatch( queryDescriptors, vmatches, 2, masks );
}
catch(...)
{
ts->printf( cvtest::TS::LOG, "knnMatch() on empty descriptors must not generate exception (2).\n" );
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
}
try
{
dmatcher->radiusMatch( queryDescriptors, vmatches, 10.f, masks );
}
catch(...)
{
ts->printf( cvtest::TS::LOG, "radiusMatch() on empty descriptors must not generate exception (2).\n" );
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
}
}
#endif
void CV_DescriptorMatcherTest::generateData( Mat& query, Mat& train )
{
RNG& rng = theRNG();
// Generate query descriptors randomly.
// Descriptor vector elements are integer values.
Mat buf( queryDescCount, dim, CV_32SC1 );
rng.fill( buf, RNG::UNIFORM, Scalar::all(0), Scalar(3) );
buf.convertTo( query, CV_32FC1 );
// Generate train decriptors as follows:
// copy each query descriptor to train set countFactor times
// and perturb some one element of the copied descriptors in
// in ascending order. General boundaries of the perturbation
// are (0.f, 1.f).
train.create( query.rows*countFactor, query.cols, CV_32FC1 );
float step = 1.f / countFactor;
for( int qIdx = 0; qIdx < query.rows; qIdx++ )
{
Mat queryDescriptor = query.row(qIdx);
for( int c = 0; c < countFactor; c++ )
{
int tIdx = qIdx * countFactor + c;
Mat trainDescriptor = train.row(tIdx);
queryDescriptor.copyTo( trainDescriptor );
int elem = rng(dim);
float diff = rng.uniform( step*c, step*(c+1) );
trainDescriptor.at<float>(0, elem) += diff;
}
}
}
void CV_DescriptorMatcherTest::matchTest( const Mat& query, const Mat& train )
{
dmatcher->clear();
// test const version of match()
{
vector<DMatch> matches;
dmatcher->match( query, train, matches );
if( (int)matches.size() != queryDescCount )
{
ts->printf(cvtest::TS::LOG, "Incorrect matches count while test match() function (1).\n");
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
}
else
{
int badCount = 0;
for( size_t i = 0; i < matches.size(); i++ )
{
DMatch match = matches[i];
if( (match.queryIdx != (int)i) || (match.trainIdx != (int)i*countFactor) || (match.imgIdx != 0) )
badCount++;
}
if( (float)badCount > (float)queryDescCount*badPart )
{
ts->printf( cvtest::TS::LOG, "%f - too large bad matches part while test match() function (1).\n",
(float)badCount/(float)queryDescCount );
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
}
}
}
// test version of match() with add()
{
vector<DMatch> matches;
// make add() twice to test such case
dmatcher->add( vector<Mat>(1,train.rowRange(0, train.rows/2)) );
dmatcher->add( vector<Mat>(1,train.rowRange(train.rows/2, train.rows)) );
// prepare masks (make first nearest match illegal)
vector<Mat> masks(2);
for(int mi = 0; mi < 2; mi++ )
{
masks[mi] = Mat(query.rows, train.rows/2, CV_8UC1, Scalar::all(1));
for( int di = 0; di < queryDescCount/2; di++ )
masks[mi].col(di*countFactor).setTo(Scalar::all(0));
}
dmatcher->match( query, matches, masks );
if( (int)matches.size() != queryDescCount )
{
ts->printf(cvtest::TS::LOG, "Incorrect matches count while test match() function (2).\n");
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
}
else
{
int badCount = 0;
for( size_t i = 0; i < matches.size(); i++ )
{
DMatch match = matches[i];
int shift = dmatcher->isMaskSupported() ? 1 : 0;
{
if( i < queryDescCount/2 )
{
if( (match.queryIdx != (int)i) || (match.trainIdx != (int)i*countFactor + shift) || (match.imgIdx != 0) )
badCount++;
}
else
{
if( (match.queryIdx != (int)i) || (match.trainIdx != ((int)i-queryDescCount/2)*countFactor + shift) || (match.imgIdx != 1) )
badCount++;
}
}
}
if( (float)badCount > (float)queryDescCount*badPart )
{
ts->printf( cvtest::TS::LOG, "%f - too large bad matches part while test match() function (2).\n",
(float)badCount/(float)queryDescCount );
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
}
}
}
}
void CV_DescriptorMatcherTest::knnMatchTest( const Mat& query, const Mat& train )
{
dmatcher->clear();
// test const version of knnMatch()
{
const int knn = 3;
vector<vector<DMatch> > matches;
dmatcher->knnMatch( query, train, matches, knn );
if( (int)matches.size() != queryDescCount )
{
ts->printf(cvtest::TS::LOG, "Incorrect matches count while test knnMatch() function (1).\n");
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
}
else
{
int badCount = 0;
for( size_t i = 0; i < matches.size(); i++ )
{
if( (int)matches[i].size() != knn )
badCount++;
else
{
int localBadCount = 0;
for( int k = 0; k < knn; k++ )
{
DMatch match = matches[i][k];
if( (match.queryIdx != (int)i) || (match.trainIdx != (int)i*countFactor+k) || (match.imgIdx != 0) )
localBadCount++;
}
badCount += localBadCount > 0 ? 1 : 0;
}
}
if( (float)badCount > (float)queryDescCount*badPart )
{
ts->printf( cvtest::TS::LOG, "%f - too large bad matches part while test knnMatch() function (1).\n",
(float)badCount/(float)queryDescCount );
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
}
}
}
// test version of knnMatch() with add()
{
const int knn = 2;
vector<vector<DMatch> > matches;
// make add() twice to test such case
dmatcher->add( vector<Mat>(1,train.rowRange(0, train.rows/2)) );
dmatcher->add( vector<Mat>(1,train.rowRange(train.rows/2, train.rows)) );
// prepare masks (make first nearest match illegal)
vector<Mat> masks(2);
for(int mi = 0; mi < 2; mi++ )
{
masks[mi] = Mat(query.rows, train.rows/2, CV_8UC1, Scalar::all(1));
for( int di = 0; di < queryDescCount/2; di++ )
masks[mi].col(di*countFactor).setTo(Scalar::all(0));
}
dmatcher->knnMatch( query, matches, knn, masks );
if( (int)matches.size() != queryDescCount )
{
ts->printf(cvtest::TS::LOG, "Incorrect matches count while test knnMatch() function (2).\n");
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
}
else
{
int badCount = 0;
int shift = dmatcher->isMaskSupported() ? 1 : 0;
for( size_t i = 0; i < matches.size(); i++ )
{
if( (int)matches[i].size() != knn )
badCount++;
else
{
int localBadCount = 0;
for( int k = 0; k < knn; k++ )
{
DMatch match = matches[i][k];
{
if( i < queryDescCount/2 )
{
if( (match.queryIdx != (int)i) || (match.trainIdx != (int)i*countFactor + k + shift) ||
(match.imgIdx != 0) )
localBadCount++;
}
else
{
if( (match.queryIdx != (int)i) || (match.trainIdx != ((int)i-queryDescCount/2)*countFactor + k + shift) ||
(match.imgIdx != 1) )
localBadCount++;
}
}
}
badCount += localBadCount > 0 ? 1 : 0;
}
}
if( (float)badCount > (float)queryDescCount*badPart )
{
ts->printf( cvtest::TS::LOG, "%f - too large bad matches part while test knnMatch() function (2).\n",
(float)badCount/(float)queryDescCount );
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
}
}
}
}
void CV_DescriptorMatcherTest::radiusMatchTest( const Mat& query, const Mat& train )
{
dmatcher->clear();
// test const version of match()
{
const float radius = 1.f/countFactor;
vector<vector<DMatch> > matches;
dmatcher->radiusMatch( query, train, matches, radius );
if( (int)matches.size() != queryDescCount )
{
ts->printf(cvtest::TS::LOG, "Incorrect matches count while test radiusMatch() function (1).\n");
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
}
else
{
int badCount = 0;
for( size_t i = 0; i < matches.size(); i++ )
{
if( (int)matches[i].size() != 1 )
badCount++;
else
{
DMatch match = matches[i][0];
if( (match.queryIdx != (int)i) || (match.trainIdx != (int)i*countFactor) || (match.imgIdx != 0) )
badCount++;
}
}
if( (float)badCount > (float)queryDescCount*badPart )
{
ts->printf( cvtest::TS::LOG, "%f - too large bad matches part while test radiusMatch() function (1).\n",
(float)badCount/(float)queryDescCount );
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
}
}
}
// test version of match() with add()
{
int n = 3;
const float radius = 1.f/countFactor * n;
vector<vector<DMatch> > matches;
// make add() twice to test such case
dmatcher->add( vector<Mat>(1,train.rowRange(0, train.rows/2)) );
dmatcher->add( vector<Mat>(1,train.rowRange(train.rows/2, train.rows)) );
// prepare masks (make first nearest match illegal)
vector<Mat> masks(2);
for(int mi = 0; mi < 2; mi++ )
{
masks[mi] = Mat(query.rows, train.rows/2, CV_8UC1, Scalar::all(1));
for( int di = 0; di < queryDescCount/2; di++ )
masks[mi].col(di*countFactor).setTo(Scalar::all(0));
}
dmatcher->radiusMatch( query, matches, radius, masks );
//int curRes = cvtest::TS::OK;
if( (int)matches.size() != queryDescCount )
{
ts->printf(cvtest::TS::LOG, "Incorrect matches count while test radiusMatch() function (1).\n");
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
}
int badCount = 0;
int shift = dmatcher->isMaskSupported() ? 1 : 0;
int needMatchCount = dmatcher->isMaskSupported() ? n-1 : n;
for( size_t i = 0; i < matches.size(); i++ )
{
if( (int)matches[i].size() != needMatchCount )
badCount++;
else
{
int localBadCount = 0;
for( int k = 0; k < needMatchCount; k++ )
{
DMatch match = matches[i][k];
{
if( i < queryDescCount/2 )
{
if( (match.queryIdx != (int)i) || (match.trainIdx != (int)i*countFactor + k + shift) ||
(match.imgIdx != 0) )
localBadCount++;
}
else
{
if( (match.queryIdx != (int)i) || (match.trainIdx != ((int)i-queryDescCount/2)*countFactor + k + shift) ||
(match.imgIdx != 1) )
localBadCount++;
}
}
}
badCount += localBadCount > 0 ? 1 : 0;
}
}
if( (float)badCount > (float)queryDescCount*badPart )
{
ts->printf( cvtest::TS::LOG, "%f - too large bad matches part while test radiusMatch() function (2).\n",
(float)badCount/(float)queryDescCount );
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
}
}
}
void CV_DescriptorMatcherTest::run( int )
{
Mat query, train;
generateData( query, train );
matchTest( query, train );
knnMatchTest( query, train );
radiusMatchTest( query, train );
}
/****************************************************************************************\
* Tests registrations *
\****************************************************************************************/
#include "features2d/test/test_detectors_regression.impl.hpp"
#include "features2d/test/test_descriptors_regression.impl.hpp"
/*
* Detectors
*/
namespace opencv_test { namespace {
#ifdef OPENCV_ENABLE_NONFREE
TEST( Features2d_Detector_SIFT, regression )
TEST( Features2d_Detector_SIFT, regression)
{
CV_FeatureDetectorTest test( "detector-sift", SIFT::create() );
test.safe_run();
......@@ -1077,9 +143,8 @@ TEST( Features2d_DescriptorExtractor_DAISY, regression )
TEST( Features2d_DescriptorExtractor_FREAK, regression )
{
// TODO adjust the parameters below
CV_DescriptorExtractorTest<Hamming> test( "descriptor-freak", (CV_DescriptorExtractorTest<Hamming>::DistanceType)12.f,
FREAK::create(), IMREAD_GRAYSCALE );
CV_DescriptorExtractorTest<Hamming> test("descriptor-freak", (CV_DescriptorExtractorTest<Hamming>::DistanceType)12.f,
FREAK::create());
test.safe_run();
}
......@@ -1190,23 +255,6 @@ TEST( Features2d_DescriptorExtractor_BINBOOST_256, regression )
}
/*#if CV_SSE2
TEST( Features2d_DescriptorExtractor_Calonder_uchar, regression )
{
CV_CalonderDescriptorExtractorTest<uchar, L2<uchar> > test( "descriptor-calonder-uchar",
std::numeric_limits<float>::epsilon() + 1,
0.0132175f );
test.safe_run();
}
TEST( Features2d_DescriptorExtractor_Calonder_float, regression )
{
CV_CalonderDescriptorExtractorTest<float, L2<float> > test( "descriptor-calonder-float",
std::numeric_limits<float>::epsilon(),
0.0221308f );
test.safe_run();
}
#endif*/ // CV_SSE2
#ifdef OPENCV_ENABLE_NONFREE
TEST(Features2d_BruteForceDescriptorMatcher_knnMatch, regression)
{
......@@ -1259,13 +307,6 @@ TEST(Features2d_BruteForceDescriptorMatcher_knnMatch, regression)
}
#endif
/*TEST(Features2d_DescriptorExtractorParamTest, regression)
{
Ptr<DescriptorExtractor> s = DescriptorExtractor::create("SURF");
ASSERT_STREQ(s->paramHelp("extended").c_str(), "");
}
*/
class CV_DetectPlanarTest : public cvtest::BaseTest
{
public:
......
......@@ -27,21 +27,20 @@ CV_GMSMatcherTest::CV_GMSMatcherTest()
combinations[2][0] = true; combinations[2][1] = false;
combinations[3][0] = true; combinations[3][1] = true;
//Threshold = truncate(min(acc_win32, acc_win64))
eps[0][0] = 0.9313;
eps[0][1] = 0.9223;
eps[0][2] = 0.9313;
eps[0][3] = 0.9223;
eps[1][0] = 0.8199;
eps[1][1] = 0.7964;
eps[1][2] = 0.8199;
eps[1][3] = 0.7964;
eps[2][0] = 0.7098;
eps[2][1] = 0.6659;
eps[2][2] = 0.6939;
eps[2][3] = 0.6457;
eps[0][0] = 0.91;
eps[0][1] = 0.91;
eps[0][2] = 0.91;
eps[0][3] = 0.91;
eps[1][0] = 0.80;
eps[1][1] = 0.78;
eps[1][2] = 0.80;
eps[1][3] = 0.78;
eps[2][0] = 0.70;
eps[2][1] = 0.66;
eps[2][2] = 0.68;
eps[2][3] = 0.63;
correctMatchDistThreshold = 5.0;
}
......@@ -66,7 +65,8 @@ void CV_GMSMatcherTest::run( int )
const int nImgs = 3;
for (int num = startImg; num < startImg+nImgs; num++)
{
string imgPath = string(ts->get_data_path()) + format("detectors_descriptors_evaluation/images_datasets/graf/img%d.png", num);
string fileName = cv::format("img%d.png", num);
string imgPath = string(ts->get_data_path()) + "detectors_descriptors_evaluation/images_datasets/graf/" + fileName;
Mat imgCur = imread(imgPath);
orb->detectAndCompute(imgCur, noArray(), keypointsCur, descriptorsCur);
......@@ -102,14 +102,11 @@ void CV_GMSMatcherTest::run( int )
}
double ratio = nbCorrectMatches / (double) matchesGMS.size();
if (ratio < eps[num-startImg][comb])
{
ts->printf( cvtest::TS::LOG, "Invalid accuracy for image %s and combination withRotation=%d withScale=%d, "
"matches ratio is %f, ratio threshold is %f, distance threshold is %f.\n",
imgPath.substr(imgPath.size()-8).c_str(), combinations[comb][0], combinations[comb][1], ratio,
EXPECT_GT(ratio, eps[num-startImg][comb]) <<
cv::format("Invalid accuracy for image %s and combination withRotation=%d withScale=%d, "
"matches ratio is %g, ratio threshold is %g, distance threshold is %g.",
fileName.c_str(), combinations[comb][0], combinations[comb][1], ratio,
eps[num-startImg][comb], correctMatchDistThreshold);
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
}
}
}
}
......
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// Intel License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of Intel Corporation may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html
#include "test_precomp.hpp"
namespace opencv_test { namespace {
const string IMAGE_TSUKUBA = "/features2d/tsukuba.png";
const string IMAGE_BIKES = "/detectors_descriptors_evaluation/images_datasets/bikes/img1.png";
#define SHOW_DEBUG_LOG 0
static
Mat generateHomography(float angle)
{
// angle - rotation around Oz in degrees
float angleRadian = static_cast<float>(angle * CV_PI / 180);
Mat H = Mat::eye(3, 3, CV_32FC1);
H.at<float>(0,0) = H.at<float>(1,1) = std::cos(angleRadian);
H.at<float>(0,1) = -std::sin(angleRadian);
H.at<float>(1,0) = std::sin(angleRadian);
return H;
}
static
Mat rotateImage(const Mat& srcImage, float angle, Mat& dstImage, Mat& dstMask)
{
// angle - rotation around Oz in degrees
float diag = std::sqrt(static_cast<float>(srcImage.cols * srcImage.cols + srcImage.rows * srcImage.rows));
Mat LUShift = Mat::eye(3, 3, CV_32FC1); // left up
LUShift.at<float>(0,2) = static_cast<float>(-srcImage.cols/2);
LUShift.at<float>(1,2) = static_cast<float>(-srcImage.rows/2);
Mat RDShift = Mat::eye(3, 3, CV_32FC1); // right down
RDShift.at<float>(0,2) = diag/2;
RDShift.at<float>(1,2) = diag/2;
Size sz(cvRound(diag), cvRound(diag));
Mat srcMask(srcImage.size(), CV_8UC1, Scalar(255));
Mat H = RDShift * generateHomography(angle) * LUShift;
warpPerspective(srcImage, dstImage, H, sz);
warpPerspective(srcMask, dstMask, H, sz);
return H;
}
void rotateKeyPoints(const vector<KeyPoint>& src, const Mat& H, float angle, vector<KeyPoint>& dst)
{
// suppose that H is rotation given from rotateImage() and angle has value passed to rotateImage()
vector<Point2f> srcCenters, dstCenters;
KeyPoint::convert(src, srcCenters);
perspectiveTransform(srcCenters, dstCenters, H);
dst = src;
for(size_t i = 0; i < dst.size(); i++)
{
dst[i].pt = dstCenters[i];
float dstAngle = src[i].angle + angle;
if(dstAngle >= 360.f)
dstAngle -= 360.f;
dst[i].angle = dstAngle;
}
}
void scaleKeyPoints(const vector<KeyPoint>& src, vector<KeyPoint>& dst, float scale)
{
dst.resize(src.size());
for(size_t i = 0; i < src.size(); i++)
dst[i] = KeyPoint(src[i].pt.x * scale, src[i].pt.y * scale, src[i].size * scale, src[i].angle);
}
static
float calcCirclesIntersectArea(const Point2f& p0, float r0, const Point2f& p1, float r1)
{
float c = static_cast<float>(cv::norm(p0 - p1)), sqr_c = c * c;
float sqr_r0 = r0 * r0;
float sqr_r1 = r1 * r1;
if(r0 + r1 <= c)
return 0;
#include "features2d/test/test_detectors_invariance.impl.hpp" // main OpenCV repo
#include "features2d/test/test_descriptors_invariance.impl.hpp" // main OpenCV repo
float minR = std::min(r0, r1);
float maxR = std::max(r0, r1);
if(c + minR <= maxR)
return static_cast<float>(CV_PI * minR * minR);
float cos_halfA0 = (sqr_r0 + sqr_c - sqr_r1) / (2 * r0 * c);
float cos_halfA1 = (sqr_r1 + sqr_c - sqr_r0) / (2 * r1 * c);
float A0 = 2 * acos(cos_halfA0);
float A1 = 2 * acos(cos_halfA1);
return 0.5f * sqr_r0 * (A0 - sin(A0)) +
0.5f * sqr_r1 * (A1 - sin(A1));
}
static
float calcIntersectRatio(const Point2f& p0, float r0, const Point2f& p1, float r1)
{
float intersectArea = calcCirclesIntersectArea(p0, r0, p1, r1);
float unionArea = static_cast<float>(CV_PI) * (r0 * r0 + r1 * r1) - intersectArea;
return intersectArea / unionArea;
}
static
void matchKeyPoints(const vector<KeyPoint>& keypoints0, const Mat& H,
const vector<KeyPoint>& keypoints1,
vector<DMatch>& matches)
{
vector<Point2f> points0;
KeyPoint::convert(keypoints0, points0);
Mat points0t;
if(H.empty())
points0t = Mat(points0);
else
perspectiveTransform(Mat(points0), points0t, H);
matches.clear();
vector<uchar> usedMask(keypoints1.size(), 0);
for(int i0 = 0; i0 < static_cast<int>(keypoints0.size()); i0++)
{
int nearestPointIndex = -1;
float maxIntersectRatio = 0.f;
const float r0 = 0.5f * keypoints0[i0].size;
for(size_t i1 = 0; i1 < keypoints1.size(); i1++)
{
float r1 = 0.5f * keypoints1[i1].size;
float intersectRatio = calcIntersectRatio(points0t.at<Point2f>(i0), r0,
keypoints1[i1].pt, r1);
if(intersectRatio > maxIntersectRatio)
{
maxIntersectRatio = intersectRatio;
nearestPointIndex = static_cast<int>(i1);
}
}
matches.push_back(DMatch(i0, nearestPointIndex, maxIntersectRatio));
if(nearestPointIndex >= 0)
usedMask[nearestPointIndex] = 1;
}
}
static void removeVerySmallKeypoints(vector<KeyPoint>& keypoints)
{
size_t i, j = 0, n = keypoints.size();
for( i = 0; i < n; i++ )
{
if( (keypoints[i].octave & 128) != 0 )
;
else
keypoints[j++] = keypoints[i];
}
keypoints.resize(j);
}
namespace opencv_test { namespace {
static const char* const IMAGE_TSUKUBA = "features2d/tsukuba.png";
static const char* const IMAGE_BIKES = "detectors_descriptors_evaluation/images_datasets/bikes/img1.png";
class DetectorRotationInvarianceTest : public cvtest::BaseTest
{
public:
DetectorRotationInvarianceTest(const Ptr<FeatureDetector>& _featureDetector,
float _minKeyPointMatchesRatio,
float _minAngleInliersRatio) :
featureDetector(_featureDetector),
minKeyPointMatchesRatio(_minKeyPointMatchesRatio),
minAngleInliersRatio(_minAngleInliersRatio)
{
CV_Assert(featureDetector);
}
// ========================== ROTATION INVARIANCE =============================
protected:
#ifdef OPENCV_ENABLE_NONFREE
void run(int)
{
const string imageFilename = string(ts->get_data_path()) + IMAGE_TSUKUBA;
// Read test data
Mat image0 = imread(imageFilename), image1, mask1;
if(image0.empty())
{
ts->printf(cvtest::TS::LOG, "Image %s can not be read.\n", imageFilename.c_str());
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
return;
}
vector<KeyPoint> keypoints0;
featureDetector->detect(image0, keypoints0);
removeVerySmallKeypoints(keypoints0);
if(keypoints0.size() < 15)
CV_Error(Error::StsAssert, "Detector gives too few points in a test image\n");
const int maxAngle = 360, angleStep = 15;
for(int angle = 0; angle < maxAngle; angle += angleStep)
{
Mat H = rotateImage(image0, static_cast<float>(angle), image1, mask1);
vector<KeyPoint> keypoints1;
featureDetector->detect(image1, keypoints1, mask1);
removeVerySmallKeypoints(keypoints1);
vector<DMatch> matches;
matchKeyPoints(keypoints0, H, keypoints1, matches);
int angleInliersCount = 0;
const float minIntersectRatio = 0.5f;
int keyPointMatchesCount = 0;
for(size_t m = 0; m < matches.size(); m++)
{
if(matches[m].distance < minIntersectRatio)
continue;
keyPointMatchesCount++;
// Check does this inlier have consistent angles
const float maxAngleDiff = 15.f; // grad
float angle0 = keypoints0[matches[m].queryIdx].angle;
float angle1 = keypoints1[matches[m].trainIdx].angle;
if(angle0 == -1 || angle1 == -1)
CV_Error(Error::StsBadArg, "Given FeatureDetector is not rotation invariant, it can not be tested here.\n");
CV_Assert(angle0 >= 0.f && angle0 < 360.f);
CV_Assert(angle1 >= 0.f && angle1 < 360.f);
float rotAngle0 = angle0 + angle;
if(rotAngle0 >= 360.f)
rotAngle0 -= 360.f;
float angleDiff = std::max(rotAngle0, angle1) - std::min(rotAngle0, angle1);
angleDiff = std::min(angleDiff, static_cast<float>(360.f - angleDiff));
CV_Assert(angleDiff >= 0.f);
bool isAngleCorrect = angleDiff < maxAngleDiff;
if(isAngleCorrect)
angleInliersCount++;
}
float keyPointMatchesRatio = static_cast<float>(keyPointMatchesCount) / keypoints0.size();
if(keyPointMatchesRatio < minKeyPointMatchesRatio)
{
ts->printf(cvtest::TS::LOG, "Incorrect keyPointMatchesRatio: curr = %f, min = %f.\n",
keyPointMatchesRatio, minKeyPointMatchesRatio);
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
return;
}
if(keyPointMatchesCount)
{
float angleInliersRatio = static_cast<float>(angleInliersCount) / keyPointMatchesCount;
if(angleInliersRatio < minAngleInliersRatio)
{
ts->printf(cvtest::TS::LOG, "Incorrect angleInliersRatio: curr = %f, min = %f.\n",
angleInliersRatio, minAngleInliersRatio);
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
return;
}
}
#if SHOW_DEBUG_LOG
std::cout << "keyPointMatchesRatio - " << keyPointMatchesRatio
<< " - angleInliersRatio " << static_cast<float>(angleInliersCount) / keyPointMatchesCount << std::endl;
#endif
}
ts->set_failed_test_info( cvtest::TS::OK );
}
INSTANTIATE_TEST_CASE_P(SURF, DetectorRotationInvariance, Values(
make_tuple(IMAGE_TSUKUBA, SURF::create(), 0.40f, 0.76f)
));
Ptr<FeatureDetector> featureDetector;
float minKeyPointMatchesRatio;
float minAngleInliersRatio;
};
INSTANTIATE_TEST_CASE_P(SIFT, DetectorRotationInvariance, Values(
make_tuple(IMAGE_TSUKUBA, SIFT::create(), 0.45f, 0.70f)
));
class DescriptorRotationInvarianceTest : public cvtest::BaseTest
{
public:
DescriptorRotationInvarianceTest(const Ptr<FeatureDetector>& _featureDetector,
const Ptr<DescriptorExtractor>& _descriptorExtractor,
int _normType,
float _minDescInliersRatio, int imgLoad = IMREAD_COLOR) :
featureDetector(_featureDetector),
descriptorExtractor(_descriptorExtractor),
normType(_normType),
minDescInliersRatio(_minDescInliersRatio),
imgLoadMode(imgLoad)
{
CV_Assert(featureDetector);
CV_Assert(descriptorExtractor);
}
INSTANTIATE_TEST_CASE_P(SURF, DescriptorRotationInvariance, Values(
make_tuple(IMAGE_TSUKUBA, SURF::create(), SURF::create(), 0.83f)
));
protected:
INSTANTIATE_TEST_CASE_P(SIFT, DescriptorRotationInvariance, Values(
make_tuple(IMAGE_TSUKUBA, SIFT::create(), SIFT::create(), 0.98f)
));
void run(int)
{
const string imageFilename = string(ts->get_data_path()) + IMAGE_TSUKUBA;
// Read test data
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());
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
return;
}
vector<KeyPoint> keypoints0;
Mat descriptors0;
featureDetector->detect(image0, keypoints0);
removeVerySmallKeypoints(keypoints0);
if(keypoints0.size() < 15)
CV_Error(Error::StsAssert, "Detector gives too few points in a test image\n");
descriptorExtractor->compute(image0, keypoints0, descriptors0);
BFMatcher bfmatcher(normType);
const float minIntersectRatio = 0.5f;
const int maxAngle = 360, angleStep = 15;
for(int angle = 0; angle < maxAngle; angle += angleStep)
{
Mat H = rotateImage(image0, static_cast<float>(angle), image1, mask1);
vector<KeyPoint> keypoints1;
rotateKeyPoints(keypoints0, H, static_cast<float>(angle), keypoints1);
Mat descriptors1;
descriptorExtractor->compute(image1, keypoints1, descriptors1);
vector<DMatch> descMatches;
bfmatcher.match(descriptors0, descriptors1, descMatches);
int descInliersCount = 0;
for(size_t m = 0; m < descMatches.size(); m++)
{
const KeyPoint& transformed_p0 = keypoints1[descMatches[m].queryIdx];
const KeyPoint& p1 = keypoints1[descMatches[m].trainIdx];
if(calcIntersectRatio(transformed_p0.pt, 0.5f * transformed_p0.size,
p1.pt, 0.5f * p1.size) >= minIntersectRatio)
{
descInliersCount++;
}
}
float descInliersRatio = static_cast<float>(descInliersCount) / keypoints0.size();
if(descInliersRatio < minDescInliersRatio)
{
ts->printf(cvtest::TS::LOG, "Incorrect descInliersRatio: curr = %f, min = %f.\n",
descInliersRatio, minDescInliersRatio);
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
return;
}
#if SHOW_DEBUG_LOG
std::cout << "descInliersRatio " << static_cast<float>(descInliersCount) / keypoints0.size() << std::endl;
#endif
}
ts->set_failed_test_info( cvtest::TS::OK );
}
INSTANTIATE_TEST_CASE_P(LATCH, DescriptorRotationInvariance, Values(
make_tuple(IMAGE_TSUKUBA, SIFT::create(), LATCH::create(), 0.9999f)
));
Ptr<FeatureDetector> featureDetector;
Ptr<DescriptorExtractor> descriptorExtractor;
int normType;
float minDescInliersRatio;
int imgLoadMode;
};
#endif // NONFREE
INSTANTIATE_TEST_CASE_P(DAISY, DescriptorRotationInvariance, Values(
make_tuple(IMAGE_TSUKUBA,
BRISK::create(),
DAISY::create(15, 3, 8, 8, DAISY::NRM_NONE, noArray(), true, true),
0.79f)
));
INSTANTIATE_TEST_CASE_P(VGG120, DescriptorRotationInvariance, Values(
make_tuple(IMAGE_TSUKUBA,
KAZE::create(),
VGG::create(VGG::VGG_120, 1.4f, true, true, 48.0f, false),
0.97f)
));
INSTANTIATE_TEST_CASE_P(VGG80, DescriptorRotationInvariance, Values(
make_tuple(IMAGE_TSUKUBA,
KAZE::create(),
VGG::create(VGG::VGG_80, 1.4f, true, true, 48.0f, false),
0.97f)
));
INSTANTIATE_TEST_CASE_P(VGG64, DescriptorRotationInvariance, Values(
make_tuple(IMAGE_TSUKUBA,
KAZE::create(),
VGG::create(VGG::VGG_64, 1.4f, true, true, 48.0f, false),
0.97f)
));
INSTANTIATE_TEST_CASE_P(VGG48, DescriptorRotationInvariance, Values(
make_tuple(IMAGE_TSUKUBA,
KAZE::create(),
VGG::create(VGG::VGG_48, 1.4f, true, true, 48.0f, false),
0.97f)
));
class DetectorScaleInvarianceTest : public cvtest::BaseTest
{
public:
DetectorScaleInvarianceTest(const Ptr<FeatureDetector>& _featureDetector,
float _minKeyPointMatchesRatio,
float _minScaleInliersRatio) :
featureDetector(_featureDetector),
minKeyPointMatchesRatio(_minKeyPointMatchesRatio),
minScaleInliersRatio(_minScaleInliersRatio)
{
CV_Assert(featureDetector);
}
protected:
#ifdef OPENCV_ENABLE_NONFREE
void run(int)
{
const string imageFilename = string(ts->get_data_path()) + IMAGE_BIKES;
// Read test data
Mat image0 = imread(imageFilename);
if(image0.empty())
{
ts->printf(cvtest::TS::LOG, "Image %s can not be read.\n", imageFilename.c_str());
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
return;
}
vector<KeyPoint> keypoints0;
featureDetector->detect(image0, keypoints0);
removeVerySmallKeypoints(keypoints0);
if(keypoints0.size() < 15)
CV_Error(Error::StsAssert, "Detector gives too few points in a test image\n");
for(int scaleIdx = 1; scaleIdx <= 3; scaleIdx++)
{
float scale = 1.f + scaleIdx * 0.5f;
Mat image1;
resize(image0, image1, Size(), 1./scale, 1./scale, INTER_LINEAR_EXACT);
vector<KeyPoint> keypoints1, osiKeypoints1; // osi - original size image
featureDetector->detect(image1, keypoints1);
removeVerySmallKeypoints(keypoints1);
if(keypoints1.size() < 15)
CV_Error(Error::StsAssert, "Detector gives too few points in a test image\n");
if(keypoints1.size() > keypoints0.size())
{
ts->printf(cvtest::TS::LOG, "Strange behavior of the detector. "
"It gives more points count in an image of the smaller size.\n"
"original size (%d, %d), keypoints count = %d\n"
"reduced size (%d, %d), keypoints count = %d\n",
image0.cols, image0.rows, keypoints0.size(),
image1.cols, image1.rows, keypoints1.size());
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT);
return;
}
scaleKeyPoints(keypoints1, osiKeypoints1, scale);
vector<DMatch> matches;
// image1 is query image (it's reduced image0)
// image0 is train image
matchKeyPoints(osiKeypoints1, Mat(), keypoints0, matches);
const float minIntersectRatio = 0.5f;
int keyPointMatchesCount = 0;
int scaleInliersCount = 0;
for(size_t m = 0; m < matches.size(); m++)
{
if(matches[m].distance < minIntersectRatio)
continue;
keyPointMatchesCount++;
// Check does this inlier have consistent sizes
const float maxSizeDiff = 0.8f;//0.9f; // grad
float size0 = keypoints0[matches[m].trainIdx].size;
float size1 = osiKeypoints1[matches[m].queryIdx].size;
CV_Assert(size0 > 0 && size1 > 0);
if(std::min(size0, size1) > maxSizeDiff * std::max(size0, size1))
scaleInliersCount++;
}
float keyPointMatchesRatio = static_cast<float>(keyPointMatchesCount) / keypoints1.size();
if(keyPointMatchesRatio < minKeyPointMatchesRatio)
{
ts->printf(cvtest::TS::LOG, "Incorrect keyPointMatchesRatio: curr = %f, min = %f.\n",
keyPointMatchesRatio, minKeyPointMatchesRatio);
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
return;
}
if(keyPointMatchesCount)
{
float scaleInliersRatio = static_cast<float>(scaleInliersCount) / keyPointMatchesCount;
if(scaleInliersRatio < minScaleInliersRatio)
{
ts->printf(cvtest::TS::LOG, "Incorrect scaleInliersRatio: curr = %f, min = %f.\n",
scaleInliersRatio, minScaleInliersRatio);
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
return;
}
}
#if SHOW_DEBUG_LOG
std::cout << "keyPointMatchesRatio - " << keyPointMatchesRatio
<< " - scaleInliersRatio " << static_cast<float>(scaleInliersCount) / keyPointMatchesCount << std::endl;
INSTANTIATE_TEST_CASE_P(BRIEF_64, DescriptorRotationInvariance, Values(
make_tuple(IMAGE_TSUKUBA,
SURF::create(),
BriefDescriptorExtractor::create(64,true),
0.98f)
));
INSTANTIATE_TEST_CASE_P(BRIEF_32, DescriptorRotationInvariance, Values(
make_tuple(IMAGE_TSUKUBA,
SURF::create(),
BriefDescriptorExtractor::create(32,true),
0.97f)
));
INSTANTIATE_TEST_CASE_P(BRIEF_16, DescriptorRotationInvariance, Values(
make_tuple(IMAGE_TSUKUBA,
SURF::create(),
BriefDescriptorExtractor::create(16, true),
0.98f)
));
INSTANTIATE_TEST_CASE_P(FREAK, DescriptorRotationInvariance, Values(
make_tuple(IMAGE_TSUKUBA,
SURF::create(),
FREAK::create(),
0.90f)
));
INSTANTIATE_TEST_CASE_P(BoostDesc_BGM, DescriptorRotationInvariance, Values(
make_tuple(IMAGE_TSUKUBA,
SURF::create(),
BoostDesc::create(BoostDesc::BGM, true, 6.25f),
0.999f)
));
INSTANTIATE_TEST_CASE_P(BoostDesc_BGM_HARD, DescriptorRotationInvariance, Values(
make_tuple(IMAGE_TSUKUBA,
SURF::create(),
BoostDesc::create(BoostDesc::BGM_HARD, true, 6.25f),
0.98f)
));
INSTANTIATE_TEST_CASE_P(BoostDesc_BGM_BILINEAR, DescriptorRotationInvariance, Values(
make_tuple(IMAGE_TSUKUBA,
SURF::create(),
BoostDesc::create(BoostDesc::BGM_BILINEAR, true, 6.25f),
0.98f)
));
INSTANTIATE_TEST_CASE_P(BoostDesc_BGM_LBGM, DescriptorRotationInvariance, Values(
make_tuple(IMAGE_TSUKUBA,
SURF::create(),
BoostDesc::create(BoostDesc::LBGM, true, 6.25f),
0.999f)
));
INSTANTIATE_TEST_CASE_P(BoostDesc_BINBOOST_64, DescriptorRotationInvariance, Values(
make_tuple(IMAGE_TSUKUBA,
SURF::create(),
BoostDesc::create(BoostDesc::BINBOOST_64, true, 6.25f),
0.98f)
));
INSTANTIATE_TEST_CASE_P(BoostDesc_BINBOOST_128, DescriptorRotationInvariance, Values(
make_tuple(IMAGE_TSUKUBA,
SURF::create(),
BoostDesc::create(BoostDesc::BINBOOST_128, true, 6.25f),
0.98f)
));
INSTANTIATE_TEST_CASE_P(BoostDesc_BINBOOST_256, DescriptorRotationInvariance, Values(
make_tuple(IMAGE_TSUKUBA,
SURF::create(),
BoostDesc::create(BoostDesc::BINBOOST_256, true, 6.25f),
0.999f)
));
#endif
}
ts->set_failed_test_info( cvtest::TS::OK );
}
Ptr<FeatureDetector> featureDetector;
float minKeyPointMatchesRatio;
float minScaleInliersRatio;
};
class DescriptorScaleInvarianceTest : public cvtest::BaseTest
{
public:
DescriptorScaleInvarianceTest(const Ptr<FeatureDetector>& _featureDetector,
const Ptr<DescriptorExtractor>& _descriptorExtractor,
int _normType,
float _minDescInliersRatio) :
featureDetector(_featureDetector),
descriptorExtractor(_descriptorExtractor),
normType(_normType),
minDescInliersRatio(_minDescInliersRatio)
{
CV_Assert(featureDetector);
CV_Assert(descriptorExtractor);
}
protected:
// ============================ SCALE INVARIANCE ==============================
void run(int)
{
const string imageFilename = string(ts->get_data_path()) + IMAGE_BIKES;
// Read test data
Mat image0 = imread(imageFilename);
if(image0.empty())
{
ts->printf(cvtest::TS::LOG, "Image %s can not be read.\n", imageFilename.c_str());
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
return;
}
vector<KeyPoint> keypoints0;
featureDetector->detect(image0, keypoints0);
removeVerySmallKeypoints(keypoints0);
if(keypoints0.size() < 15)
CV_Error(Error::StsAssert, "Detector gives too few points in a test image\n");
Mat descriptors0;
descriptorExtractor->compute(image0, keypoints0, descriptors0);
BFMatcher bfmatcher(normType);
for(int scaleIdx = 1; scaleIdx <= 3; scaleIdx++)
{
float scale = 1.f + scaleIdx * 0.5f;
Mat image1;
resize(image0, image1, Size(), 1./scale, 1./scale, INTER_LINEAR_EXACT);
vector<KeyPoint> keypoints1;
scaleKeyPoints(keypoints0, keypoints1, 1.0f/scale);
Mat descriptors1;
descriptorExtractor->compute(image1, keypoints1, descriptors1);
vector<DMatch> descMatches;
bfmatcher.match(descriptors0, descriptors1, descMatches);
const float minIntersectRatio = 0.5f;
int descInliersCount = 0;
for(size_t m = 0; m < descMatches.size(); m++)
{
const KeyPoint& transformed_p0 = keypoints0[descMatches[m].queryIdx];
const KeyPoint& p1 = keypoints0[descMatches[m].trainIdx];
if(calcIntersectRatio(transformed_p0.pt, 0.5f * transformed_p0.size,
p1.pt, 0.5f * p1.size) >= minIntersectRatio)
{
descInliersCount++;
}
}
float descInliersRatio = static_cast<float>(descInliersCount) / keypoints0.size();
if(descInliersRatio < minDescInliersRatio)
{
ts->printf(cvtest::TS::LOG, "Incorrect descInliersRatio: curr = %f, min = %f.\n",
descInliersRatio, minDescInliersRatio);
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
return;
}
#if SHOW_DEBUG_LOG
std::cout << "descInliersRatio " << static_cast<float>(descInliersCount) / keypoints0.size() << std::endl;
#endif
}
ts->set_failed_test_info( cvtest::TS::OK );
}
Ptr<FeatureDetector> featureDetector;
Ptr<DescriptorExtractor> descriptorExtractor;
int normType;
float minKeyPointMatchesRatio;
float minDescInliersRatio;
};
// Tests registration
/*
* Detector's rotation invariance check
*/
#ifdef OPENCV_ENABLE_NONFREE
TEST(Features2d_RotationInvariance_Detector_SURF, regression)
{
DetectorRotationInvarianceTest test(SURF::create(),
0.65f,
0.76f);
test.safe_run();
}
TEST(Features2d_RotationInvariance_Detector_SIFT, DISABLED_regression)
{
DetectorRotationInvarianceTest test(SIFT::create(),
0.45f,
0.70f);
test.safe_run();
}
INSTANTIATE_TEST_CASE_P(SURF, DetectorScaleInvariance, Values(
make_tuple(IMAGE_BIKES, SURF::create(), 0.64f, 0.84f)
));
INSTANTIATE_TEST_CASE_P(SIFT, DetectorScaleInvariance, Values(
make_tuple(IMAGE_BIKES, SIFT::create(), 0.55f, 0.99f)
));
INSTANTIATE_TEST_CASE_P(SURF, DescriptorScaleInvariance, Values(
make_tuple(IMAGE_BIKES, SURF::create(), SURF::create(), 0.7f)
));
INSTANTIATE_TEST_CASE_P(SIFT, DescriptorScaleInvariance, Values(
make_tuple(IMAGE_BIKES, SIFT::create(), SIFT::create(), 0.3f)
));
#endif // NONFREE
/*
* Descriptors's rotation invariance check
*/
TEST(Features2d_RotationInvariance_Descriptor_SURF, regression)
{
DescriptorRotationInvarianceTest test(SURF::create(),
SURF::create(),
NORM_L1,
0.83f);
test.safe_run();
}
TEST(Features2d_RotationInvariance_Descriptor_SIFT, regression)
{
DescriptorRotationInvarianceTest test(SIFT::create(),
SIFT::create(),
NORM_L1,
0.98f);
test.safe_run();
}
#if 0 // DAISY is not scale invariant
INSTANTIATE_TEST_CASE_P(DISABLED_DAISY, DescriptorScaleInvariance, Values(
make_tuple(IMAGE_BIKES,
BRISK::create(),
DAISY::create(15, 3, 8, 8, DAISY::NRM_NONE, noArray(), true, true),
0.1f)
));
#endif
TEST(Features2d_RotationInvariance_Descriptor_LATCH, regression)
{
DescriptorRotationInvarianceTest test(SIFT::create(),
LATCH::create(),
NORM_HAMMING,
0.9999f);
test.safe_run();
}
INSTANTIATE_TEST_CASE_P(VGG120, DescriptorScaleInvariance, Values(
make_tuple(IMAGE_BIKES,
KAZE::create(),
VGG::create(VGG::VGG_120, 1.4f, true, true, 48.0f, false),
0.98f)
));
INSTANTIATE_TEST_CASE_P(VGG80, DescriptorScaleInvariance, Values(
make_tuple(IMAGE_BIKES,
KAZE::create(),
VGG::create(VGG::VGG_80, 1.4f, true, true, 48.0f, false),
0.98f)
));
INSTANTIATE_TEST_CASE_P(VGG64, DescriptorScaleInvariance, Values(
make_tuple(IMAGE_BIKES,
KAZE::create(),
VGG::create(VGG::VGG_64, 1.4f, true, true, 48.0f, false),
0.97f)
));
INSTANTIATE_TEST_CASE_P(VGG48, DescriptorScaleInvariance, Values(
make_tuple(IMAGE_BIKES,
KAZE::create(),
VGG::create(VGG::VGG_48, 1.4f, true, true, 48.0f, false),
0.93f)
));
#ifdef OPENCV_ENABLE_NONFREE // SURF detector is used in tests
INSTANTIATE_TEST_CASE_P(BoostDesc_BGM, DescriptorScaleInvariance, Values(
make_tuple(IMAGE_BIKES,
SURF::create(),
BoostDesc::create(BoostDesc::BGM, true, 6.25f),
0.98f)
));
INSTANTIATE_TEST_CASE_P(BoostDesc_BGM_HARD, DescriptorScaleInvariance, Values(
make_tuple(IMAGE_BIKES,
SURF::create(),
BoostDesc::create(BoostDesc::BGM_HARD, true, 6.25f),
0.75f)
));
INSTANTIATE_TEST_CASE_P(BoostDesc_BGM_BILINEAR, DescriptorScaleInvariance, Values(
make_tuple(IMAGE_BIKES,
SURF::create(),
BoostDesc::create(BoostDesc::BGM_BILINEAR, true, 6.25f),
0.95f)
));
INSTANTIATE_TEST_CASE_P(BoostDesc_LBGM, DescriptorScaleInvariance, Values(
make_tuple(IMAGE_BIKES,
SURF::create(),
BoostDesc::create(BoostDesc::LBGM, true, 6.25f),
0.95f)
));
INSTANTIATE_TEST_CASE_P(BoostDesc_BINBOOST_64, DescriptorScaleInvariance, Values(
make_tuple(IMAGE_BIKES,
SURF::create(),
BoostDesc::create(BoostDesc::BINBOOST_64, true, 6.25f),
0.75f)
));
INSTANTIATE_TEST_CASE_P(BoostDesc_BINBOOST_128, DescriptorScaleInvariance, Values(
make_tuple(IMAGE_BIKES,
SURF::create(),
BoostDesc::create(BoostDesc::BINBOOST_128, true, 6.25f),
0.95f)
));
INSTANTIATE_TEST_CASE_P(BoostDesc_BINBOOST_256, DescriptorScaleInvariance, Values(
make_tuple(IMAGE_BIKES,
SURF::create(),
BoostDesc::create(BoostDesc::BINBOOST_256, true, 6.25f),
0.98f)
));
#endif // NONFREE
TEST(DISABLED_Features2d_RotationInvariance_Descriptor_DAISY, regression)
{
DescriptorRotationInvarianceTest test(BRISK::create(),
DAISY::create(15, 3, 8, 8, DAISY::NRM_NONE, noArray(), true, true),
NORM_L1,
0.79f);
test.safe_run();
}
TEST(Features2d_RotationInvariance_Descriptor_VGG120, regression)
{
DescriptorRotationInvarianceTest test(KAZE::create(),
VGG::create(VGG::VGG_120, 1.4f, true, true, 48.0f, false),
NORM_L1,
1.00f);
test.safe_run();
}
TEST(Features2d_RotationInvariance_Descriptor_VGG80, regression)
{
DescriptorRotationInvarianceTest test(KAZE::create(),
VGG::create(VGG::VGG_80, 1.4f, true, true, 48.0f, false),
NORM_L1,
1.00f);
test.safe_run();
}
TEST(Features2d_RotationInvariance_Descriptor_VGG64, regression)
{
DescriptorRotationInvarianceTest test(KAZE::create(),
VGG::create(VGG::VGG_64, 1.4f, true, true, 48.0f, false),
NORM_L1,
1.00f);
test.safe_run();
}
TEST(Features2d_RotationInvariance_Descriptor_VGG48, regression)
{
DescriptorRotationInvarianceTest test(KAZE::create(),
VGG::create(VGG::VGG_48, 1.4f, true, true, 48.0f, false),
NORM_L1,
1.00f);
test.safe_run();
}
// ============================== OTHER TESTS =================================
#ifdef OPENCV_ENABLE_NONFREE
TEST(Features2d_RotationInvariance_Descriptor_BRIEF_64, regression)
{
DescriptorRotationInvarianceTest test(SURF::create(),
BriefDescriptorExtractor::create(64,true),
NORM_L1,
0.98f);
test.safe_run();
}
TEST(Features2d_RotationInvariance_Descriptor_BRIEF_32, regression)
{
DescriptorRotationInvarianceTest test(SURF::create(),
BriefDescriptorExtractor::create(32,true),
NORM_L1,
0.97f);
test.safe_run();
}
TEST(Features2d_RotationInvariance_Descriptor_BRIEF_16, regression)
{
DescriptorRotationInvarianceTest test(SURF::create(),
BriefDescriptorExtractor::create(16,true),
NORM_L1,
0.85f);
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();
}
TEST(Features2d_RotationInvariance_Descriptor_BoostDesc_BGM, regression)
{
DescriptorRotationInvarianceTest test(SURF::create(),
BoostDesc::create(BoostDesc::BGM,true,6.25f),
NORM_HAMMING,
0.999f);
test.safe_run();
}
TEST(Features2d_RotationInvariance_Descriptor_BoostDesc_BGM_HARD, regression)
{
DescriptorRotationInvarianceTest test(SURF::create(),
BoostDesc::create(BoostDesc::BGM_HARD,true,6.25f),
NORM_HAMMING,
0.98f);
test.safe_run();
}
TEST(Features2d_RotationInvariance_Descriptor_BoostDesc_BGM_BILINEAR, regression)
{
DescriptorRotationInvarianceTest test(SURF::create(),
BoostDesc::create(BoostDesc::BGM_BILINEAR,true,6.25f),
NORM_HAMMING,
0.98f);
test.safe_run();
}
TEST(Features2d_RotationInvariance_Descriptor_BoostDesc_LBGM, regression)
{
DescriptorRotationInvarianceTest test(SURF::create(),
BoostDesc::create(BoostDesc::LBGM,true,6.25f),
NORM_L1,
0.999f);
test.safe_run();
}
TEST(Features2d_RotationInvariance_Descriptor_BoostDesc_BINBOOST_64, regression)
{
DescriptorRotationInvarianceTest test(SURF::create(),
BoostDesc::create(BoostDesc::BINBOOST_64,true,6.25f),
NORM_HAMMING,
0.98f);
test.safe_run();
}
TEST(Features2d_RotationInvariance_Descriptor_BoostDesc_BINBOOST_128, regression)
{
DescriptorRotationInvarianceTest test(SURF::create(),
BoostDesc::create(BoostDesc::BINBOOST_128,true,6.25f),
NORM_HAMMING,
0.98f);
test.safe_run();
}
TEST(Features2d_RotationInvariance_Descriptor_BoostDesc_BINBOOST_256, regression)
{
DescriptorRotationInvarianceTest test(SURF::create(),
BoostDesc::create(BoostDesc::BINBOOST_256,true,6.25f),
NORM_HAMMING,
0.999f);
test.safe_run();
}
/*
* Detector's scale invariance check
*/
TEST(Features2d_ScaleInvariance_Detector_SURF, regression)
{
DetectorScaleInvarianceTest test(SURF::create(),
0.64f,
0.84f);
test.safe_run();
}
TEST(Features2d_ScaleInvariance_Detector_SIFT, regression)
{
DetectorScaleInvarianceTest test(SIFT::create(),
0.69f,
0.99f);
test.safe_run();
}
/*
* Descriptor's scale invariance check
*/
TEST(Features2d_ScaleInvariance_Descriptor_SURF, regression)
{
DescriptorScaleInvarianceTest test(SURF::create(),
SURF::create(),
NORM_L1,
0.61f);
test.safe_run();
}
TEST(Features2d_ScaleInvariance_Descriptor_SIFT, regression)
{
DescriptorScaleInvarianceTest test(SIFT::create(),
SIFT::create(),
NORM_L1,
0.78f);
test.safe_run();
}
TEST(Features2d_RotationInvariance2_Detector_SURF, regression)
{
Mat cross(100, 100, CV_8UC1, Scalar(255));
......@@ -872,117 +284,6 @@ TEST(Features2d_RotationInvariance2_Detector_SURF, regression)
ASSERT_LT(fabs(keypoints[i1].response - keypoints[i].response) / keypoints[i1].response, 1e-6);
}
}
#endif // NONFREE
TEST(DISABLED_Features2d_ScaleInvariance_Descriptor_DAISY, regression)
{
DescriptorScaleInvarianceTest test(BRISK::create(),
DAISY::create(15, 3, 8, 8, DAISY::NRM_NONE, noArray(), true, true),
NORM_L1,
0.075f);
test.safe_run();
}
TEST(Features2d_ScaleInvariance_Descriptor_VGG120, regression)
{
DescriptorScaleInvarianceTest test(KAZE::create(),
VGG::create(VGG::VGG_120, 1.4f, true, true, 48.0f, false),
NORM_L1,
0.99f);
test.safe_run();
}
TEST(Features2d_ScaleInvariance_Descriptor_VGG80, regression)
{
DescriptorScaleInvarianceTest test(KAZE::create(),
VGG::create(VGG::VGG_80, 1.4f, true, true, 48.0f, false),
NORM_L1,
0.98f);
test.safe_run();
}
TEST(Features2d_ScaleInvariance_Descriptor_VGG64, regression)
{
DescriptorScaleInvarianceTest test(KAZE::create(),
VGG::create(VGG::VGG_64, 1.4f, true, true, 48.0f, false),
NORM_L1,
0.97f);
test.safe_run();
}
TEST(Features2d_ScaleInvariance_Descriptor_VGG48, regression)
{
DescriptorScaleInvarianceTest test(KAZE::create(),
VGG::create(VGG::VGG_48, 1.4f, true, true, 48.0f, false),
NORM_L1,
0.93f);
test.safe_run();
}
#ifdef OPENCV_ENABLE_NONFREE
TEST(Features2d_ScaleInvariance_Descriptor_BoostDesc_BGM, regression)
{
DescriptorScaleInvarianceTest test(SURF::create(),
BoostDesc::create(BoostDesc::BGM, true, 6.25f),
NORM_HAMMING,
0.98f);
test.safe_run();
}
TEST(Features2d_ScaleInvariance_Descriptor_BoostDesc_BGM_HARD, regression)
{
DescriptorScaleInvarianceTest test(SURF::create(),
BoostDesc::create(BoostDesc::BGM_HARD, true, 6.25f),
NORM_HAMMING,
0.75f);
test.safe_run();
}
TEST(Features2d_ScaleInvariance_Descriptor_BoostDesc_BGM_BILINEAR, regression)
{
DescriptorScaleInvarianceTest test(SURF::create(),
BoostDesc::create(BoostDesc::BGM_BILINEAR, true, 6.25f),
NORM_HAMMING,
0.95f);
test.safe_run();
}
TEST(Features2d_ScaleInvariance_Descriptor_BoostDesc_LBGM, regression)
{
DescriptorScaleInvarianceTest test(SURF::create(),
BoostDesc::create(BoostDesc::LBGM, true, 6.25f),
NORM_L1,
0.95f);
test.safe_run();
}
TEST(Features2d_ScaleInvariance_Descriptor_BoostDesc_BINBOOST_64, regression)
{
DescriptorScaleInvarianceTest test(SURF::create(),
BoostDesc::create(BoostDesc::BINBOOST_64, true, 6.25f),
NORM_HAMMING,
0.75f);
test.safe_run();
}
TEST(Features2d_ScaleInvariance_Descriptor_BoostDesc_BINBOOST_128, regression)
{
DescriptorScaleInvarianceTest test(SURF::create(),
BoostDesc::create(BoostDesc::BINBOOST_128, true, 6.25f),
NORM_HAMMING,
0.95f);
test.safe_run();
}
TEST(Features2d_ScaleInvariance_Descriptor_BoostDesc_BINBOOST_256, regression)
{
DescriptorScaleInvarianceTest test(SURF::create(),
BoostDesc::create(BoostDesc::BINBOOST_256, true, 6.25f),
NORM_HAMMING,
0.98f);
test.safe_run();
}
#endif // NONFREE
}} // namespace
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