Path: blob/master/modules/features2d/test/test_keypoints.cpp
16354 views
/*M///////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// Intel License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2000, Intel Corporation, all rights reserved.13// Third party copyrights are property of their respective owners.14//15// Redistribution and use in source and binary forms, with or without modification,16// are permitted provided that the following conditions are met:17//18// * Redistribution's of source code must retain the above copyright notice,19// this list of conditions and the following disclaimer.20//21// * Redistribution's in binary form must reproduce the above copyright notice,22// this list of conditions and the following disclaimer in the documentation23// and/or other materials provided with the distribution.24//25// * The name of Intel Corporation may not be used to endorse or promote products26// derived from this software without specific prior written permission.27//28// This software is provided by the copyright holders and contributors "as is" and29// any express or implied warranties, including, but not limited to, the implied30// warranties of merchantability and fitness for a particular purpose are disclaimed.31// In no event shall the Intel Corporation or contributors be liable for any direct,32// indirect, incidental, special, exemplary, or consequential damages33// (including, but not limited to, procurement of substitute goods or services;34// loss of use, data, or profits; or business interruption) however caused35// and on any theory of liability, whether in contract, strict liability,36// or tort (including negligence or otherwise) arising in any way out of37// the use of this software, even if advised of the possibility of such damage.38//39//M*/4041#include "test_precomp.hpp"42#include "opencv2/core/core_c.h"4344namespace opencv_test { namespace {4546const string FEATURES2D_DIR = "features2d";47const string IMAGE_FILENAME = "tsukuba.png";4849/****************************************************************************************\50* Test for KeyPoint *51\****************************************************************************************/5253class CV_FeatureDetectorKeypointsTest : public cvtest::BaseTest54{55public:56CV_FeatureDetectorKeypointsTest(const Ptr<FeatureDetector>& _detector) :57detector(_detector) {}5859protected:60virtual void run(int)61{62CV_Assert(detector);63string imgFilename = string(ts->get_data_path()) + FEATURES2D_DIR + "/" + IMAGE_FILENAME;6465// Read the test image.66Mat image = imread(imgFilename);67if(image.empty())68{69ts->printf(cvtest::TS::LOG, "Image %s can not be read.\n", imgFilename.c_str());70ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);71return;72}7374vector<KeyPoint> keypoints;75detector->detect(image, keypoints);7677if(keypoints.empty())78{79ts->printf(cvtest::TS::LOG, "Detector can't find keypoints in image.\n");80ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT);81return;82}8384Rect r(0, 0, image.cols, image.rows);85for(size_t i = 0; i < keypoints.size(); i++)86{87const KeyPoint& kp = keypoints[i];8889if(!r.contains(kp.pt))90{91ts->printf(cvtest::TS::LOG, "KeyPoint::pt is out of image (x=%f, y=%f).\n", kp.pt.x, kp.pt.y);92ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT);93return;94}9596if(kp.size <= 0.f)97{98ts->printf(cvtest::TS::LOG, "KeyPoint::size is not positive (%f).\n", kp.size);99ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT);100return;101}102103if((kp.angle < 0.f && kp.angle != -1.f) || kp.angle >= 360.f)104{105ts->printf(cvtest::TS::LOG, "KeyPoint::angle is out of range [0, 360). It's %f.\n", kp.angle);106ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT);107return;108}109}110ts->set_failed_test_info(cvtest::TS::OK);111}112113Ptr<FeatureDetector> detector;114};115116117// Registration of tests118119TEST(Features2d_Detector_Keypoints_BRISK, validation)120{121CV_FeatureDetectorKeypointsTest test(BRISK::create());122test.safe_run();123}124125TEST(Features2d_Detector_Keypoints_FAST, validation)126{127CV_FeatureDetectorKeypointsTest test(FastFeatureDetector::create());128test.safe_run();129}130131TEST(Features2d_Detector_Keypoints_AGAST, validation)132{133CV_FeatureDetectorKeypointsTest test(AgastFeatureDetector::create());134test.safe_run();135}136137TEST(Features2d_Detector_Keypoints_HARRIS, validation)138{139140CV_FeatureDetectorKeypointsTest test(GFTTDetector::create(1000, 0.01, 1, 3, 3, true, 0.04));141test.safe_run();142}143144TEST(Features2d_Detector_Keypoints_GFTT, validation)145{146Ptr<GFTTDetector> gftt = GFTTDetector::create();147gftt->setHarrisDetector(true);148CV_FeatureDetectorKeypointsTest test(gftt);149test.safe_run();150}151152TEST(Features2d_Detector_Keypoints_MSER, validation)153{154CV_FeatureDetectorKeypointsTest test(MSER::create());155test.safe_run();156}157158TEST(Features2d_Detector_Keypoints_ORB, validation)159{160CV_FeatureDetectorKeypointsTest test(ORB::create());161test.safe_run();162}163164TEST(Features2d_Detector_Keypoints_KAZE, validation)165{166CV_FeatureDetectorKeypointsTest test(KAZE::create());167test.safe_run();168}169170TEST(Features2d_Detector_Keypoints_AKAZE, validation)171{172CV_FeatureDetectorKeypointsTest test_kaze(AKAZE::create(AKAZE::DESCRIPTOR_KAZE));173test_kaze.safe_run();174175CV_FeatureDetectorKeypointsTest test_mldb(AKAZE::create(AKAZE::DESCRIPTOR_MLDB));176test_mldb.safe_run();177}178179}} // namespace180181182