Skip to content

Commit 94dbc35

Browse files
committed
features2d(test): more AKAZE tests
1 parent ad2e864 commit 94dbc35

File tree

3 files changed

+64
-44
lines changed

3 files changed

+64
-44
lines changed

modules/features2d/src/kaze/AKAZEFeatures.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2144,7 +2144,8 @@ void generateDescriptorSubsample(Mat& sampleList, Mat& comparisons, int nbits,
21442144
}
21452145
ssz *= nchannels;
21462146

2147-
CV_Assert(nbits <= ssz); // Descriptor size can't be bigger than full descriptor
2147+
CV_Assert(ssz == 162*nchannels);
2148+
CV_Assert(nbits <= ssz && "Descriptor size can't be bigger than full descriptor (486 = 162*3 - 3 channels)");
21482149

21492150
// Since the full descriptor is usually under 10k elements, we pick
21502151
// the selection from the full matrix. We take as many samples per

modules/features2d/test/test_descriptors_regression.cpp

Lines changed: 57 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
using namespace std;
4545
using namespace cv;
46+
using namespace testing;
4647

4748
const string FEATURES2D_DIR = "features2d";
4849
const string IMAGE_FILENAME = "tsukuba.png";
@@ -417,68 +418,82 @@ TEST( Features2d_DescriptorExtractor, batch )
417418
}
418419
}
419420

420-
TEST( Features2d_Feature2d, no_crash )
421+
class DescriptorImage : public TestWithParam<std::string>
422+
{
423+
protected:
424+
virtual void SetUp() {
425+
pattern = GetParam();
426+
}
427+
428+
std::string pattern;
429+
};
430+
431+
TEST_P(DescriptorImage, no_crash)
421432
{
422-
const String& pattern = string(cvtest::TS::ptr()->get_data_path() + "shared/*.png");
423433
vector<String> fnames;
424-
glob(pattern, fnames, false);
434+
glob(cvtest::TS::ptr()->get_data_path() + pattern, fnames, false);
425435
sort(fnames.begin(), fnames.end());
426436

427-
Ptr<AKAZE> akaze = AKAZE::create();
437+
Ptr<AKAZE> akaze_mldb = AKAZE::create(AKAZE::DESCRIPTOR_MLDB);
438+
Ptr<AKAZE> akaze_mldb_upright = AKAZE::create(AKAZE::DESCRIPTOR_MLDB_UPRIGHT);
439+
Ptr<AKAZE> akaze_mldb_256 = AKAZE::create(AKAZE::DESCRIPTOR_MLDB, 256);
440+
Ptr<AKAZE> akaze_mldb_upright_256 = AKAZE::create(AKAZE::DESCRIPTOR_MLDB_UPRIGHT, 256);
441+
Ptr<AKAZE> akaze_kaze = AKAZE::create(AKAZE::DESCRIPTOR_KAZE);
442+
Ptr<AKAZE> akaze_kaze_upright = AKAZE::create(AKAZE::DESCRIPTOR_KAZE_UPRIGHT);
428443
Ptr<ORB> orb = ORB::create();
429444
Ptr<KAZE> kaze = KAZE::create();
430445
Ptr<BRISK> brisk = BRISK::create();
431-
size_t i, n = fnames.size();
446+
size_t n = fnames.size();
432447
vector<KeyPoint> keypoints;
433448
Mat descriptors;
434449
orb->setMaxFeatures(5000);
435450

436-
for( i = 0; i < n; i++ )
451+
for(size_t i = 0; i < n; i++ )
437452
{
438453
printf("%d. image: %s:\n", (int)i, fnames[i].c_str());
439454
if( strstr(fnames[i].c_str(), "MP.png") != 0 )
455+
{
456+
printf("\tskip\n");
440457
continue;
458+
}
441459
bool checkCount = strstr(fnames[i].c_str(), "templ.png") == 0;
442460

443461
Mat img = imread(fnames[i], -1);
444-
printf("\tAKAZE ... "); fflush(stdout);
445-
akaze->detectAndCompute(img, noArray(), keypoints, descriptors);
446-
printf("(%d keypoints) ", (int)keypoints.size()); fflush(stdout);
447-
if( checkCount )
448-
{
449-
EXPECT_GT((int)keypoints.size(), 0);
450-
}
451-
ASSERT_EQ(descriptors.rows, (int)keypoints.size());
452-
printf("ok\n");
453462

454-
printf("\tKAZE ... "); fflush(stdout);
455-
kaze->detectAndCompute(img, noArray(), keypoints, descriptors);
456-
printf("(%d keypoints) ", (int)keypoints.size()); fflush(stdout);
457-
if( checkCount )
458-
{
459-
EXPECT_GT((int)keypoints.size(), 0);
460-
}
463+
printf("\t%dx%d\n", img.cols, img.rows);
464+
465+
#define TEST_DETECTOR(name, descriptor) \
466+
keypoints.clear(); descriptors.release(); \
467+
printf("\t" name "\n"); fflush(stdout); \
468+
descriptor->detectAndCompute(img, noArray(), keypoints, descriptors); \
469+
printf("\t\t\t(%d keypoints, descriptor size = %d)\n", (int)keypoints.size(), descriptors.cols); fflush(stdout); \
470+
if (checkCount) \
471+
{ \
472+
EXPECT_GT((int)keypoints.size(), 0); \
473+
} \
461474
ASSERT_EQ(descriptors.rows, (int)keypoints.size());
462-
printf("ok\n");
463475

464-
printf("\tORB ... "); fflush(stdout);
465-
orb->detectAndCompute(img, noArray(), keypoints, descriptors);
466-
printf("(%d keypoints) ", (int)keypoints.size()); fflush(stdout);
467-
if( checkCount )
468-
{
469-
EXPECT_GT((int)keypoints.size(), 0);
470-
}
471-
ASSERT_EQ(descriptors.rows, (int)keypoints.size());
472-
printf("ok\n");
473-
474-
printf("\tBRISK ... "); fflush(stdout);
475-
brisk->detectAndCompute(img, noArray(), keypoints, descriptors);
476-
printf("(%d keypoints) ", (int)keypoints.size()); fflush(stdout);
477-
if( checkCount )
478-
{
479-
EXPECT_GT((int)keypoints.size(), 0);
480-
}
481-
ASSERT_EQ(descriptors.rows, (int)keypoints.size());
482-
printf("ok\n");
476+
TEST_DETECTOR("AKAZE:MLDB", akaze_mldb);
477+
TEST_DETECTOR("AKAZE:MLDB_UPRIGHT", akaze_mldb_upright);
478+
TEST_DETECTOR("AKAZE:MLDB_256", akaze_mldb_256);
479+
TEST_DETECTOR("AKAZE:MLDB_UPRIGHT_256", akaze_mldb_upright_256);
480+
TEST_DETECTOR("AKAZE:KAZE", akaze_kaze);
481+
TEST_DETECTOR("AKAZE:KAZE_UPRIGHT", akaze_kaze_upright);
482+
TEST_DETECTOR("KAZE", kaze);
483+
TEST_DETECTOR("ORB", orb);
484+
TEST_DETECTOR("BRISK", brisk);
483485
}
484486
}
487+
488+
INSTANTIATE_TEST_CASE_P(Features2d, DescriptorImage,
489+
testing::Values(
490+
"shared/lena.png",
491+
"shared/box*.png",
492+
"shared/fruits*.png",
493+
"shared/airplane.png",
494+
"shared/graffiti.png",
495+
"shared/1_itseez-0001*.png",
496+
"shared/pic*.png",
497+
"shared/templ.png"
498+
)
499+
);

modules/ts/misc/run_long.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
LONG_TESTS_DEBUG_VALGRIND = [
99
('calib3d', 'Calib3d_InitUndistortRectifyMap.accuracy', 2017.22),
1010
('dnn', 'Reproducibility*', 1000), # large DNN models
11-
('features2d', 'Features2d_Feature2d.no_crash', 1235.68),
11+
('features2d', 'Features2d/DescriptorImage.no_crash/3', 1000),
12+
('features2d', 'Features2d/DescriptorImage.no_crash/4', 1000),
13+
('features2d', 'Features2d/DescriptorImage.no_crash/5', 1000),
14+
('features2d', 'Features2d/DescriptorImage.no_crash/6', 1000),
15+
('features2d', 'Features2d/DescriptorImage.no_crash/7', 1000),
1216
('imgcodecs', 'Imgcodecs_Png.write_big', 1000), # memory limit
1317
('imgcodecs', 'Imgcodecs_Tiff.decode_tile16384x16384', 1000), # memory limit
1418
('ml', 'ML_RTrees.regression', 1423.47),

0 commit comments

Comments
 (0)