Path: blob/master/modules/features2d/test/test_descriptors_regression.cpp
16354 views
// This file is part of OpenCV project.1// It is subject to the license terms in the LICENSE file found in the top-level directory2// of this distribution and at http://opencv.org/license.html34#include "test_precomp.hpp"56namespace opencv_test { namespace {7const string FEATURES2D_DIR = "features2d";8const string IMAGE_FILENAME = "tsukuba.png";9const string DESCRIPTOR_DIR = FEATURES2D_DIR + "/descriptor_extractors";10}} // namespace1112#include "test_descriptors_regression.impl.hpp"1314namespace opencv_test { namespace {1516/****************************************************************************************\17* Tests registrations *18\****************************************************************************************/1920TEST( Features2d_DescriptorExtractor_BRISK, regression )21{22CV_DescriptorExtractorTest<Hamming> test( "descriptor-brisk",23(CV_DescriptorExtractorTest<Hamming>::DistanceType)2.f,24BRISK::create() );25test.safe_run();26}2728TEST( Features2d_DescriptorExtractor_ORB, regression )29{30// TODO adjust the parameters below31CV_DescriptorExtractorTest<Hamming> test( "descriptor-orb",32#if CV_NEON33(CV_DescriptorExtractorTest<Hamming>::DistanceType)25.f,34#else35(CV_DescriptorExtractorTest<Hamming>::DistanceType)12.f,36#endif37ORB::create() );38test.safe_run();39}4041TEST( Features2d_DescriptorExtractor_KAZE, regression )42{43CV_DescriptorExtractorTest< L2<float> > test( "descriptor-kaze", 0.03f,44KAZE::create(),45L2<float>(), KAZE::create() );46test.safe_run();47}4849TEST( Features2d_DescriptorExtractor_AKAZE, regression )50{51CV_DescriptorExtractorTest<Hamming> test( "descriptor-akaze",52(CV_DescriptorExtractorTest<Hamming>::DistanceType)(486*0.05f),53AKAZE::create(),54Hamming(), AKAZE::create());55test.safe_run();56}5758TEST( Features2d_DescriptorExtractor_AKAZE_DESCRIPTOR_KAZE, regression )59{60CV_DescriptorExtractorTest< L2<float> > test( "descriptor-akaze-with-kaze-desc", 0.03f,61AKAZE::create(AKAZE::DESCRIPTOR_KAZE),62L2<float>(), AKAZE::create(AKAZE::DESCRIPTOR_KAZE));63test.safe_run();64}6566TEST( Features2d_DescriptorExtractor, batch )67{68string path = string(cvtest::TS::ptr()->get_data_path() + "detectors_descriptors_evaluation/images_datasets/graf");69vector<Mat> imgs, descriptors;70vector<vector<KeyPoint> > keypoints;71int i, n = 6;72Ptr<ORB> orb = ORB::create();7374for( i = 0; i < n; i++ )75{76string imgname = format("%s/img%d.png", path.c_str(), i+1);77Mat img = imread(imgname, 0);78imgs.push_back(img);79}8081orb->detect(imgs, keypoints);82orb->compute(imgs, keypoints, descriptors);8384ASSERT_EQ((int)keypoints.size(), n);85ASSERT_EQ((int)descriptors.size(), n);8687for( i = 0; i < n; i++ )88{89EXPECT_GT((int)keypoints[i].size(), 100);90EXPECT_GT(descriptors[i].rows, 100);91}92}9394class DescriptorImage : public TestWithParam<std::string>95{96protected:97virtual void SetUp() {98pattern = GetParam();99}100101std::string pattern;102};103104TEST_P(DescriptorImage, no_crash)105{106vector<String> fnames;107glob(cvtest::TS::ptr()->get_data_path() + pattern, fnames, false);108sort(fnames.begin(), fnames.end());109110Ptr<AKAZE> akaze_mldb = AKAZE::create(AKAZE::DESCRIPTOR_MLDB);111Ptr<AKAZE> akaze_mldb_upright = AKAZE::create(AKAZE::DESCRIPTOR_MLDB_UPRIGHT);112Ptr<AKAZE> akaze_mldb_256 = AKAZE::create(AKAZE::DESCRIPTOR_MLDB, 256);113Ptr<AKAZE> akaze_mldb_upright_256 = AKAZE::create(AKAZE::DESCRIPTOR_MLDB_UPRIGHT, 256);114Ptr<AKAZE> akaze_kaze = AKAZE::create(AKAZE::DESCRIPTOR_KAZE);115Ptr<AKAZE> akaze_kaze_upright = AKAZE::create(AKAZE::DESCRIPTOR_KAZE_UPRIGHT);116Ptr<ORB> orb = ORB::create();117Ptr<KAZE> kaze = KAZE::create();118Ptr<BRISK> brisk = BRISK::create();119size_t n = fnames.size();120vector<KeyPoint> keypoints;121Mat descriptors;122orb->setMaxFeatures(5000);123124for(size_t i = 0; i < n; i++ )125{126printf("%d. image: %s:\n", (int)i, fnames[i].c_str());127if( strstr(fnames[i].c_str(), "MP.png") != 0 )128{129printf("\tskip\n");130continue;131}132bool checkCount = strstr(fnames[i].c_str(), "templ.png") == 0;133134Mat img = imread(fnames[i], -1);135136printf("\t%dx%d\n", img.cols, img.rows);137138#define TEST_DETECTOR(name, descriptor) \139keypoints.clear(); descriptors.release(); \140printf("\t" name "\n"); fflush(stdout); \141descriptor->detectAndCompute(img, noArray(), keypoints, descriptors); \142printf("\t\t\t(%d keypoints, descriptor size = %d)\n", (int)keypoints.size(), descriptors.cols); fflush(stdout); \143if (checkCount) \144{ \145EXPECT_GT((int)keypoints.size(), 0); \146} \147ASSERT_EQ(descriptors.rows, (int)keypoints.size());148149TEST_DETECTOR("AKAZE:MLDB", akaze_mldb);150TEST_DETECTOR("AKAZE:MLDB_UPRIGHT", akaze_mldb_upright);151TEST_DETECTOR("AKAZE:MLDB_256", akaze_mldb_256);152TEST_DETECTOR("AKAZE:MLDB_UPRIGHT_256", akaze_mldb_upright_256);153TEST_DETECTOR("AKAZE:KAZE", akaze_kaze);154TEST_DETECTOR("AKAZE:KAZE_UPRIGHT", akaze_kaze_upright);155TEST_DETECTOR("KAZE", kaze);156TEST_DETECTOR("ORB", orb);157TEST_DETECTOR("BRISK", brisk);158}159}160161INSTANTIATE_TEST_CASE_P(Features2d, DescriptorImage,162testing::Values(163"shared/lena.png",164"shared/box*.png",165"shared/fruits*.png",166"shared/airplane.png",167"shared/graffiti.png",168"shared/1_itseez-0001*.png",169"shared/pic*.png",170"shared/templ.png"171)172);173174}} // namespace175176177