Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/features2d/test/test_descriptors_regression.cpp
16354 views
1
// This file is part of OpenCV project.
2
// It is subject to the license terms in the LICENSE file found in the top-level directory
3
// of this distribution and at http://opencv.org/license.html
4
5
#include "test_precomp.hpp"
6
7
namespace opencv_test { namespace {
8
const string FEATURES2D_DIR = "features2d";
9
const string IMAGE_FILENAME = "tsukuba.png";
10
const string DESCRIPTOR_DIR = FEATURES2D_DIR + "/descriptor_extractors";
11
}} // namespace
12
13
#include "test_descriptors_regression.impl.hpp"
14
15
namespace opencv_test { namespace {
16
17
/****************************************************************************************\
18
* Tests registrations *
19
\****************************************************************************************/
20
21
TEST( Features2d_DescriptorExtractor_BRISK, regression )
22
{
23
CV_DescriptorExtractorTest<Hamming> test( "descriptor-brisk",
24
(CV_DescriptorExtractorTest<Hamming>::DistanceType)2.f,
25
BRISK::create() );
26
test.safe_run();
27
}
28
29
TEST( Features2d_DescriptorExtractor_ORB, regression )
30
{
31
// TODO adjust the parameters below
32
CV_DescriptorExtractorTest<Hamming> test( "descriptor-orb",
33
#if CV_NEON
34
(CV_DescriptorExtractorTest<Hamming>::DistanceType)25.f,
35
#else
36
(CV_DescriptorExtractorTest<Hamming>::DistanceType)12.f,
37
#endif
38
ORB::create() );
39
test.safe_run();
40
}
41
42
TEST( Features2d_DescriptorExtractor_KAZE, regression )
43
{
44
CV_DescriptorExtractorTest< L2<float> > test( "descriptor-kaze", 0.03f,
45
KAZE::create(),
46
L2<float>(), KAZE::create() );
47
test.safe_run();
48
}
49
50
TEST( Features2d_DescriptorExtractor_AKAZE, regression )
51
{
52
CV_DescriptorExtractorTest<Hamming> test( "descriptor-akaze",
53
(CV_DescriptorExtractorTest<Hamming>::DistanceType)(486*0.05f),
54
AKAZE::create(),
55
Hamming(), AKAZE::create());
56
test.safe_run();
57
}
58
59
TEST( Features2d_DescriptorExtractor_AKAZE_DESCRIPTOR_KAZE, regression )
60
{
61
CV_DescriptorExtractorTest< L2<float> > test( "descriptor-akaze-with-kaze-desc", 0.03f,
62
AKAZE::create(AKAZE::DESCRIPTOR_KAZE),
63
L2<float>(), AKAZE::create(AKAZE::DESCRIPTOR_KAZE));
64
test.safe_run();
65
}
66
67
TEST( Features2d_DescriptorExtractor, batch )
68
{
69
string path = string(cvtest::TS::ptr()->get_data_path() + "detectors_descriptors_evaluation/images_datasets/graf");
70
vector<Mat> imgs, descriptors;
71
vector<vector<KeyPoint> > keypoints;
72
int i, n = 6;
73
Ptr<ORB> orb = ORB::create();
74
75
for( i = 0; i < n; i++ )
76
{
77
string imgname = format("%s/img%d.png", path.c_str(), i+1);
78
Mat img = imread(imgname, 0);
79
imgs.push_back(img);
80
}
81
82
orb->detect(imgs, keypoints);
83
orb->compute(imgs, keypoints, descriptors);
84
85
ASSERT_EQ((int)keypoints.size(), n);
86
ASSERT_EQ((int)descriptors.size(), n);
87
88
for( i = 0; i < n; i++ )
89
{
90
EXPECT_GT((int)keypoints[i].size(), 100);
91
EXPECT_GT(descriptors[i].rows, 100);
92
}
93
}
94
95
class DescriptorImage : public TestWithParam<std::string>
96
{
97
protected:
98
virtual void SetUp() {
99
pattern = GetParam();
100
}
101
102
std::string pattern;
103
};
104
105
TEST_P(DescriptorImage, no_crash)
106
{
107
vector<String> fnames;
108
glob(cvtest::TS::ptr()->get_data_path() + pattern, fnames, false);
109
sort(fnames.begin(), fnames.end());
110
111
Ptr<AKAZE> akaze_mldb = AKAZE::create(AKAZE::DESCRIPTOR_MLDB);
112
Ptr<AKAZE> akaze_mldb_upright = AKAZE::create(AKAZE::DESCRIPTOR_MLDB_UPRIGHT);
113
Ptr<AKAZE> akaze_mldb_256 = AKAZE::create(AKAZE::DESCRIPTOR_MLDB, 256);
114
Ptr<AKAZE> akaze_mldb_upright_256 = AKAZE::create(AKAZE::DESCRIPTOR_MLDB_UPRIGHT, 256);
115
Ptr<AKAZE> akaze_kaze = AKAZE::create(AKAZE::DESCRIPTOR_KAZE);
116
Ptr<AKAZE> akaze_kaze_upright = AKAZE::create(AKAZE::DESCRIPTOR_KAZE_UPRIGHT);
117
Ptr<ORB> orb = ORB::create();
118
Ptr<KAZE> kaze = KAZE::create();
119
Ptr<BRISK> brisk = BRISK::create();
120
size_t n = fnames.size();
121
vector<KeyPoint> keypoints;
122
Mat descriptors;
123
orb->setMaxFeatures(5000);
124
125
for(size_t i = 0; i < n; i++ )
126
{
127
printf("%d. image: %s:\n", (int)i, fnames[i].c_str());
128
if( strstr(fnames[i].c_str(), "MP.png") != 0 )
129
{
130
printf("\tskip\n");
131
continue;
132
}
133
bool checkCount = strstr(fnames[i].c_str(), "templ.png") == 0;
134
135
Mat img = imread(fnames[i], -1);
136
137
printf("\t%dx%d\n", img.cols, img.rows);
138
139
#define TEST_DETECTOR(name, descriptor) \
140
keypoints.clear(); descriptors.release(); \
141
printf("\t" name "\n"); fflush(stdout); \
142
descriptor->detectAndCompute(img, noArray(), keypoints, descriptors); \
143
printf("\t\t\t(%d keypoints, descriptor size = %d)\n", (int)keypoints.size(), descriptors.cols); fflush(stdout); \
144
if (checkCount) \
145
{ \
146
EXPECT_GT((int)keypoints.size(), 0); \
147
} \
148
ASSERT_EQ(descriptors.rows, (int)keypoints.size());
149
150
TEST_DETECTOR("AKAZE:MLDB", akaze_mldb);
151
TEST_DETECTOR("AKAZE:MLDB_UPRIGHT", akaze_mldb_upright);
152
TEST_DETECTOR("AKAZE:MLDB_256", akaze_mldb_256);
153
TEST_DETECTOR("AKAZE:MLDB_UPRIGHT_256", akaze_mldb_upright_256);
154
TEST_DETECTOR("AKAZE:KAZE", akaze_kaze);
155
TEST_DETECTOR("AKAZE:KAZE_UPRIGHT", akaze_kaze_upright);
156
TEST_DETECTOR("KAZE", kaze);
157
TEST_DETECTOR("ORB", orb);
158
TEST_DETECTOR("BRISK", brisk);
159
}
160
}
161
162
INSTANTIATE_TEST_CASE_P(Features2d, DescriptorImage,
163
testing::Values(
164
"shared/lena.png",
165
"shared/box*.png",
166
"shared/fruits*.png",
167
"shared/airplane.png",
168
"shared/graffiti.png",
169
"shared/1_itseez-0001*.png",
170
"shared/pic*.png",
171
"shared/templ.png"
172
)
173
);
174
175
}} // namespace
176
177