1 /*M///////////////////////////////////////////////////////////////////////////////////////
\r
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
\r
5 // By downloading, copying, installing or using the software you agree to this license.
\r
6 // If you do not agree to this license, do not download, install,
\r
7 // copy or use the software.
\r
10 // License Agreement
\r
11 // For Open Source Computer Vision Library
\r
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
\r
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
\r
15 // Third party copyrights are property of their respective owners.
\r
17 // Redistribution and use in source and binary forms, with or without modification,
\r
18 // are permitted provided that the following conditions are met:
\r
20 // * Redistribution's of source code must retain the above copyright notice,
\r
21 // this list of conditions and the following disclaimer.
\r
23 // * Redistribution's in binary form must reproduce the above copyright notice,
\r
24 // this list of conditions and the following disclaimer in the documentation
\r
25 // and/or other materials provided with the distribution.
\r
27 // * The name of the copyright holders may not be used to endorse or promote products
\r
28 // derived from this software without specific prior written permission.
\r
30 // This software is provided by the copyright holders and contributors "as is" and
\r
31 // any express or implied warranties, including, but not limited to, the implied
\r
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
\r
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
\r
34 // indirect, incidental, special, exemplary, or consequential damages
\r
35 // (including, but not limited to, procurement of substitute goods or services;
\r
36 // loss of use, data, or profits; or business interruption) however caused
\r
37 // and on any theory of liability, whether in contract, strict liability,
\r
38 // or tort (including negligence or otherwise) arising in any way out of
\r
39 // the use of this software, even if advised of the possibility of such damage.
\r
51 using namespace std;
\r
53 class CV_DetectorsTest : public CvTest
\r
57 ~CV_DetectorsTest();
\r
62 CV_DetectorsTest::CV_DetectorsTest(): CvTest( "feature-detectors", "?" )
\r
64 support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
\r
66 CV_DetectorsTest::~CV_DetectorsTest() {}
\r
71 OutOfMask(const Mat& mask) : msk(mask) {};
\r
72 OutOfMask& operator=(const OutOfMask&);
\r
73 bool operator()(const KeyPoint& kp) const { return msk.at<uchar>(kp.pt) == 0; }
\r
79 WrapPoint(const Mat& rmat) : R(rmat.ptr<double>()) { };
\r
81 KeyPoint operator()(const KeyPoint& kp) const
\r
84 res.pt.x = static_cast<float>(kp.pt.x * R[0] + kp.pt.y * R[1] + R[2]);
\r
85 res.pt.y = static_cast<float>(kp.pt.x * R[3] + kp.pt.y * R[4] + R[5]);
\r
90 void CV_DetectorsTest::run( int /*start_from*/ )
\r
92 Mat oimg = imread(string(ts->get_data_path()) + "shared/baboon.jpg", 0);
\r
93 //Mat oimg = imread(string(ts->get_data_path()) + "shared/fruits.jpg", 0);
\r
97 ts->set_failed_test_info( CvTS::FAIL_INVALID_TEST_DATA );
\r
101 Point center(oimg.cols/2, oimg.rows/2);
\r
103 Mat aff = getRotationMatrix2D(center, 45, 1);
\r
106 warpAffine( oimg, rimg, aff, oimg.size());
\r
108 Mat mask(oimg.size(), CV_8U, Scalar(0));
\r
109 circle(mask, center, std::min(center.x, center.y) - 10, Scalar(255), CV_FILLED);
\r
111 mask.convertTo(inv_mask, CV_8U, -1, 255);
\r
113 Mat oimg_color, rimg_color;
\r
114 cvtColor(oimg, oimg_color, CV_GRAY2BGR); oimg_color.setTo(Scalar(0), inv_mask);
\r
115 cvtColor(rimg, rimg_color, CV_GRAY2BGR); rimg_color.setTo(Scalar(0), inv_mask);
\r
117 SURF surf(1536, 2);
\r
118 StarDetector star(45, 30, 10, 8, 5);
\r
120 vector<KeyPoint> opoints_surf, rpoints_surf, opoints_star, rpoints_star;
\r
121 surf(oimg, mask, opoints_surf);
\r
122 surf(rimg, mask, rpoints_surf);
\r
124 star(oimg, opoints_star);
\r
125 star(rimg, rpoints_star);
\r
127 opoints_star.erase(
\r
128 remove_if(opoints_star.begin(), opoints_star.end(), OutOfMask(mask)),
\r
129 opoints_star.end());
\r
131 rpoints_star.erase(
\r
132 remove_if(rpoints_star.begin(), rpoints_star.end(), OutOfMask(mask)),
\r
133 rpoints_star.end());
\r
135 vector<KeyPoint> exp_rpoints_surf(opoints_surf.size()), exp_rpoints_star(opoints_star.size());
\r
136 transform(opoints_surf.begin(), opoints_surf.end(), exp_rpoints_surf.begin(), WrapPoint(aff));
\r
137 transform(opoints_star.begin(), opoints_star.end(), exp_rpoints_star.begin(), WrapPoint(aff));
\r
139 for(size_t i = 0; i < opoints_surf.size(); ++i)
\r
141 circle(oimg_color, opoints_surf[i].pt, (int)opoints_surf[i].size/2, CV_RGB(0, 255, 0));
\r
142 circle(rimg_color, exp_rpoints_surf[i].pt, (int)exp_rpoints_surf[i].size/2, CV_RGB(255, 0, 0));
\r
145 for(size_t i = 0; i < rpoints_surf.size(); ++i)
\r
146 circle(rimg_color, rpoints_surf[i].pt, (int)rpoints_surf[i].size/2, CV_RGB(0, 255, 0));
\r
148 for(size_t i = 0; i < opoints_star.size(); ++i)
\r
150 circle(oimg_color, opoints_star[i].pt, (int)opoints_star[i].size/2, CV_RGB(0, 0, 255));
\r
151 circle(rimg_color, exp_rpoints_surf[i].pt, (int)exp_rpoints_surf[i].size/2, CV_RGB(255, 0, 0));
\r
154 for(size_t i = 0; i < rpoints_star.size(); ++i)
\r
155 circle(rimg_color, rpoints_star[i].pt, (int)rpoints_star[i].size/2, CV_RGB(0, 0, 255));
\r
157 /* namedWindow("R"); imshow("R", rimg_color);
\r
158 namedWindow("O"); imshow("O", oimg_color);
\r
161 ts->set_failed_test_info( CvTS::FAIL_GENERIC );
\r
165 CV_DetectorsTest Detectors_test;
\r