Path: blob/master/modules/features2d/test/test_orb.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"4243namespace opencv_test { namespace {4445TEST(Features2D_ORB, _1996)46{47Ptr<FeatureDetector> fd = ORB::create(10000, 1.2f, 8, 31, 0, 2, ORB::HARRIS_SCORE, 31, 20);48Ptr<DescriptorExtractor> de = fd;4950Mat image = imread(string(cvtest::TS::ptr()->get_data_path()) + "shared/lena.png");51ASSERT_FALSE(image.empty());5253Mat roi(image.size(), CV_8UC1, Scalar(0));5455Point poly[] = {Point(100, 20), Point(300, 50), Point(400, 200), Point(10, 500)};56fillConvexPoly(roi, poly, int(sizeof(poly) / sizeof(poly[0])), Scalar(255));5758std::vector<KeyPoint> keypoints;59fd->detect(image, keypoints, roi);60Mat descriptors;61de->compute(image, keypoints, descriptors);6263//image.setTo(Scalar(255,255,255), roi);6465int roiViolations = 0;66for(std::vector<KeyPoint>::const_iterator kp = keypoints.begin(); kp != keypoints.end(); ++kp)67{68int x = cvRound(kp->pt.x);69int y = cvRound(kp->pt.y);7071ASSERT_LE(0, x);72ASSERT_LE(0, y);73ASSERT_GT(image.cols, x);74ASSERT_GT(image.rows, y);7576// if (!roi.at<uchar>(y,x))77// {78// roiViolations++;79// circle(image, kp->pt, 3, Scalar(0,0,255));80// }81}8283// if(roiViolations)84// {85// imshow("img", image);86// waitKey();87// }8889ASSERT_EQ(0, roiViolations);90}9192TEST(Features2D_ORB, crash)93{94cv::Mat image = cv::Mat::zeros(cv::Size(1920, 1080), CV_8UC3);9596int nfeatures = 8000;97float orbScaleFactor = 1.2f;98int nlevels = 18;99int edgeThreshold = 4;100int firstLevel = 0;101int WTA_K = 2;102ORB::ScoreType scoreType = cv::ORB::HARRIS_SCORE;103int patchSize = 47;104int fastThreshold = 20;105106Ptr<ORB> orb = cv::ORB::create(nfeatures, orbScaleFactor, nlevels, edgeThreshold, firstLevel, WTA_K, scoreType, patchSize, fastThreshold);107108std::vector<cv::KeyPoint> keypoints;109cv::Mat descriptors;110111cv::KeyPoint kp;112kp.pt.x = 443;113kp.pt.y = 5;114kp.size = 47;115kp.angle = 53.4580612f;116kp.response = 0.0000470733867f;117kp.octave = 0;118kp.class_id = -1;119120keypoints.push_back(kp);121122ASSERT_NO_THROW(orb->compute(image, keypoints, descriptors));123}124125}} // namespace126127128