opencv/modules/features2d/test/test_descriptors_regression.cpp

212 lines
7.1 KiB
C++
Raw Normal View History

// 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
2012-07-12 21:57:17 +08:00
#include "test_precomp.hpp"
namespace opencv_test { namespace {
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";
}} // namespace
2012-07-12 21:57:17 +08:00
#include "test_descriptors_regression.impl.hpp"
2012-07-12 21:57:17 +08:00
namespace opencv_test { namespace {
2012-07-12 21:57:17 +08:00
/****************************************************************************************\
* Tests registrations *
\****************************************************************************************/
TEST( Features2d_DescriptorExtractor_SIFT, regression )
{
CV_DescriptorExtractorTest<L1<float> > test( "descriptor-sift", 1.0f,
SIFT::create() );
test.safe_run();
}
TEST( Features2d_DescriptorExtractor_BRISK, regression )
{
CV_DescriptorExtractorTest<Hamming> test( "descriptor-brisk",
(CV_DescriptorExtractorTest<Hamming>::DistanceType)2.f,
BRISK::create() );
test.safe_run();
}
2012-07-12 21:57:17 +08:00
TEST( Features2d_DescriptorExtractor_ORB, regression )
{
// TODO adjust the parameters below
CV_DescriptorExtractorTest<Hamming> test( "descriptor-orb",
#if CV_NEON
(CV_DescriptorExtractorTest<Hamming>::DistanceType)25.f,
#else
(CV_DescriptorExtractorTest<Hamming>::DistanceType)12.f,
#endif
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,
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 )
{
CV_DescriptorExtractorTest<Hamming> test( "descriptor-akaze",
(CV_DescriptorExtractorTest<Hamming>::DistanceType)(486*0.05f),
AKAZE::create(),
Hamming(), AKAZE::create());
2014-07-30 22:02:08 +08:00
test.safe_run();
Merge pull request #8869 from hrnr:akaze_part1 [GSOC] Speeding-up AKAZE, part #1 (#8869) * ts: expand arguments before stringifications in CV_ENUM and CV_FLAGS added protective macros to always force macro expansion of arguments. This allows using CV_ENUM and CV_FLAGS with macro arguments. * feature2d: unify perf test use the same test for all detectors/descriptors we have. * added AKAZE tests * features2d: extend perf tests * add BRISK, KAZE, MSER * run all extract tests on AKAZE keypoints, so that the test si more comparable for the speed of extraction * feature2d: rework opencl perf tests use the same configuration as cpu tests * feature2d: fix descriptors allocation for AKAZE and KAZE fix crash when descriptors are UMat * feature2d: name enum to fix build with older gcc * Revert "ts: expand arguments before stringifications in CV_ENUM and CV_FLAGS" This reverts commit 19538cac1e45b0cec98190cf06a5ecb07d9b596e. This wasn't a great idea after all. There is a lot of flags implemented as #define, that we don't want to expand. * feature2d: fix expansion problems with CV_ENUM in perf * expand arguments before passing them to CV_ENUM. This does not need modifications of CV_ENUM. * added include guards to `perf_feature2d.hpp` * feature2d: fix crash in AKAZE when using KAZE descriptors * out-of-bound access in Get_MSURF_Descriptor_64 * this happened reliably when running on provided keypoints (not computed by the same instance) * feature2d: added regression tests for AKAZE * test with both MLDB and KAZE keypoints * feature2d: do not compute keypoints orientation twice * always compute keypoints orientation, when computing keypoints * do not recompute keypoint orientation when computing descriptors this allows to test detection and extraction separately * features2d: fix crash in AKAZE * out-of-bound reads near the image edge * same as the bug in KAZE descriptors * feature2d: refactor invariance testing * split detectors and descriptors tests * rewrite to google test to simplify debugging * add tests for AKAZE and one test for ORB * stitching: add tests with AKAZE feature finder * added basic stitching cpu and ocl tests * fix bug in AKAZE wrapper for stitching pipeline causing lots of ! OPENCV warning: getUMat()/getMat() call chain possible problem. ! Base object is dead, while nested/derived object is still alive or processed. ! Please check lifetime of UMat/Mat objects!
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
}
TEST( Features2d_DescriptorExtractor, batch_ORB )
{
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, IMREAD_GRAYSCALE);
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);
}
}
TEST( Features2d_DescriptorExtractor, batch_SIFT )
{
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<SIFT> sift = SIFT::create();
for( i = 0; i < n; i++ )
{
string imgname = format("%s/img%d.png", path.c_str(), i+1);
Mat img = imread(imgname, IMREAD_GRAYSCALE);
imgs.push_back(img);
}
sift->detect(imgs, keypoints);
sift->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);
}
}
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)
{
vector<String> fnames;
2017-08-04 06:02:47 +08:00
glob(cvtest::TS::ptr()->get_data_path() + pattern, fnames, false);
2023-09-06 18:45:28 +08:00
std::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);
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();
vector<KeyPoint> keypoints;
Mat descriptors;
orb->setMaxFeatures(5000);
2017-08-04 06:02:47 +08:00
for(size_t i = 0; i < n; i++ )
{
printf("%d. image: %s:\n", (int)i, fnames[i].c_str());
if( strstr(fnames[i].c_str(), "MP.png") != 0 )
2017-08-04 06:02:47 +08:00
{
printf("\tskip\n");
continue;
2017-08-04 06:02:47 +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); \
} \
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);
}
}
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"
)
);
}} // namespace