1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
20 // * Redistribution's of source code must retain the above copyright notice,
21 // this list of conditions and the following disclaimer.
23 // * Redistribution's in binary form must reproduce the above copyright notice,
24 // this list of conditions and the following disclaimer in the documentation
25 // and/or other materials provided with the distribution.
27 // * The name of the copyright holders may not be used to endorse or promote products
28 // derived from this software without specific prior written permission.
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
43 #include "perf_precomp.hpp"
46 using namespace testing;
49 //////////////////////////////////////////////////////////////////////
52 DEF_PARAM_TEST(Image_Threshold_NonMaxSuppression, string, int, bool);
54 PERF_TEST_P(Image_Threshold_NonMaxSuppression, FAST,
55 Combine(Values<string>("gpu/perf/aloe.png"),
59 const cv::Mat img = readImage(GET_PARAM(0), cv::IMREAD_GRAYSCALE);
60 ASSERT_FALSE(img.empty());
62 const int threshold = GET_PARAM(1);
63 const bool nonMaxSuppersion = GET_PARAM(2);
67 cv::cuda::FAST_CUDA d_fast(threshold, nonMaxSuppersion, 0.5);
69 const cv::cuda::GpuMat d_img(img);
70 cv::cuda::GpuMat d_keypoints;
72 TEST_CYCLE() d_fast(d_img, cv::cuda::GpuMat(), d_keypoints);
74 std::vector<cv::KeyPoint> gpu_keypoints;
75 d_fast.downloadKeypoints(d_keypoints, gpu_keypoints);
77 sortKeyPoints(gpu_keypoints);
79 SANITY_CHECK_KEYPOINTS(gpu_keypoints);
83 std::vector<cv::KeyPoint> cpu_keypoints;
85 TEST_CYCLE() cv::FAST(img, cpu_keypoints, threshold, nonMaxSuppersion);
87 SANITY_CHECK_KEYPOINTS(cpu_keypoints);
91 //////////////////////////////////////////////////////////////////////
94 DEF_PARAM_TEST(Image_NFeatures, string, int);
96 PERF_TEST_P(Image_NFeatures, ORB,
97 Combine(Values<string>("gpu/perf/aloe.png"),
102 const cv::Mat img = readImage(GET_PARAM(0), cv::IMREAD_GRAYSCALE);
103 ASSERT_FALSE(img.empty());
105 const int nFeatures = GET_PARAM(1);
109 cv::cuda::ORB_CUDA d_orb(nFeatures);
111 const cv::cuda::GpuMat d_img(img);
112 cv::cuda::GpuMat d_keypoints, d_descriptors;
114 TEST_CYCLE() d_orb(d_img, cv::cuda::GpuMat(), d_keypoints, d_descriptors);
116 std::vector<cv::KeyPoint> gpu_keypoints;
117 d_orb.downloadKeyPoints(d_keypoints, gpu_keypoints);
119 cv::Mat gpu_descriptors(d_descriptors);
121 gpu_keypoints.resize(10);
122 gpu_descriptors = gpu_descriptors.rowRange(0, 10);
124 sortKeyPoints(gpu_keypoints, gpu_descriptors);
126 SANITY_CHECK_KEYPOINTS(gpu_keypoints, 1e-4);
127 SANITY_CHECK(gpu_descriptors);
131 cv::Ptr<cv::ORB> orb;
133 std::vector<cv::KeyPoint> cpu_keypoints;
134 cv::Mat cpu_descriptors;
136 TEST_CYCLE() orb->detectAndCompute(img, cv::noArray(), cpu_keypoints, cpu_descriptors);
138 SANITY_CHECK_KEYPOINTS(cpu_keypoints);
139 SANITY_CHECK(cpu_descriptors);
143 //////////////////////////////////////////////////////////////////////
146 DEF_PARAM_TEST(DescSize_Norm, int, NormType);
148 PERF_TEST_P(DescSize_Norm, BFMatch,
149 Combine(Values(64, 128, 256),
150 Values(NormType(cv::NORM_L1), NormType(cv::NORM_L2), NormType(cv::NORM_HAMMING))))
154 const int desc_size = GET_PARAM(0);
155 const int normType = GET_PARAM(1);
157 const int type = normType == cv::NORM_HAMMING ? CV_8U : CV_32F;
159 cv::Mat query(3000, desc_size, type);
160 declare.in(query, WARMUP_RNG);
162 cv::Mat train(3000, desc_size, type);
163 declare.in(train, WARMUP_RNG);
167 cv::cuda::BFMatcher_CUDA d_matcher(normType);
169 const cv::cuda::GpuMat d_query(query);
170 const cv::cuda::GpuMat d_train(train);
171 cv::cuda::GpuMat d_trainIdx, d_distance;
173 TEST_CYCLE() d_matcher.matchSingle(d_query, d_train, d_trainIdx, d_distance);
175 std::vector<cv::DMatch> gpu_matches;
176 d_matcher.matchDownload(d_trainIdx, d_distance, gpu_matches);
178 SANITY_CHECK_MATCHES(gpu_matches);
182 cv::BFMatcher matcher(normType);
184 std::vector<cv::DMatch> cpu_matches;
186 TEST_CYCLE() matcher.match(query, train, cpu_matches);
188 SANITY_CHECK_MATCHES(cpu_matches);
192 //////////////////////////////////////////////////////////////////////
195 static void toOneRowMatches(const std::vector< std::vector<cv::DMatch> >& src, std::vector<cv::DMatch>& dst)
198 for (size_t i = 0; i < src.size(); ++i)
199 for (size_t j = 0; j < src[i].size(); ++j)
200 dst.push_back(src[i][j]);
203 DEF_PARAM_TEST(DescSize_K_Norm, int, int, NormType);
205 PERF_TEST_P(DescSize_K_Norm, BFKnnMatch,
206 Combine(Values(64, 128, 256),
208 Values(NormType(cv::NORM_L1), NormType(cv::NORM_L2))))
212 const int desc_size = GET_PARAM(0);
213 const int k = GET_PARAM(1);
214 const int normType = GET_PARAM(2);
216 const int type = normType == cv::NORM_HAMMING ? CV_8U : CV_32F;
218 cv::Mat query(3000, desc_size, type);
219 declare.in(query, WARMUP_RNG);
221 cv::Mat train(3000, desc_size, type);
222 declare.in(train, WARMUP_RNG);
226 cv::cuda::BFMatcher_CUDA d_matcher(normType);
228 const cv::cuda::GpuMat d_query(query);
229 const cv::cuda::GpuMat d_train(train);
230 cv::cuda::GpuMat d_trainIdx, d_distance, d_allDist;
232 TEST_CYCLE() d_matcher.knnMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_allDist, k);
234 std::vector< std::vector<cv::DMatch> > matchesTbl;
235 d_matcher.knnMatchDownload(d_trainIdx, d_distance, matchesTbl);
237 std::vector<cv::DMatch> gpu_matches;
238 toOneRowMatches(matchesTbl, gpu_matches);
240 SANITY_CHECK_MATCHES(gpu_matches);
244 cv::BFMatcher matcher(normType);
246 std::vector< std::vector<cv::DMatch> > matchesTbl;
248 TEST_CYCLE() matcher.knnMatch(query, train, matchesTbl, k);
250 std::vector<cv::DMatch> cpu_matches;
251 toOneRowMatches(matchesTbl, cpu_matches);
253 SANITY_CHECK_MATCHES(cpu_matches);
257 //////////////////////////////////////////////////////////////////////
260 PERF_TEST_P(DescSize_Norm, BFRadiusMatch,
261 Combine(Values(64, 128, 256),
262 Values(NormType(cv::NORM_L1), NormType(cv::NORM_L2))))
266 const int desc_size = GET_PARAM(0);
267 const int normType = GET_PARAM(1);
269 const int type = normType == cv::NORM_HAMMING ? CV_8U : CV_32F;
270 const float maxDistance = 10000;
272 cv::Mat query(3000, desc_size, type);
273 declare.in(query, WARMUP_RNG);
275 cv::Mat train(3000, desc_size, type);
276 declare.in(train, WARMUP_RNG);
280 cv::cuda::BFMatcher_CUDA d_matcher(normType);
282 const cv::cuda::GpuMat d_query(query);
283 const cv::cuda::GpuMat d_train(train);
284 cv::cuda::GpuMat d_trainIdx, d_nMatches, d_distance;
286 TEST_CYCLE() d_matcher.radiusMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_nMatches, maxDistance);
288 std::vector< std::vector<cv::DMatch> > matchesTbl;
289 d_matcher.radiusMatchDownload(d_trainIdx, d_distance, d_nMatches, matchesTbl);
291 std::vector<cv::DMatch> gpu_matches;
292 toOneRowMatches(matchesTbl, gpu_matches);
294 SANITY_CHECK_MATCHES(gpu_matches);
298 cv::BFMatcher matcher(normType);
300 std::vector< std::vector<cv::DMatch> > matchesTbl;
302 TEST_CYCLE() matcher.radiusMatch(query, train, matchesTbl, maxDistance);
304 std::vector<cv::DMatch> cpu_matches;
305 toOneRowMatches(matchesTbl, cpu_matches);
307 SANITY_CHECK_MATCHES(cpu_matches);