2012-07-12 21:57:17 +08:00
|
|
|
/*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*/
|
|
|
|
|
|
|
|
#include "test_precomp.hpp"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace cv;
|
2017-08-04 06:02:47 +08:00
|
|
|
using namespace testing;
|
2012-07-12 21:57:17 +08:00
|
|
|
|
|
|
|
const string FEATURES2D_DIR = "features2d";
|
|
|
|
const string IMAGE_FILENAME = "tsukuba.png";
|
|
|
|
const string DESCRIPTOR_DIR = FEATURES2D_DIR + "/descriptor_extractors";
|
|
|
|
|
|
|
|
/****************************************************************************************\
|
|
|
|
* Regression tests for descriptor extractors. *
|
|
|
|
\****************************************************************************************/
|
|
|
|
static void writeMatInBin( const Mat& mat, const string& filename )
|
|
|
|
{
|
|
|
|
FILE* f = fopen( filename.c_str(), "wb");
|
|
|
|
if( f )
|
|
|
|
{
|
2017-08-03 18:19:51 +08:00
|
|
|
CV_Assert(4 == sizeof(int));
|
2012-07-12 21:57:17 +08:00
|
|
|
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 );
|
2015-08-31 22:30:42 +08:00
|
|
|
int dataSize = (int)(mat.step * mat.rows);
|
2012-07-12 21:57:17 +08:00
|
|
|
fwrite( (void*)&dataSize, sizeof(int), 1, f );
|
2014-08-13 19:08:27 +08:00
|
|
|
fwrite( (void*)mat.ptr(), 1, dataSize, f );
|
2012-07-12 21:57:17 +08:00
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Mat readMatFromBin( const string& filename )
|
|
|
|
{
|
|
|
|
FILE* f = fopen( filename.c_str(), "rb" );
|
|
|
|
if( f )
|
|
|
|
{
|
2017-08-03 18:19:51 +08:00
|
|
|
CV_Assert(4 == sizeof(int));
|
2012-07-12 21:57:17 +08:00
|
|
|
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);
|
|
|
|
|
2013-10-04 21:03:15 +08:00
|
|
|
int step = dataSize / rows / CV_ELEM_SIZE(type);
|
|
|
|
CV_Assert(step >= cols);
|
2013-04-10 19:54:14 +08:00
|
|
|
|
2015-08-31 22:30:42 +08:00
|
|
|
Mat returnMat = Mat(rows, step, type).colRange(0, cols);
|
2013-04-10 19:54:14 +08:00
|
|
|
|
2015-08-31 22:30:42 +08:00
|
|
|
size_t elements_read = fread( returnMat.ptr(), 1, dataSize, f );
|
2012-07-12 21:57:17 +08:00
|
|
|
CV_Assert(elements_read == (size_t)(dataSize));
|
2015-08-31 22:30:42 +08:00
|
|
|
|
2012-07-12 21:57:17 +08:00
|
|
|
fclose(f);
|
|
|
|
|
2015-08-31 22:30:42 +08:00
|
|
|
return returnMat;
|
2012-07-12 21:57:17 +08:00
|
|
|
}
|
|
|
|
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,
|
2014-07-30 22:02:08 +08:00
|
|
|
Distance d = Distance(), Ptr<FeatureDetector> _detector = Ptr<FeatureDetector>()):
|
|
|
|
name(_name), maxDist(_maxDist), dextractor(_dextractor), distance(d) , detector(_detector) {}
|
|
|
|
|
|
|
|
~CV_DescriptorExtractorTest()
|
|
|
|
{
|
|
|
|
}
|
2012-07-12 21:57:17 +08:00
|
|
|
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->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CV_Assert( DataType<ValueType>::type == validDescriptors.type() );
|
|
|
|
|
|
|
|
int dimension = validDescriptors.cols;
|
2017-08-03 18:19:51 +08:00
|
|
|
DistanceType curMaxDist = 0;
|
|
|
|
size_t exact_count = 0, failed_count = 0;
|
2012-07-12 21:57:17 +08:00
|
|
|
for( int y = 0; y < validDescriptors.rows; y++ )
|
|
|
|
{
|
|
|
|
DistanceType dist = distance( validDescriptors.ptr<ValueType>(y), calcDescriptors.ptr<ValueType>(y), dimension );
|
2017-08-03 18:19:51 +08:00
|
|
|
if (dist == 0)
|
|
|
|
exact_count++;
|
2012-07-12 21:57:17 +08:00
|
|
|
if( dist > curMaxDist )
|
2017-08-03 18:19:51 +08:00
|
|
|
{
|
|
|
|
if (dist > maxDist)
|
|
|
|
failed_count++;
|
2012-07-12 21:57:17 +08:00
|
|
|
curMaxDist = dist;
|
2017-08-03 18:19:51 +08:00
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
if (dist > 0)
|
|
|
|
{
|
|
|
|
std::cout << "i=" << y << " fail_count=" << failed_count << " dist=" << dist << std::endl;
|
|
|
|
std::cout << "valid: " << validDescriptors.row(y) << std::endl;
|
|
|
|
std::cout << " calc: " << calcDescriptors.row(y) << std::endl;
|
|
|
|
}
|
|
|
|
#endif
|
2012-07-12 21:57:17 +08:00
|
|
|
}
|
|
|
|
|
2017-08-03 18:19:51 +08:00
|
|
|
float exact_percents = (100 * (float)exact_count / validDescriptors.rows);
|
|
|
|
float failed_percents = (100 * (float)failed_count / validDescriptors.rows);
|
2012-07-12 21:57:17 +08:00
|
|
|
stringstream ss;
|
2017-08-03 18:19:51 +08:00
|
|
|
ss << "Exact count (dist == 0): " << exact_count << " (" << (int)exact_percents << "%)" << std::endl
|
|
|
|
<< "Failed count (dist > " << maxDist << "): " << failed_count << " (" << (int)failed_percents << "%)" << std::endl
|
|
|
|
<< "Max distance between valid and computed descriptors (" << validDescriptors.size() << "): " << curMaxDist;
|
|
|
|
EXPECT_LE(failed_percents, 20.0f);
|
|
|
|
std::cout << ss.str() << std::endl;
|
2012-07-12 21:57:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void emptyDataTest()
|
|
|
|
{
|
2013-08-13 21:30:14 +08:00
|
|
|
assert( dextractor );
|
2012-07-12 21:57:17 +08:00
|
|
|
|
|
|
|
// 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 );
|
|
|
|
}
|
|
|
|
|
2015-12-08 23:24:39 +08:00
|
|
|
RNG rng;
|
|
|
|
image = cvtest::randomMat(rng, Size(50, 50), CV_8UC3, 0, 255, false);
|
2012-07-12 21:57:17 +08:00
|
|
|
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()
|
|
|
|
{
|
2013-08-13 21:30:14 +08:00
|
|
|
assert( dextractor );
|
2012-07-12 21:57:17 +08:00
|
|
|
|
|
|
|
// Read the test image.
|
|
|
|
string imgFilename = string(ts->get_data_path()) + FEATURES2D_DIR + "/" + IMAGE_FILENAME;
|
|
|
|
Mat img = imread( imgFilename );
|
|
|
|
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;
|
|
|
|
}
|
2017-08-03 18:19:51 +08:00
|
|
|
const std::string keypoints_filename = string(ts->get_data_path()) +
|
|
|
|
(detector.empty()
|
|
|
|
? (FEATURES2D_DIR + "/" + std::string("keypoints.xml.gz"))
|
|
|
|
: (DESCRIPTOR_DIR + "/" + name + "_keypoints.xml.gz"));
|
|
|
|
FileStorage fs(keypoints_filename, FileStorage::READ);
|
|
|
|
|
2012-07-12 21:57:17 +08:00
|
|
|
vector<KeyPoint> keypoints;
|
2017-08-03 18:19:51 +08:00
|
|
|
EXPECT_TRUE(fs.isOpened()) << "Keypoint testdata is missing. Re-computing and re-writing keypoints testdata...";
|
|
|
|
if (!fs.isOpened())
|
|
|
|
{
|
|
|
|
fs.open(keypoints_filename, FileStorage::WRITE);
|
|
|
|
ASSERT_TRUE(fs.isOpened()) << "File for writting keypoints can not be opened.";
|
|
|
|
if (detector.empty())
|
|
|
|
{
|
|
|
|
Ptr<ORB> fd = ORB::create();
|
|
|
|
fd->detect(img, keypoints);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
detector->detect(img, keypoints);
|
|
|
|
}
|
|
|
|
write(fs, "keypoints", keypoints);
|
|
|
|
fs.release();
|
2014-07-30 22:02:08 +08:00
|
|
|
}
|
2017-08-03 18:19:51 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
read(fs.getFirstTopLevelNode(), keypoints);
|
|
|
|
fs.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!detector.empty())
|
|
|
|
{
|
|
|
|
vector<KeyPoint> calcKeypoints;
|
|
|
|
detector->detect(img, calcKeypoints);
|
|
|
|
// TODO validate received keypoints
|
|
|
|
int diff = abs((int)calcKeypoints.size() - (int)keypoints.size());
|
|
|
|
if (diff > 0)
|
|
|
|
{
|
|
|
|
std::cout << "Keypoints difference: " << diff << std::endl;
|
|
|
|
EXPECT_LE(diff, (int)(keypoints.size() * 0.03f));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ASSERT_FALSE(keypoints.empty());
|
2014-07-30 22:02:08 +08:00
|
|
|
{
|
2012-07-12 21:57:17 +08:00
|
|
|
Mat calcDescriptors;
|
|
|
|
double t = (double)getTickCount();
|
2017-08-03 18:19:51 +08:00
|
|
|
dextractor->compute(img, keypoints, calcDescriptors);
|
2012-07-12 21:57:17 +08:00
|
|
|
t = getTickCount() - t;
|
2013-04-10 19:54:14 +08:00
|
|
|
ts->printf(cvtest::TS::LOG, "\nAverage time of computing one descriptor = %g ms.\n", t/((double)getTickFrequency()*1000.)/calcDescriptors.rows);
|
2012-07-12 21:57:17 +08:00
|
|
|
|
2017-08-03 18:19:51 +08:00
|
|
|
if (calcDescriptors.rows != (int)keypoints.size())
|
2012-07-12 21:57:17 +08:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-08-03 18:19:51 +08:00
|
|
|
if (calcDescriptors.cols != dextractor->descriptorSize() || calcDescriptors.type() != dextractor->descriptorType())
|
2012-07-12 21:57:17 +08:00
|
|
|
{
|
|
|
|
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();
|
2017-08-03 18:19:51 +08:00
|
|
|
EXPECT_FALSE(validDescriptors.empty()) << "Descriptors testdata is missing. Re-writing descriptors testdata...";
|
|
|
|
if (!validDescriptors.empty())
|
2012-07-12 21:57:17 +08:00
|
|
|
{
|
2017-08-03 18:19:51 +08:00
|
|
|
compareDescriptors(validDescriptors, calcDescriptors);
|
2012-07-12 21:57:17 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-03 18:19:51 +08:00
|
|
|
ASSERT_TRUE(writeDescriptors(calcDescriptors)) << "Descriptors can not be written.";
|
2012-07-12 21:57:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void run(int)
|
|
|
|
{
|
|
|
|
createDescriptorExtractor();
|
2013-08-13 21:30:14 +08:00
|
|
|
if( !dextractor )
|
2012-07-12 21:57:17 +08:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
Distance distance;
|
2014-07-30 22:02:08 +08:00
|
|
|
Ptr<FeatureDetector> detector;
|
2012-07-12 21:57:17 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
CV_DescriptorExtractorTest& operator=(const CV_DescriptorExtractorTest&) { return *this; }
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************************\
|
|
|
|
* Tests registrations *
|
|
|
|
\****************************************************************************************/
|
|
|
|
|
2012-08-23 20:52:01 +08:00
|
|
|
TEST( Features2d_DescriptorExtractor_BRISK, regression )
|
|
|
|
{
|
2014-10-16 02:49:17 +08:00
|
|
|
CV_DescriptorExtractorTest<Hamming> test( "descriptor-brisk",
|
|
|
|
(CV_DescriptorExtractorTest<Hamming>::DistanceType)2.f,
|
|
|
|
BRISK::create() );
|
2012-08-23 20:52:01 +08:00
|
|
|
test.safe_run();
|
|
|
|
}
|
|
|
|
|
2012-07-12 21:57:17 +08:00
|
|
|
TEST( Features2d_DescriptorExtractor_ORB, regression )
|
|
|
|
{
|
|
|
|
// TODO adjust the parameters below
|
2014-10-16 02:49:17 +08:00
|
|
|
CV_DescriptorExtractorTest<Hamming> test( "descriptor-orb",
|
2014-12-22 03:27:03 +08:00
|
|
|
#if CV_NEON
|
|
|
|
(CV_DescriptorExtractorTest<Hamming>::DistanceType)25.f,
|
|
|
|
#else
|
2014-10-16 02:49:17 +08:00
|
|
|
(CV_DescriptorExtractorTest<Hamming>::DistanceType)12.f,
|
2014-12-22 03:27:03 +08:00
|
|
|
#endif
|
2014-10-16 02:49:17 +08:00
|
|
|
ORB::create() );
|
2012-07-12 21:57:17 +08:00
|
|
|
test.safe_run();
|
|
|
|
}
|
|
|
|
|
2014-07-30 22:02:08 +08:00
|
|
|
TEST( Features2d_DescriptorExtractor_KAZE, regression )
|
|
|
|
{
|
|
|
|
CV_DescriptorExtractorTest< L2<float> > test( "descriptor-kaze", 0.03f,
|
2014-10-16 02:49:17 +08:00
|
|
|
KAZE::create(),
|
2014-10-17 00:58:29 +08:00
|
|
|
L2<float>(), KAZE::create() );
|
2014-07-30 22:02:08 +08:00
|
|
|
test.safe_run();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST( Features2d_DescriptorExtractor_AKAZE, regression )
|
|
|
|
{
|
2014-10-16 02:49:17 +08:00
|
|
|
CV_DescriptorExtractorTest<Hamming> test( "descriptor-akaze",
|
2017-08-03 18:19:51 +08:00
|
|
|
(CV_DescriptorExtractorTest<Hamming>::DistanceType)(486*0.05f),
|
2014-10-16 02:49:17 +08:00
|
|
|
AKAZE::create(),
|
|
|
|
Hamming(), AKAZE::create());
|
2014-07-30 22:02:08 +08:00
|
|
|
test.safe_run();
|
2017-06-21 19:33:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST( Features2d_DescriptorExtractor_AKAZE_DESCRIPTOR_KAZE, regression )
|
|
|
|
{
|
|
|
|
CV_DescriptorExtractorTest< L2<float> > test( "descriptor-akaze-with-kaze-desc", 0.03f,
|
|
|
|
AKAZE::create(AKAZE::DESCRIPTOR_KAZE),
|
|
|
|
L2<float>(), AKAZE::create(AKAZE::DESCRIPTOR_KAZE));
|
|
|
|
test.safe_run();
|
2014-07-30 22:02:08 +08:00
|
|
|
}
|
2015-05-19 00:01:00 +08:00
|
|
|
|
|
|
|
TEST( Features2d_DescriptorExtractor, batch )
|
|
|
|
{
|
|
|
|
string path = string(cvtest::TS::ptr()->get_data_path() + "detectors_descriptors_evaluation/images_datasets/graf");
|
|
|
|
vector<Mat> imgs, descriptors;
|
|
|
|
vector<vector<KeyPoint> > keypoints;
|
|
|
|
int i, n = 6;
|
|
|
|
Ptr<ORB> orb = ORB::create();
|
|
|
|
|
|
|
|
for( i = 0; i < n; i++ )
|
|
|
|
{
|
|
|
|
string imgname = format("%s/img%d.png", path.c_str(), i+1);
|
|
|
|
Mat img = imread(imgname, 0);
|
|
|
|
imgs.push_back(img);
|
|
|
|
}
|
|
|
|
|
|
|
|
orb->detect(imgs, keypoints);
|
|
|
|
orb->compute(imgs, keypoints, descriptors);
|
|
|
|
|
|
|
|
ASSERT_EQ((int)keypoints.size(), n);
|
|
|
|
ASSERT_EQ((int)descriptors.size(), n);
|
|
|
|
|
|
|
|
for( i = 0; i < n; i++ )
|
|
|
|
{
|
|
|
|
EXPECT_GT((int)keypoints[i].size(), 100);
|
|
|
|
EXPECT_GT(descriptors[i].rows, 100);
|
|
|
|
}
|
|
|
|
}
|
2015-05-19 02:16:53 +08:00
|
|
|
|
2017-08-04 06:02:47 +08:00
|
|
|
class DescriptorImage : public TestWithParam<std::string>
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
virtual void SetUp() {
|
|
|
|
pattern = GetParam();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string pattern;
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_P(DescriptorImage, no_crash)
|
2015-05-19 02:16:53 +08:00
|
|
|
{
|
|
|
|
vector<String> fnames;
|
2017-08-04 06:02:47 +08:00
|
|
|
glob(cvtest::TS::ptr()->get_data_path() + pattern, fnames, false);
|
2015-05-19 02:16:53 +08:00
|
|
|
sort(fnames.begin(), fnames.end());
|
|
|
|
|
2017-08-04 06:02:47 +08:00
|
|
|
Ptr<AKAZE> akaze_mldb = AKAZE::create(AKAZE::DESCRIPTOR_MLDB);
|
|
|
|
Ptr<AKAZE> akaze_mldb_upright = AKAZE::create(AKAZE::DESCRIPTOR_MLDB_UPRIGHT);
|
|
|
|
Ptr<AKAZE> akaze_mldb_256 = AKAZE::create(AKAZE::DESCRIPTOR_MLDB, 256);
|
|
|
|
Ptr<AKAZE> akaze_mldb_upright_256 = AKAZE::create(AKAZE::DESCRIPTOR_MLDB_UPRIGHT, 256);
|
|
|
|
Ptr<AKAZE> akaze_kaze = AKAZE::create(AKAZE::DESCRIPTOR_KAZE);
|
|
|
|
Ptr<AKAZE> akaze_kaze_upright = AKAZE::create(AKAZE::DESCRIPTOR_KAZE_UPRIGHT);
|
2015-05-19 02:16:53 +08:00
|
|
|
Ptr<ORB> orb = ORB::create();
|
|
|
|
Ptr<KAZE> kaze = KAZE::create();
|
|
|
|
Ptr<BRISK> brisk = BRISK::create();
|
2017-08-04 06:02:47 +08:00
|
|
|
size_t n = fnames.size();
|
2015-05-19 02:16:53 +08:00
|
|
|
vector<KeyPoint> keypoints;
|
|
|
|
Mat descriptors;
|
2015-05-21 20:03:17 +08:00
|
|
|
orb->setMaxFeatures(5000);
|
2015-05-19 02:16:53 +08:00
|
|
|
|
2017-08-04 06:02:47 +08:00
|
|
|
for(size_t i = 0; i < n; i++ )
|
2015-05-19 02:16:53 +08:00
|
|
|
{
|
|
|
|
printf("%d. image: %s:\n", (int)i, fnames[i].c_str());
|
2015-05-21 20:03:17 +08:00
|
|
|
if( strstr(fnames[i].c_str(), "MP.png") != 0 )
|
2017-08-04 06:02:47 +08:00
|
|
|
{
|
|
|
|
printf("\tskip\n");
|
2015-05-21 20:03:17 +08:00
|
|
|
continue;
|
2017-08-04 06:02:47 +08:00
|
|
|
}
|
2015-05-19 02:16:53 +08:00
|
|
|
bool checkCount = strstr(fnames[i].c_str(), "templ.png") == 0;
|
|
|
|
|
|
|
|
Mat img = imread(fnames[i], -1);
|
|
|
|
|
2017-08-04 06:02:47 +08:00
|
|
|
printf("\t%dx%d\n", img.cols, img.rows);
|
|
|
|
|
|
|
|
#define TEST_DETECTOR(name, descriptor) \
|
|
|
|
keypoints.clear(); descriptors.release(); \
|
|
|
|
printf("\t" name "\n"); fflush(stdout); \
|
|
|
|
descriptor->detectAndCompute(img, noArray(), keypoints, descriptors); \
|
|
|
|
printf("\t\t\t(%d keypoints, descriptor size = %d)\n", (int)keypoints.size(), descriptors.cols); fflush(stdout); \
|
|
|
|
if (checkCount) \
|
|
|
|
{ \
|
|
|
|
EXPECT_GT((int)keypoints.size(), 0); \
|
|
|
|
} \
|
2015-05-19 02:16:53 +08:00
|
|
|
ASSERT_EQ(descriptors.rows, (int)keypoints.size());
|
|
|
|
|
2017-08-04 06:02:47 +08:00
|
|
|
TEST_DETECTOR("AKAZE:MLDB", akaze_mldb);
|
|
|
|
TEST_DETECTOR("AKAZE:MLDB_UPRIGHT", akaze_mldb_upright);
|
|
|
|
TEST_DETECTOR("AKAZE:MLDB_256", akaze_mldb_256);
|
|
|
|
TEST_DETECTOR("AKAZE:MLDB_UPRIGHT_256", akaze_mldb_upright_256);
|
|
|
|
TEST_DETECTOR("AKAZE:KAZE", akaze_kaze);
|
|
|
|
TEST_DETECTOR("AKAZE:KAZE_UPRIGHT", akaze_kaze_upright);
|
|
|
|
TEST_DETECTOR("KAZE", kaze);
|
|
|
|
TEST_DETECTOR("ORB", orb);
|
|
|
|
TEST_DETECTOR("BRISK", brisk);
|
2015-05-19 02:16:53 +08:00
|
|
|
}
|
|
|
|
}
|
2017-08-04 06:02:47 +08:00
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(Features2d, DescriptorImage,
|
|
|
|
testing::Values(
|
|
|
|
"shared/lena.png",
|
|
|
|
"shared/box*.png",
|
|
|
|
"shared/fruits*.png",
|
|
|
|
"shared/airplane.png",
|
|
|
|
"shared/graffiti.png",
|
|
|
|
"shared/1_itseez-0001*.png",
|
|
|
|
"shared/pic*.png",
|
|
|
|
"shared/templ.png"
|
|
|
|
)
|
|
|
|
);
|