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 enum { HALF_SIZE=0, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH };
53 CV_ENUM(RemapMode, HALF_SIZE, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH);
55 void generateMap(cv::Mat& map_x, cv::Mat& map_y, int remapMode)
57 for (int j = 0; j < map_x.rows; ++j)
59 for (int i = 0; i < map_x.cols; ++i)
64 if (i > map_x.cols*0.25 && i < map_x.cols*0.75 && j > map_x.rows*0.25 && j < map_x.rows*0.75)
66 map_x.at<float>(j,i) = 2.f * (i - map_x.cols * 0.25f) + 0.5f;
67 map_y.at<float>(j,i) = 2.f * (j - map_x.rows * 0.25f) + 0.5f;
71 map_x.at<float>(j,i) = 0.f;
72 map_y.at<float>(j,i) = 0.f;
76 map_x.at<float>(j,i) = static_cast<float>(i);
77 map_y.at<float>(j,i) = static_cast<float>(map_x.rows - j);
80 map_x.at<float>(j,i) = static_cast<float>(map_x.cols - i);
81 map_y.at<float>(j,i) = static_cast<float>(j);
84 map_x.at<float>(j,i) = static_cast<float>(map_x.cols - i);
85 map_y.at<float>(j,i) = static_cast<float>(map_x.rows - j);
92 DEF_PARAM_TEST(Sz_Depth_Cn_Inter_Border_Mode, cv::Size, MatDepth, MatCn, Interpolation, BorderMode, RemapMode);
94 PERF_TEST_P(Sz_Depth_Cn_Inter_Border_Mode, ImgProc_Remap,
95 Combine(GPU_TYPICAL_MAT_SIZES,
96 Values(CV_8U, CV_16U, CV_32F),
98 Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
104 const cv::Size size = GET_PARAM(0);
105 const int depth = GET_PARAM(1);
106 const int channels = GET_PARAM(2);
107 const int interpolation = GET_PARAM(3);
108 const int borderMode = GET_PARAM(4);
109 const int remapMode = GET_PARAM(5);
111 const int type = CV_MAKE_TYPE(depth, channels);
113 cv::Mat src(size, type);
114 declare.in(src, WARMUP_RNG);
116 cv::Mat xmap(size, CV_32FC1);
117 cv::Mat ymap(size, CV_32FC1);
118 generateMap(xmap, ymap, remapMode);
122 const cv::gpu::GpuMat d_src(src);
123 const cv::gpu::GpuMat d_xmap(xmap);
124 const cv::gpu::GpuMat d_ymap(ymap);
127 TEST_CYCLE() cv::gpu::remap(d_src, dst, d_xmap, d_ymap, interpolation, borderMode);
129 GPU_SANITY_CHECK(dst);
135 TEST_CYCLE() cv::remap(src, dst, xmap, ymap, interpolation, borderMode);
137 CPU_SANITY_CHECK(dst);
141 //////////////////////////////////////////////////////////////////////
144 DEF_PARAM_TEST(Sz_Depth_Cn_Inter_Scale, cv::Size, MatDepth, MatCn, Interpolation, double);
146 PERF_TEST_P(Sz_Depth_Cn_Inter_Scale, ImgProc_Resize,
147 Combine(GPU_TYPICAL_MAT_SIZES,
148 Values(CV_8U, CV_16U, CV_32F),
150 Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
151 Values(0.5, 0.3, 2.0)))
155 const cv::Size size = GET_PARAM(0);
156 const int depth = GET_PARAM(1);
157 const int channels = GET_PARAM(2);
158 const int interpolation = GET_PARAM(3);
159 const double f = GET_PARAM(4);
161 const int type = CV_MAKE_TYPE(depth, channels);
163 cv::Mat src(size, type);
164 declare.in(src, WARMUP_RNG);
168 const cv::gpu::GpuMat d_src(src);
171 TEST_CYCLE() cv::gpu::resize(d_src, dst, cv::Size(), f, f, interpolation);
173 GPU_SANITY_CHECK(dst, 1e-3, ERROR_RELATIVE);
179 TEST_CYCLE() cv::resize(src, dst, cv::Size(), f, f, interpolation);
181 CPU_SANITY_CHECK(dst);
185 //////////////////////////////////////////////////////////////////////
188 DEF_PARAM_TEST(Sz_Depth_Cn_Scale, cv::Size, MatDepth, MatCn, double);
190 PERF_TEST_P(Sz_Depth_Cn_Scale, ImgProc_ResizeArea,
191 Combine(GPU_TYPICAL_MAT_SIZES,
192 Values(CV_8U, CV_16U, CV_32F),
194 Values(0.2, 0.1, 0.05)))
198 const cv::Size size = GET_PARAM(0);
199 const int depth = GET_PARAM(1);
200 const int channels = GET_PARAM(2);
201 const int interpolation = cv::INTER_AREA;
202 const double f = GET_PARAM(3);
204 const int type = CV_MAKE_TYPE(depth, channels);
206 cv::Mat src(size, type);
207 declare.in(src, WARMUP_RNG);
211 const cv::gpu::GpuMat d_src(src);
214 TEST_CYCLE() cv::gpu::resize(d_src, dst, cv::Size(), f, f, interpolation);
216 GPU_SANITY_CHECK(dst);
222 TEST_CYCLE() cv::resize(src, dst, cv::Size(), f, f, interpolation);
224 CPU_SANITY_CHECK(dst);
228 //////////////////////////////////////////////////////////////////////
231 DEF_PARAM_TEST(Sz_Depth_Cn_Inter_Border, cv::Size, MatDepth, MatCn, Interpolation, BorderMode);
233 PERF_TEST_P(Sz_Depth_Cn_Inter_Border, ImgProc_WarpAffine,
234 Combine(GPU_TYPICAL_MAT_SIZES,
235 Values(CV_8U, CV_16U, CV_32F),
237 Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
242 const cv::Size size = GET_PARAM(0);
243 const int depth = GET_PARAM(1);
244 const int channels = GET_PARAM(2);
245 const int interpolation = GET_PARAM(3);
246 const int borderMode = GET_PARAM(4);
248 const int type = CV_MAKE_TYPE(depth, channels);
250 cv::Mat src(size, type);
251 declare.in(src, WARMUP_RNG);
253 const double aplha = CV_PI / 4;
254 const double mat[2 * 3] =
256 std::cos(aplha), -std::sin(aplha), src.cols / 2,
257 std::sin(aplha), std::cos(aplha), 0
259 const cv::Mat M(2, 3, CV_64F, (void*) mat);
263 const cv::gpu::GpuMat d_src(src);
266 TEST_CYCLE() cv::gpu::warpAffine(d_src, dst, M, size, interpolation, borderMode);
268 GPU_SANITY_CHECK(dst, 1);
274 TEST_CYCLE() cv::warpAffine(src, dst, M, size, interpolation, borderMode);
276 CPU_SANITY_CHECK(dst);
280 //////////////////////////////////////////////////////////////////////
283 PERF_TEST_P(Sz_Depth_Cn_Inter_Border, ImgProc_WarpPerspective,
284 Combine(GPU_TYPICAL_MAT_SIZES,
285 Values(CV_8U, CV_16U, CV_32F),
287 Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
292 const cv::Size size = GET_PARAM(0);
293 const int depth = GET_PARAM(1);
294 const int channels = GET_PARAM(2);
295 const int interpolation = GET_PARAM(3);
296 const int borderMode = GET_PARAM(4);
298 const int type = CV_MAKE_TYPE(depth, channels);
300 cv::Mat src(size, type);
301 declare.in(src, WARMUP_RNG);
303 const double aplha = CV_PI / 4;
304 double mat[3][3] = { {std::cos(aplha), -std::sin(aplha), src.cols / 2},
305 {std::sin(aplha), std::cos(aplha), 0},
307 const cv::Mat M(3, 3, CV_64F, (void*) mat);
311 const cv::gpu::GpuMat d_src(src);
314 TEST_CYCLE() cv::gpu::warpPerspective(d_src, dst, M, size, interpolation, borderMode);
316 GPU_SANITY_CHECK(dst, 1);
322 TEST_CYCLE() cv::warpPerspective(src, dst, M, size, interpolation, borderMode);
324 CPU_SANITY_CHECK(dst);
328 //////////////////////////////////////////////////////////////////////
331 DEF_PARAM_TEST(Sz_Depth_Cn_Border, cv::Size, MatDepth, MatCn, BorderMode);
333 PERF_TEST_P(Sz_Depth_Cn_Border, ImgProc_CopyMakeBorder,
334 Combine(GPU_TYPICAL_MAT_SIZES,
335 Values(CV_8U, CV_16U, CV_32F),
339 const cv::Size size = GET_PARAM(0);
340 const int depth = GET_PARAM(1);
341 const int channels = GET_PARAM(2);
342 const int borderMode = GET_PARAM(3);
344 const int type = CV_MAKE_TYPE(depth, channels);
346 cv::Mat src(size, type);
347 declare.in(src, WARMUP_RNG);
351 const cv::gpu::GpuMat d_src(src);
354 TEST_CYCLE() cv::gpu::copyMakeBorder(d_src, dst, 5, 5, 5, 5, borderMode);
356 GPU_SANITY_CHECK(dst);
362 TEST_CYCLE() cv::copyMakeBorder(src, dst, 5, 5, 5, 5, borderMode);
364 CPU_SANITY_CHECK(dst);
368 //////////////////////////////////////////////////////////////////////
371 CV_ENUM(ThreshOp, THRESH_BINARY, THRESH_BINARY_INV, THRESH_TRUNC, THRESH_TOZERO, THRESH_TOZERO_INV)
373 DEF_PARAM_TEST(Sz_Depth_Op, cv::Size, MatDepth, ThreshOp);
375 PERF_TEST_P(Sz_Depth_Op, ImgProc_Threshold,
376 Combine(GPU_TYPICAL_MAT_SIZES,
377 Values(CV_8U, CV_16U, CV_32F, CV_64F),
380 const cv::Size size = GET_PARAM(0);
381 const int depth = GET_PARAM(1);
382 const int threshOp = GET_PARAM(2);
384 cv::Mat src(size, depth);
385 declare.in(src, WARMUP_RNG);
389 const cv::gpu::GpuMat d_src(src);
392 TEST_CYCLE() cv::gpu::threshold(d_src, dst, 100.0, 255.0, threshOp);
394 GPU_SANITY_CHECK(dst, 1e-10);
400 TEST_CYCLE() cv::threshold(src, dst, 100.0, 255.0, threshOp);
402 CPU_SANITY_CHECK(dst);
406 //////////////////////////////////////////////////////////////////////
409 PERF_TEST_P(Sz, ImgProc_Integral,
410 GPU_TYPICAL_MAT_SIZES)
412 const cv::Size size = GetParam();
414 cv::Mat src(size, CV_8UC1);
415 declare.in(src, WARMUP_RNG);
419 const cv::gpu::GpuMat d_src(src);
421 cv::gpu::GpuMat d_buf;
423 TEST_CYCLE() cv::gpu::integralBuffered(d_src, dst, d_buf);
425 GPU_SANITY_CHECK(dst);
431 TEST_CYCLE() cv::integral(src, dst);
433 CPU_SANITY_CHECK(dst);
437 //////////////////////////////////////////////////////////////////////
440 PERF_TEST_P(Sz, ImgProc_IntegralSqr,
441 GPU_TYPICAL_MAT_SIZES)
443 const cv::Size size = GetParam();
445 cv::Mat src(size, CV_8UC1);
446 declare.in(src, WARMUP_RNG);
450 const cv::gpu::GpuMat d_src(src);
453 TEST_CYCLE() cv::gpu::sqrIntegral(d_src, dst);
455 GPU_SANITY_CHECK(dst);
463 //////////////////////////////////////////////////////////////////////
466 PERF_TEST_P(Sz_Depth, ImgProc_HistEvenC1,
467 Combine(GPU_TYPICAL_MAT_SIZES,
468 Values(CV_8U, CV_16U, CV_16S)))
470 const cv::Size size = GET_PARAM(0);
471 const int depth = GET_PARAM(1);
473 cv::Mat src(size, depth);
474 declare.in(src, WARMUP_RNG);
478 const cv::gpu::GpuMat d_src(src);
480 cv::gpu::GpuMat d_buf;
482 TEST_CYCLE() cv::gpu::histEven(d_src, dst, d_buf, 30, 0, 180);
484 GPU_SANITY_CHECK(dst);
488 const int hbins = 30;
489 const float hranges[] = {0.0f, 180.0f};
490 const int histSize[] = {hbins};
491 const float* ranges[] = {hranges};
492 const int channels[] = {0};
496 TEST_CYCLE() cv::calcHist(&src, 1, channels, cv::Mat(), dst, 1, histSize, ranges);
498 CPU_SANITY_CHECK(dst);
502 //////////////////////////////////////////////////////////////////////
505 PERF_TEST_P(Sz_Depth, ImgProc_HistEvenC4,
506 Combine(GPU_TYPICAL_MAT_SIZES,
507 Values(CV_8U, CV_16U, CV_16S)))
509 const cv::Size size = GET_PARAM(0);
510 const int depth = GET_PARAM(1);
512 cv::Mat src(size, CV_MAKE_TYPE(depth, 4));
513 declare.in(src, WARMUP_RNG);
515 int histSize[] = {30, 30, 30, 30};
516 int lowerLevel[] = {0, 0, 0, 0};
517 int upperLevel[] = {180, 180, 180, 180};
521 const cv::gpu::GpuMat d_src(src);
522 cv::gpu::GpuMat d_hist[4];
523 cv::gpu::GpuMat d_buf;
525 TEST_CYCLE() cv::gpu::histEven(d_src, d_hist, d_buf, histSize, lowerLevel, upperLevel);
527 cv::Mat cpu_hist0, cpu_hist1, cpu_hist2, cpu_hist3;
528 d_hist[0].download(cpu_hist0);
529 d_hist[1].download(cpu_hist1);
530 d_hist[2].download(cpu_hist2);
531 d_hist[3].download(cpu_hist3);
532 SANITY_CHECK(cpu_hist0);
533 SANITY_CHECK(cpu_hist1);
534 SANITY_CHECK(cpu_hist2);
535 SANITY_CHECK(cpu_hist3);
543 //////////////////////////////////////////////////////////////////////
546 PERF_TEST_P(Sz, ImgProc_CalcHist,
547 GPU_TYPICAL_MAT_SIZES)
549 const cv::Size size = GetParam();
551 cv::Mat src(size, CV_8UC1);
552 declare.in(src, WARMUP_RNG);
556 const cv::gpu::GpuMat d_src(src);
559 TEST_CYCLE() cv::gpu::calcHist(d_src, dst);
561 GPU_SANITY_CHECK(dst);
569 //////////////////////////////////////////////////////////////////////
572 PERF_TEST_P(Sz, ImgProc_EqualizeHist,
573 GPU_TYPICAL_MAT_SIZES)
575 const cv::Size size = GetParam();
577 cv::Mat src(size, CV_8UC1);
578 declare.in(src, WARMUP_RNG);
582 const cv::gpu::GpuMat d_src(src);
584 cv::gpu::GpuMat d_hist;
585 cv::gpu::GpuMat d_buf;
587 TEST_CYCLE() cv::gpu::equalizeHist(d_src, dst, d_hist, d_buf);
589 GPU_SANITY_CHECK(dst);
595 TEST_CYCLE() cv::equalizeHist(src, dst);
597 CPU_SANITY_CHECK(dst);
601 DEF_PARAM_TEST(Sz_ClipLimit, cv::Size, double);
603 PERF_TEST_P(Sz_ClipLimit, ImgProc_CLAHE,
604 Combine(GPU_TYPICAL_MAT_SIZES,
607 const cv::Size size = GET_PARAM(0);
608 const double clipLimit = GET_PARAM(1);
610 cv::Mat src(size, CV_8UC1);
611 declare.in(src, WARMUP_RNG);
615 cv::Ptr<cv::gpu::CLAHE> clahe = cv::gpu::createCLAHE(clipLimit);
616 cv::gpu::GpuMat d_src(src);
619 TEST_CYCLE() clahe->apply(d_src, dst);
621 GPU_SANITY_CHECK(dst);
625 cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE(clipLimit);
628 TEST_CYCLE() clahe->apply(src, dst);
630 CPU_SANITY_CHECK(dst);
634 //////////////////////////////////////////////////////////////////////
637 PERF_TEST_P(Sz, ImgProc_ColumnSum,
638 GPU_TYPICAL_MAT_SIZES)
640 const cv::Size size = GetParam();
642 cv::Mat src(size, CV_32FC1);
643 declare.in(src, WARMUP_RNG);
647 const cv::gpu::GpuMat d_src(src);
650 TEST_CYCLE() cv::gpu::columnSum(d_src, dst);
652 GPU_SANITY_CHECK(dst);
660 //////////////////////////////////////////////////////////////////////
663 DEF_PARAM_TEST(Image_AppertureSz_L2gradient, string, int, bool);
665 PERF_TEST_P(Image_AppertureSz_L2gradient, ImgProc_Canny,
666 Combine(Values("perf/800x600.png", "perf/1280x1024.png", "perf/1680x1050.png"),
670 const string fileName = GET_PARAM(0);
671 const int apperture_size = GET_PARAM(1);
672 const bool useL2gradient = GET_PARAM(2);
674 const cv::Mat image = readImage(fileName, cv::IMREAD_GRAYSCALE);
675 ASSERT_FALSE(image.empty());
677 const double low_thresh = 50.0;
678 const double high_thresh = 100.0;
682 const cv::gpu::GpuMat d_image(image);
684 cv::gpu::CannyBuf d_buf;
686 TEST_CYCLE() cv::gpu::Canny(d_image, d_buf, dst, low_thresh, high_thresh, apperture_size, useL2gradient);
688 GPU_SANITY_CHECK(dst);
694 TEST_CYCLE() cv::Canny(image, dst, low_thresh, high_thresh, apperture_size, useL2gradient);
696 CPU_SANITY_CHECK(dst);
700 //////////////////////////////////////////////////////////////////////
701 // MeanShiftFiltering
703 DEF_PARAM_TEST_1(Image, string);
705 PERF_TEST_P(Image, ImgProc_MeanShiftFiltering,
706 Values<string>("gpu/meanshift/cones.png"))
710 const cv::Mat img = readImage(GetParam());
711 ASSERT_FALSE(img.empty());
714 cv::cvtColor(img, rgba, cv::COLOR_BGR2BGRA);
721 const cv::gpu::GpuMat d_src(rgba);
724 TEST_CYCLE() cv::gpu::meanShiftFiltering(d_src, dst, sp, sr);
726 GPU_SANITY_CHECK(dst);
732 TEST_CYCLE() cv::pyrMeanShiftFiltering(img, dst, sp, sr);
734 CPU_SANITY_CHECK(dst);
738 //////////////////////////////////////////////////////////////////////
741 PERF_TEST_P(Image, ImgProc_MeanShiftProc,
742 Values<string>("gpu/meanshift/cones.png"))
746 const cv::Mat img = readImage(GetParam());
747 ASSERT_FALSE(img.empty());
750 cv::cvtColor(img, rgba, cv::COLOR_BGR2BGRA);
757 const cv::gpu::GpuMat d_src(rgba);
758 cv::gpu::GpuMat dstr;
759 cv::gpu::GpuMat dstsp;
761 TEST_CYCLE() cv::gpu::meanShiftProc(d_src, dstr, dstsp, sp, sr);
763 GPU_SANITY_CHECK(dstr);
764 GPU_SANITY_CHECK(dstsp);
772 //////////////////////////////////////////////////////////////////////
773 // MeanShiftSegmentation
775 PERF_TEST_P(Image, ImgProc_MeanShiftSegmentation,
776 Values<string>("gpu/meanshift/cones.png"))
780 const cv::Mat img = readImage(GetParam());
781 ASSERT_FALSE(img.empty());
784 cv::cvtColor(img, rgba, cv::COLOR_BGR2BGRA);
788 const int minsize = 20;
792 const cv::gpu::GpuMat d_src(rgba);
795 TEST_CYCLE() cv::gpu::meanShiftSegmentation(d_src, dst, sp, sr, minsize);
797 GPU_SANITY_CHECK(dst);
805 //////////////////////////////////////////////////////////////////////
808 PERF_TEST_P(Sz_Depth_Cn, ImgProc_BlendLinear,
809 Combine(GPU_TYPICAL_MAT_SIZES,
810 Values(CV_8U, CV_32F),
813 const cv::Size size = GET_PARAM(0);
814 const int depth = GET_PARAM(1);
815 const int channels = GET_PARAM(2);
817 const int type = CV_MAKE_TYPE(depth, channels);
819 cv::Mat img1(size, type);
820 cv::Mat img2(size, type);
821 declare.in(img1, img2, WARMUP_RNG);
823 const cv::Mat weights1(size, CV_32FC1, cv::Scalar::all(0.5));
824 const cv::Mat weights2(size, CV_32FC1, cv::Scalar::all(0.5));
828 const cv::gpu::GpuMat d_img1(img1);
829 const cv::gpu::GpuMat d_img2(img2);
830 const cv::gpu::GpuMat d_weights1(weights1);
831 const cv::gpu::GpuMat d_weights2(weights2);
834 TEST_CYCLE() cv::gpu::blendLinear(d_img1, d_img2, d_weights1, d_weights2, dst);
836 GPU_SANITY_CHECK(dst);
844 //////////////////////////////////////////////////////////////////////
847 DEF_PARAM_TEST(Sz_KernelSz_Ccorr, cv::Size, int, bool);
849 PERF_TEST_P(Sz_KernelSz_Ccorr, ImgProc_Convolve,
850 Combine(GPU_TYPICAL_MAT_SIZES,
851 Values(17, 27, 32, 64),
856 const cv::Size size = GET_PARAM(0);
857 const int templ_size = GET_PARAM(1);
858 const bool ccorr = GET_PARAM(2);
860 const cv::Mat image(size, CV_32FC1);
861 const cv::Mat templ(templ_size, templ_size, CV_32FC1);
862 declare.in(image, templ, WARMUP_RNG);
866 cv::gpu::GpuMat d_image = cv::gpu::createContinuous(size, CV_32FC1);
867 d_image.upload(image);
869 cv::gpu::GpuMat d_templ = cv::gpu::createContinuous(templ_size, templ_size, CV_32FC1);
870 d_templ.upload(templ);
873 cv::gpu::ConvolveBuf d_buf;
875 TEST_CYCLE() cv::gpu::convolve(d_image, d_templ, dst, ccorr, d_buf);
877 GPU_SANITY_CHECK(dst);
886 TEST_CYCLE() cv::filter2D(image, dst, image.depth(), templ);
888 CPU_SANITY_CHECK(dst);
892 ////////////////////////////////////////////////////////////////////////////////
895 CV_ENUM(TemplateMethod, TM_SQDIFF, TM_SQDIFF_NORMED, TM_CCORR, TM_CCORR_NORMED, TM_CCOEFF, TM_CCOEFF_NORMED)
897 DEF_PARAM_TEST(Sz_TemplateSz_Cn_Method, cv::Size, cv::Size, MatCn, TemplateMethod);
899 PERF_TEST_P(Sz_TemplateSz_Cn_Method, ImgProc_MatchTemplate8U,
900 Combine(GPU_TYPICAL_MAT_SIZES,
901 Values(cv::Size(5, 5), cv::Size(16, 16), cv::Size(30, 30)),
903 TemplateMethod::all()))
907 const cv::Size size = GET_PARAM(0);
908 const cv::Size templ_size = GET_PARAM(1);
909 const int cn = GET_PARAM(2);
910 const int method = GET_PARAM(3);
912 cv::Mat image(size, CV_MAKE_TYPE(CV_8U, cn));
913 cv::Mat templ(templ_size, CV_MAKE_TYPE(CV_8U, cn));
914 declare.in(image, templ, WARMUP_RNG);
918 const cv::gpu::GpuMat d_image(image);
919 const cv::gpu::GpuMat d_templ(templ);
922 TEST_CYCLE() cv::gpu::matchTemplate(d_image, d_templ, dst, method);
924 GPU_SANITY_CHECK(dst, 1e-5, ERROR_RELATIVE);
930 TEST_CYCLE() cv::matchTemplate(image, templ, dst, method);
932 CPU_SANITY_CHECK(dst);
936 ////////////////////////////////////////////////////////////////////////////////
939 PERF_TEST_P(Sz_TemplateSz_Cn_Method, ImgProc_MatchTemplate32F,
940 Combine(GPU_TYPICAL_MAT_SIZES,
941 Values(cv::Size(5, 5), cv::Size(16, 16), cv::Size(30, 30)),
943 Values(TemplateMethod(cv::TM_SQDIFF), TemplateMethod(cv::TM_CCORR))))
947 const cv::Size size = GET_PARAM(0);
948 const cv::Size templ_size = GET_PARAM(1);
949 const int cn = GET_PARAM(2);
950 int method = GET_PARAM(3);
952 cv::Mat image(size, CV_MAKE_TYPE(CV_32F, cn));
953 cv::Mat templ(templ_size, CV_MAKE_TYPE(CV_32F, cn));
954 declare.in(image, templ, WARMUP_RNG);
958 const cv::gpu::GpuMat d_image(image);
959 const cv::gpu::GpuMat d_templ(templ);
962 TEST_CYCLE() cv::gpu::matchTemplate(d_image, d_templ, dst, method);
964 GPU_SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
970 TEST_CYCLE() cv::matchTemplate(image, templ, dst, method);
972 CPU_SANITY_CHECK(dst);
976 //////////////////////////////////////////////////////////////////////
979 CV_FLAGS(DftFlags, 0, DFT_INVERSE, DFT_SCALE, DFT_ROWS, DFT_COMPLEX_OUTPUT, DFT_REAL_OUTPUT)
981 DEF_PARAM_TEST(Sz_Flags, cv::Size, DftFlags);
983 PERF_TEST_P(Sz_Flags, ImgProc_MulSpectrums,
984 Combine(GPU_TYPICAL_MAT_SIZES,
985 Values(0, DftFlags(cv::DFT_ROWS))))
987 const cv::Size size = GET_PARAM(0);
988 const int flag = GET_PARAM(1);
990 cv::Mat a(size, CV_32FC2);
991 cv::Mat b(size, CV_32FC2);
992 declare.in(a, b, WARMUP_RNG);
996 const cv::gpu::GpuMat d_a(a);
997 const cv::gpu::GpuMat d_b(b);
1000 TEST_CYCLE() cv::gpu::mulSpectrums(d_a, d_b, dst, flag);
1002 GPU_SANITY_CHECK(dst);
1008 TEST_CYCLE() cv::mulSpectrums(a, b, dst, flag);
1010 CPU_SANITY_CHECK(dst);
1014 //////////////////////////////////////////////////////////////////////
1015 // MulAndScaleSpectrums
1017 PERF_TEST_P(Sz, ImgProc_MulAndScaleSpectrums,
1018 GPU_TYPICAL_MAT_SIZES)
1020 const cv::Size size = GetParam();
1022 const float scale = 1.f / size.area();
1024 cv::Mat src1(size, CV_32FC2);
1025 cv::Mat src2(size, CV_32FC2);
1026 declare.in(src1,src2, WARMUP_RNG);
1030 const cv::gpu::GpuMat d_src1(src1);
1031 const cv::gpu::GpuMat d_src2(src2);
1032 cv::gpu::GpuMat dst;
1034 TEST_CYCLE() cv::gpu::mulAndScaleSpectrums(d_src1, d_src2, dst, cv::DFT_ROWS, scale, false);
1036 GPU_SANITY_CHECK(dst);
1044 //////////////////////////////////////////////////////////////////////
1047 PERF_TEST_P(Sz_Flags, ImgProc_Dft,
1048 Combine(GPU_TYPICAL_MAT_SIZES,
1049 Values(0, DftFlags(cv::DFT_ROWS), DftFlags(cv::DFT_INVERSE))))
1053 const cv::Size size = GET_PARAM(0);
1054 const int flag = GET_PARAM(1);
1056 cv::Mat src(size, CV_32FC2);
1057 declare.in(src, WARMUP_RNG);
1061 const cv::gpu::GpuMat d_src(src);
1062 cv::gpu::GpuMat dst;
1064 TEST_CYCLE() cv::gpu::dft(d_src, dst, size, flag);
1066 GPU_SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
1072 TEST_CYCLE() cv::dft(src, dst, flag);
1074 CPU_SANITY_CHECK(dst);
1078 //////////////////////////////////////////////////////////////////////
1081 DEF_PARAM_TEST(Image_Type_Border_BlockSz_ApertureSz, string, MatType, BorderMode, int, int);
1083 PERF_TEST_P(Image_Type_Border_BlockSz_ApertureSz, ImgProc_CornerHarris,
1084 Combine(Values<string>("gpu/stereobm/aloe-L.png"),
1085 Values(CV_8UC1, CV_32FC1),
1086 Values(BorderMode(cv::BORDER_REFLECT101), BorderMode(cv::BORDER_REPLICATE), BorderMode(cv::BORDER_REFLECT)),
1088 Values(0, 3, 5, 7)))
1090 const string fileName = GET_PARAM(0);
1091 const int type = GET_PARAM(1);
1092 const int borderMode = GET_PARAM(2);
1093 const int blockSize = GET_PARAM(3);
1094 const int apertureSize = GET_PARAM(4);
1096 cv::Mat img = readImage(fileName, cv::IMREAD_GRAYSCALE);
1097 ASSERT_FALSE(img.empty());
1099 img.convertTo(img, type, type == CV_32F ? 1.0 / 255.0 : 1.0);
1101 const double k = 0.5;
1105 const cv::gpu::GpuMat d_img(img);
1106 cv::gpu::GpuMat dst;
1107 cv::gpu::GpuMat d_Dx;
1108 cv::gpu::GpuMat d_Dy;
1109 cv::gpu::GpuMat d_buf;
1111 TEST_CYCLE() cv::gpu::cornerHarris(d_img, dst, d_Dx, d_Dy, d_buf, blockSize, apertureSize, k, borderMode);
1113 GPU_SANITY_CHECK(dst, 1e-4);
1119 TEST_CYCLE() cv::cornerHarris(img, dst, blockSize, apertureSize, k, borderMode);
1121 CPU_SANITY_CHECK(dst);
1125 //////////////////////////////////////////////////////////////////////
1126 // CornerMinEigenVal
1128 PERF_TEST_P(Image_Type_Border_BlockSz_ApertureSz, ImgProc_CornerMinEigenVal,
1129 Combine(Values<string>("gpu/stereobm/aloe-L.png"),
1130 Values(CV_8UC1, CV_32FC1),
1131 Values(BorderMode(cv::BORDER_REFLECT101), BorderMode(cv::BORDER_REPLICATE), BorderMode(cv::BORDER_REFLECT)),
1133 Values(0, 3, 5, 7)))
1135 const string fileName = GET_PARAM(0);
1136 const int type = GET_PARAM(1);
1137 const int borderMode = GET_PARAM(2);
1138 const int blockSize = GET_PARAM(3);
1139 const int apertureSize = GET_PARAM(4);
1141 cv::Mat img = readImage(fileName, cv::IMREAD_GRAYSCALE);
1142 ASSERT_FALSE(img.empty());
1144 img.convertTo(img, type, type == CV_32F ? 1.0 / 255.0 : 1.0);
1148 const cv::gpu::GpuMat d_img(img);
1149 cv::gpu::GpuMat dst;
1150 cv::gpu::GpuMat d_Dx;
1151 cv::gpu::GpuMat d_Dy;
1152 cv::gpu::GpuMat d_buf;
1154 TEST_CYCLE() cv::gpu::cornerMinEigenVal(d_img, dst, d_Dx, d_Dy, d_buf, blockSize, apertureSize, borderMode);
1156 GPU_SANITY_CHECK(dst, 1e-4);
1162 TEST_CYCLE() cv::cornerMinEigenVal(img, dst, blockSize, apertureSize, borderMode);
1164 CPU_SANITY_CHECK(dst);
1168 //////////////////////////////////////////////////////////////////////
1169 // BuildWarpPlaneMaps
1171 PERF_TEST_P(Sz, ImgProc_BuildWarpPlaneMaps,
1172 GPU_TYPICAL_MAT_SIZES)
1174 const cv::Size size = GetParam();
1176 const cv::Mat K = cv::Mat::eye(3, 3, CV_32FC1);
1177 const cv::Mat R = cv::Mat::ones(3, 3, CV_32FC1);
1178 const cv::Mat T = cv::Mat::zeros(1, 3, CV_32F);
1182 cv::gpu::GpuMat map_x;
1183 cv::gpu::GpuMat map_y;
1185 TEST_CYCLE() cv::gpu::buildWarpPlaneMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, T, 1.0, map_x, map_y);
1187 GPU_SANITY_CHECK(map_x);
1188 GPU_SANITY_CHECK(map_y);
1196 //////////////////////////////////////////////////////////////////////
1197 // BuildWarpCylindricalMaps
1199 PERF_TEST_P(Sz, ImgProc_BuildWarpCylindricalMaps,
1200 GPU_TYPICAL_MAT_SIZES)
1202 const cv::Size size = GetParam();
1204 const cv::Mat K = cv::Mat::eye(3, 3, CV_32FC1);
1205 const cv::Mat R = cv::Mat::ones(3, 3, CV_32FC1);
1209 cv::gpu::GpuMat map_x;
1210 cv::gpu::GpuMat map_y;
1212 TEST_CYCLE() cv::gpu::buildWarpCylindricalMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, 1.0, map_x, map_y);
1214 GPU_SANITY_CHECK(map_x);
1215 GPU_SANITY_CHECK(map_y);
1223 //////////////////////////////////////////////////////////////////////
1224 // BuildWarpSphericalMaps
1226 PERF_TEST_P(Sz, ImgProc_BuildWarpSphericalMaps,
1227 GPU_TYPICAL_MAT_SIZES)
1229 const cv::Size size = GetParam();
1231 const cv::Mat K = cv::Mat::eye(3, 3, CV_32FC1);
1232 const cv::Mat R = cv::Mat::ones(3, 3, CV_32FC1);
1236 cv::gpu::GpuMat map_x;
1237 cv::gpu::GpuMat map_y;
1239 TEST_CYCLE() cv::gpu::buildWarpSphericalMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, 1.0, map_x, map_y);
1241 GPU_SANITY_CHECK(map_x);
1242 GPU_SANITY_CHECK(map_y);
1250 //////////////////////////////////////////////////////////////////////
1253 DEF_PARAM_TEST(Sz_Depth_Cn_Inter, cv::Size, MatDepth, MatCn, Interpolation);
1255 PERF_TEST_P(Sz_Depth_Cn_Inter, ImgProc_Rotate,
1256 Combine(GPU_TYPICAL_MAT_SIZES,
1257 Values(CV_8U, CV_16U, CV_32F),
1259 Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC))))
1261 const cv::Size size = GET_PARAM(0);
1262 const int depth = GET_PARAM(1);
1263 const int channels = GET_PARAM(2);
1264 const int interpolation = GET_PARAM(3);
1266 const int type = CV_MAKE_TYPE(depth, channels);
1268 cv::Mat src(size, type);
1269 declare.in(src, WARMUP_RNG);
1273 const cv::gpu::GpuMat d_src(src);
1274 cv::gpu::GpuMat dst;
1276 TEST_CYCLE() cv::gpu::rotate(d_src, dst, size, 30.0, 0, 0, interpolation);
1278 GPU_SANITY_CHECK(dst, 1e-3, ERROR_RELATIVE);
1286 //////////////////////////////////////////////////////////////////////
1289 PERF_TEST_P(Sz_Depth_Cn, ImgProc_PyrDown,
1290 Combine(GPU_TYPICAL_MAT_SIZES,
1291 Values(CV_8U, CV_16U, CV_32F),
1292 GPU_CHANNELS_1_3_4))
1294 const cv::Size size = GET_PARAM(0);
1295 const int depth = GET_PARAM(1);
1296 const int channels = GET_PARAM(2);
1298 const int type = CV_MAKE_TYPE(depth, channels);
1300 cv::Mat src(size, type);
1301 declare.in(src, WARMUP_RNG);
1305 const cv::gpu::GpuMat d_src(src);
1306 cv::gpu::GpuMat dst;
1308 TEST_CYCLE() cv::gpu::pyrDown(d_src, dst);
1310 GPU_SANITY_CHECK(dst);
1316 TEST_CYCLE() cv::pyrDown(src, dst);
1318 CPU_SANITY_CHECK(dst);
1322 //////////////////////////////////////////////////////////////////////
1325 PERF_TEST_P(Sz_Depth_Cn, ImgProc_PyrUp,
1326 Combine(GPU_TYPICAL_MAT_SIZES,
1327 Values(CV_8U, CV_16U, CV_32F),
1328 GPU_CHANNELS_1_3_4))
1330 const cv::Size size = GET_PARAM(0);
1331 const int depth = GET_PARAM(1);
1332 const int channels = GET_PARAM(2);
1334 const int type = CV_MAKE_TYPE(depth, channels);
1336 cv::Mat src(size, type);
1337 declare.in(src, WARMUP_RNG);
1341 const cv::gpu::GpuMat d_src(src);
1342 cv::gpu::GpuMat dst;
1344 TEST_CYCLE() cv::gpu::pyrUp(d_src, dst);
1346 GPU_SANITY_CHECK(dst);
1352 TEST_CYCLE() cv::pyrUp(src, dst);
1354 CPU_SANITY_CHECK(dst);
1358 //////////////////////////////////////////////////////////////////////
1361 DEF_PARAM_TEST(Sz_Depth_Code, cv::Size, MatDepth, CvtColorInfo);
1363 PERF_TEST_P(Sz_Depth_Code, ImgProc_CvtColor,
1364 Combine(GPU_TYPICAL_MAT_SIZES,
1365 Values(CV_8U, CV_32F),
1366 Values(CvtColorInfo(4, 4, cv::COLOR_RGBA2BGRA),
1367 CvtColorInfo(4, 1, cv::COLOR_BGRA2GRAY),
1368 CvtColorInfo(1, 4, cv::COLOR_GRAY2BGRA),
1369 CvtColorInfo(3, 3, cv::COLOR_BGR2XYZ),
1370 CvtColorInfo(3, 3, cv::COLOR_XYZ2BGR),
1371 CvtColorInfo(3, 3, cv::COLOR_BGR2YCrCb),
1372 CvtColorInfo(3, 3, cv::COLOR_YCrCb2BGR),
1373 CvtColorInfo(3, 3, cv::COLOR_BGR2YUV),
1374 CvtColorInfo(3, 3, cv::COLOR_YUV2BGR),
1375 CvtColorInfo(3, 3, cv::COLOR_BGR2HSV),
1376 CvtColorInfo(3, 3, cv::COLOR_HSV2BGR),
1377 CvtColorInfo(3, 3, cv::COLOR_BGR2HLS),
1378 CvtColorInfo(3, 3, cv::COLOR_HLS2BGR),
1379 CvtColorInfo(3, 3, cv::COLOR_BGR2Lab),
1380 CvtColorInfo(3, 3, cv::COLOR_LBGR2Lab),
1381 CvtColorInfo(3, 3, cv::COLOR_BGR2Luv),
1382 CvtColorInfo(3, 3, cv::COLOR_LBGR2Luv),
1383 CvtColorInfo(3, 3, cv::COLOR_Lab2BGR),
1384 CvtColorInfo(3, 3, cv::COLOR_Lab2LBGR),
1385 CvtColorInfo(3, 3, cv::COLOR_Luv2RGB),
1386 CvtColorInfo(3, 3, cv::COLOR_Luv2LRGB))))
1388 const cv::Size size = GET_PARAM(0);
1389 const int depth = GET_PARAM(1);
1390 const CvtColorInfo info = GET_PARAM(2);
1392 cv::Mat src(size, CV_MAKETYPE(depth, info.scn));
1393 cv::randu(src, 0, depth == CV_8U ? 255.0 : 1.0);
1397 const cv::gpu::GpuMat d_src(src);
1398 cv::gpu::GpuMat dst;
1400 TEST_CYCLE() cv::gpu::cvtColor(d_src, dst, info.code, info.dcn);
1402 GPU_SANITY_CHECK(dst, 1e-4);
1408 TEST_CYCLE() cv::cvtColor(src, dst, info.code, info.dcn);
1410 CPU_SANITY_CHECK(dst);
1414 PERF_TEST_P(Sz_Depth_Code, ImgProc_CvtColorBayer,
1415 Combine(GPU_TYPICAL_MAT_SIZES,
1416 Values(CV_8U, CV_16U),
1417 Values(CvtColorInfo(1, 3, cv::COLOR_BayerBG2BGR),
1418 CvtColorInfo(1, 3, cv::COLOR_BayerGB2BGR),
1419 CvtColorInfo(1, 3, cv::COLOR_BayerRG2BGR),
1420 CvtColorInfo(1, 3, cv::COLOR_BayerGR2BGR),
1422 CvtColorInfo(1, 1, cv::COLOR_BayerBG2GRAY),
1423 CvtColorInfo(1, 1, cv::COLOR_BayerGB2GRAY),
1424 CvtColorInfo(1, 1, cv::COLOR_BayerRG2GRAY),
1425 CvtColorInfo(1, 1, cv::COLOR_BayerGR2GRAY))))
1427 const cv::Size size = GET_PARAM(0);
1428 const int depth = GET_PARAM(1);
1429 const CvtColorInfo info = GET_PARAM(2);
1431 cv::Mat src(size, CV_MAKETYPE(depth, info.scn));
1432 declare.in(src, WARMUP_RNG);
1436 const cv::gpu::GpuMat d_src(src);
1437 cv::gpu::GpuMat dst;
1439 TEST_CYCLE() cv::gpu::cvtColor(d_src, dst, info.code, info.dcn);
1441 GPU_SANITY_CHECK(dst);
1447 TEST_CYCLE() cv::cvtColor(src, dst, info.code, info.dcn);
1449 CPU_SANITY_CHECK(dst);
1453 CV_ENUM(DemosaicingCode,
1454 COLOR_BayerBG2BGR, COLOR_BayerGB2BGR, COLOR_BayerRG2BGR, COLOR_BayerGR2BGR,
1455 COLOR_BayerBG2GRAY, COLOR_BayerGB2GRAY, COLOR_BayerRG2GRAY, COLOR_BayerGR2GRAY,
1456 COLOR_BayerBG2BGR_MHT, COLOR_BayerGB2BGR_MHT, COLOR_BayerRG2BGR_MHT, COLOR_BayerGR2BGR_MHT,
1457 COLOR_BayerBG2GRAY_MHT, COLOR_BayerGB2GRAY_MHT, COLOR_BayerRG2GRAY_MHT, COLOR_BayerGR2GRAY_MHT)
1459 DEF_PARAM_TEST(Sz_Code, cv::Size, DemosaicingCode);
1461 PERF_TEST_P(Sz_Code, ImgProc_Demosaicing,
1462 Combine(GPU_TYPICAL_MAT_SIZES,
1463 DemosaicingCode::all()))
1465 const cv::Size size = GET_PARAM(0);
1466 const int code = GET_PARAM(1);
1468 cv::Mat src(size, CV_8UC1);
1469 declare.in(src, WARMUP_RNG);
1473 const cv::gpu::GpuMat d_src(src);
1474 cv::gpu::GpuMat dst;
1476 TEST_CYCLE() cv::gpu::demosaicing(d_src, dst, code);
1478 GPU_SANITY_CHECK(dst);
1482 if (code >= cv::COLOR_COLORCVT_MAX)
1490 TEST_CYCLE() cv::cvtColor(src, dst, code);
1492 CPU_SANITY_CHECK(dst);
1497 //////////////////////////////////////////////////////////////////////
1500 PERF_TEST_P(Sz, ImgProc_SwapChannels,
1501 GPU_TYPICAL_MAT_SIZES)
1503 const cv::Size size = GetParam();
1505 cv::Mat src(size, CV_8UC4);
1506 declare.in(src, WARMUP_RNG);
1508 const int dstOrder[] = {2, 1, 0, 3};
1512 cv::gpu::GpuMat dst(src);
1514 TEST_CYCLE() cv::gpu::swapChannels(dst, dstOrder);
1516 GPU_SANITY_CHECK(dst);
1524 //////////////////////////////////////////////////////////////////////
1527 CV_ENUM(AlphaOp, ALPHA_OVER, ALPHA_IN, ALPHA_OUT, ALPHA_ATOP, ALPHA_XOR, ALPHA_PLUS, ALPHA_OVER_PREMUL, ALPHA_IN_PREMUL, ALPHA_OUT_PREMUL, ALPHA_ATOP_PREMUL, ALPHA_XOR_PREMUL, ALPHA_PLUS_PREMUL, ALPHA_PREMUL)
1529 DEF_PARAM_TEST(Sz_Type_Op, cv::Size, MatType, AlphaOp);
1531 PERF_TEST_P(Sz_Type_Op, ImgProc_AlphaComp,
1532 Combine(GPU_TYPICAL_MAT_SIZES,
1533 Values(CV_8UC4, CV_16UC4, CV_32SC4, CV_32FC4),
1536 const cv::Size size = GET_PARAM(0);
1537 const int type = GET_PARAM(1);
1538 const int alpha_op = GET_PARAM(2);
1540 cv::Mat img1(size, type);
1541 cv::Mat img2(size, type);
1542 declare.in(img1, img2, WARMUP_RNG);
1546 const cv::gpu::GpuMat d_img1(img1);
1547 const cv::gpu::GpuMat d_img2(img2);
1548 cv::gpu::GpuMat dst;
1550 TEST_CYCLE() cv::gpu::alphaComp(d_img1, d_img2, dst, alpha_op);
1552 GPU_SANITY_CHECK(dst, 1e-3, ERROR_RELATIVE);
1560 //////////////////////////////////////////////////////////////////////
1561 // ImagePyramidBuild
1563 PERF_TEST_P(Sz_Depth_Cn, ImgProc_ImagePyramidBuild,
1564 Combine(GPU_TYPICAL_MAT_SIZES,
1565 Values(CV_8U, CV_16U, CV_32F),
1566 GPU_CHANNELS_1_3_4))
1568 const cv::Size size = GET_PARAM(0);
1569 const int depth = GET_PARAM(1);
1570 const int channels = GET_PARAM(2);
1572 const int type = CV_MAKE_TYPE(depth, channels);
1574 cv::Mat src(size, type);
1575 declare.in(src, WARMUP_RNG);
1577 const int nLayers = 5;
1578 const cv::Size dstSize(size.width / 2 + 10, size.height / 2 + 10);
1582 const cv::gpu::GpuMat d_src(src);
1584 cv::gpu::ImagePyramid d_pyr;
1586 TEST_CYCLE() d_pyr.build(d_src, nLayers);
1588 cv::gpu::GpuMat dst;
1589 d_pyr.getLayer(dst, dstSize);
1591 GPU_SANITY_CHECK(dst);
1599 //////////////////////////////////////////////////////////////////////
1600 // ImagePyramidGetLayer
1602 PERF_TEST_P(Sz_Depth_Cn, ImgProc_ImagePyramidGetLayer,
1603 Combine(GPU_TYPICAL_MAT_SIZES,
1604 Values(CV_8U, CV_16U, CV_32F),
1605 GPU_CHANNELS_1_3_4))
1607 const cv::Size size = GET_PARAM(0);
1608 const int depth = GET_PARAM(1);
1609 const int channels = GET_PARAM(2);
1611 const int type = CV_MAKE_TYPE(depth, channels);
1613 cv::Mat src(size, type);
1614 declare.in(src, WARMUP_RNG);
1616 const int nLayers = 3;
1617 const cv::Size dstSize(size.width / 2 + 10, size.height / 2 + 10);
1621 const cv::gpu::GpuMat d_src(src);
1622 cv::gpu::GpuMat dst;
1624 cv::gpu::ImagePyramid d_pyr(d_src, nLayers);
1626 TEST_CYCLE() d_pyr.getLayer(dst, dstSize);
1628 GPU_SANITY_CHECK(dst);
1636 //////////////////////////////////////////////////////////////////////
1641 struct Vec4iComparator
1643 bool operator()(const cv::Vec4i& a, const cv::Vec4i b) const
1645 if (a[0] != b[0]) return a[0] < b[0];
1646 else if(a[1] != b[1]) return a[1] < b[1];
1647 else if(a[2] != b[2]) return a[2] < b[2];
1648 else return a[3] < b[3];
1651 struct Vec3fComparator
1653 bool operator()(const cv::Vec3f& a, const cv::Vec3f b) const
1655 if(a[0] != b[0]) return a[0] < b[0];
1656 else if(a[1] != b[1]) return a[1] < b[1];
1657 else return a[2] < b[2];
1660 struct Vec2fComparator
1662 bool operator()(const cv::Vec2f& a, const cv::Vec2f b) const
1664 if(a[0] != b[0]) return a[0] < b[0];
1665 else return a[1] < b[1];
1670 PERF_TEST_P(Sz, ImgProc_HoughLines,
1671 GPU_TYPICAL_MAT_SIZES)
1675 const cv::Size size = GetParam();
1677 const float rho = 1.0f;
1678 const float theta = static_cast<float>(CV_PI / 180.0);
1679 const int threshold = 300;
1681 cv::Mat src(size, CV_8UC1, cv::Scalar::all(0));
1682 cv::line(src, cv::Point(0, 100), cv::Point(src.cols, 100), cv::Scalar::all(255), 1);
1683 cv::line(src, cv::Point(0, 200), cv::Point(src.cols, 200), cv::Scalar::all(255), 1);
1684 cv::line(src, cv::Point(0, 400), cv::Point(src.cols, 400), cv::Scalar::all(255), 1);
1685 cv::line(src, cv::Point(100, 0), cv::Point(100, src.rows), cv::Scalar::all(255), 1);
1686 cv::line(src, cv::Point(200, 0), cv::Point(200, src.rows), cv::Scalar::all(255), 1);
1687 cv::line(src, cv::Point(400, 0), cv::Point(400, src.rows), cv::Scalar::all(255), 1);
1691 const cv::gpu::GpuMat d_src(src);
1692 cv::gpu::GpuMat d_lines;
1693 cv::gpu::HoughLinesBuf d_buf;
1695 TEST_CYCLE() cv::gpu::HoughLines(d_src, d_lines, d_buf, rho, theta, threshold);
1697 cv::Mat gpu_lines(d_lines.row(0));
1698 cv::Vec2f* begin = gpu_lines.ptr<cv::Vec2f>(0);
1699 cv::Vec2f* end = begin + gpu_lines.cols;
1700 std::sort(begin, end, Vec2fComparator());
1701 SANITY_CHECK(gpu_lines);
1705 std::vector<cv::Vec2f> cpu_lines;
1707 TEST_CYCLE() cv::HoughLines(src, cpu_lines, rho, theta, threshold);
1709 SANITY_CHECK(cpu_lines);
1713 //////////////////////////////////////////////////////////////////////
1716 DEF_PARAM_TEST_1(Image, std::string);
1718 PERF_TEST_P(Image, ImgProc_HoughLinesP,
1719 testing::Values("cv/shared/pic5.png", "stitching/a1.png"))
1723 const std::string fileName = getDataPath(GetParam());
1725 const float rho = 1.0f;
1726 const float theta = static_cast<float>(CV_PI / 180.0);
1727 const int threshold = 100;
1728 const int minLineLenght = 50;
1729 const int maxLineGap = 5;
1731 const cv::Mat image = cv::imread(fileName, cv::IMREAD_GRAYSCALE);
1732 ASSERT_FALSE(image.empty());
1735 cv::Canny(image, mask, 50, 100);
1739 const cv::gpu::GpuMat d_mask(mask);
1740 cv::gpu::GpuMat d_lines;
1741 cv::gpu::HoughLinesBuf d_buf;
1743 TEST_CYCLE() cv::gpu::HoughLinesP(d_mask, d_lines, d_buf, rho, theta, minLineLenght, maxLineGap);
1745 cv::Mat gpu_lines(d_lines);
1746 cv::Vec4i* begin = gpu_lines.ptr<cv::Vec4i>();
1747 cv::Vec4i* end = begin + gpu_lines.cols;
1748 std::sort(begin, end, Vec4iComparator());
1749 SANITY_CHECK(gpu_lines);
1753 std::vector<cv::Vec4i> cpu_lines;
1755 TEST_CYCLE() cv::HoughLinesP(mask, cpu_lines, rho, theta, threshold, minLineLenght, maxLineGap);
1757 SANITY_CHECK(cpu_lines);
1761 //////////////////////////////////////////////////////////////////////
1764 DEF_PARAM_TEST(Sz_Dp_MinDist, cv::Size, float, float);
1766 PERF_TEST_P(Sz_Dp_MinDist, ImgProc_HoughCircles,
1767 Combine(GPU_TYPICAL_MAT_SIZES,
1768 Values(1.0f, 2.0f, 4.0f),
1773 const cv::Size size = GET_PARAM(0);
1774 const float dp = GET_PARAM(1);
1775 const float minDist = GET_PARAM(2);
1777 const int minRadius = 10;
1778 const int maxRadius = 30;
1779 const int cannyThreshold = 100;
1780 const int votesThreshold = 15;
1782 cv::Mat src(size, CV_8UC1, cv::Scalar::all(0));
1783 cv::circle(src, cv::Point(100, 100), 20, cv::Scalar::all(255), -1);
1784 cv::circle(src, cv::Point(200, 200), 25, cv::Scalar::all(255), -1);
1785 cv::circle(src, cv::Point(200, 100), 25, cv::Scalar::all(255), -1);
1789 const cv::gpu::GpuMat d_src(src);
1790 cv::gpu::GpuMat d_circles;
1791 cv::gpu::HoughCirclesBuf d_buf;
1793 TEST_CYCLE() cv::gpu::HoughCircles(d_src, d_circles, d_buf, CV_HOUGH_GRADIENT, dp, minDist, cannyThreshold, votesThreshold, minRadius, maxRadius);
1795 cv::Mat gpu_circles(d_circles);
1796 cv::Vec3f* begin = gpu_circles.ptr<cv::Vec3f>(0);
1797 cv::Vec3f* end = begin + gpu_circles.cols;
1798 std::sort(begin, end, Vec3fComparator());
1799 SANITY_CHECK(gpu_circles);
1803 std::vector<cv::Vec3f> cpu_circles;
1805 TEST_CYCLE() cv::HoughCircles(src, cpu_circles, CV_HOUGH_GRADIENT, dp, minDist, cannyThreshold, votesThreshold, minRadius, maxRadius);
1807 SANITY_CHECK(cpu_circles);
1811 //////////////////////////////////////////////////////////////////////
1814 CV_FLAGS(GHMethod, GHT_POSITION, GHT_SCALE, GHT_ROTATION);
1816 DEF_PARAM_TEST(Method_Sz, GHMethod, cv::Size);
1818 PERF_TEST_P(Method_Sz, ImgProc_GeneralizedHough,
1819 Combine(Values(GHMethod(cv::GHT_POSITION), GHMethod(cv::GHT_POSITION | cv::GHT_SCALE), GHMethod(cv::GHT_POSITION | cv::GHT_ROTATION), GHMethod(cv::GHT_POSITION | cv::GHT_SCALE | cv::GHT_ROTATION)),
1820 GPU_TYPICAL_MAT_SIZES))
1824 const int method = GET_PARAM(0);
1825 const cv::Size imageSize = GET_PARAM(1);
1827 const cv::Mat templ = readImage("cv/shared/templ.png", cv::IMREAD_GRAYSCALE);
1828 ASSERT_FALSE(templ.empty());
1830 cv::Mat image(imageSize, CV_8UC1, cv::Scalar::all(0));
1831 templ.copyTo(image(cv::Rect(50, 50, templ.cols, templ.rows)));
1833 cv::RNG rng(123456789);
1834 const int objCount = rng.uniform(5, 15);
1835 for (int i = 0; i < objCount; ++i)
1837 double scale = rng.uniform(0.7, 1.3);
1838 bool rotate = 1 == rng.uniform(0, 2);
1841 cv::resize(templ, obj, cv::Size(), scale, scale);
1847 pos.x = rng.uniform(0, image.cols - obj.cols);
1848 pos.y = rng.uniform(0, image.rows - obj.rows);
1850 cv::Mat roi = image(cv::Rect(pos, obj.size()));
1851 cv::add(roi, obj, roi);
1855 cv::Canny(image, edges, 50, 100);
1858 cv::Sobel(image, dx, CV_32F, 1, 0);
1859 cv::Sobel(image, dy, CV_32F, 0, 1);
1863 const cv::gpu::GpuMat d_edges(edges);
1864 const cv::gpu::GpuMat d_dx(dx);
1865 const cv::gpu::GpuMat d_dy(dy);
1866 cv::gpu::GpuMat posAndVotes;
1868 cv::Ptr<cv::gpu::GeneralizedHough_GPU> d_hough = cv::gpu::GeneralizedHough_GPU::create(method);
1869 if (method & cv::GHT_ROTATION)
1871 d_hough->set("maxAngle", 90.0);
1872 d_hough->set("angleStep", 2.0);
1875 d_hough->setTemplate(cv::gpu::GpuMat(templ));
1877 TEST_CYCLE() d_hough->detect(d_edges, d_dx, d_dy, posAndVotes);
1879 const cv::gpu::GpuMat positions(1, posAndVotes.cols, CV_32FC4, posAndVotes.data);
1880 GPU_SANITY_CHECK(positions);
1886 cv::Ptr<cv::GeneralizedHough> hough = cv::GeneralizedHough::create(method);
1887 if (method & cv::GHT_ROTATION)
1889 hough->set("maxAngle", 90.0);
1890 hough->set("angleStep", 2.0);
1893 hough->setTemplate(templ);
1895 TEST_CYCLE() hough->detect(edges, dx, dy, positions);
1897 CPU_SANITY_CHECK(positions);