CLAHE Python bindings
[profile/ivi/opencv.git] / modules / gpu / perf / perf_imgproc.cpp
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
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.
8 //
9 //
10 //                           License Agreement
11 //                For Open Source Computer Vision Library
12 //
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.
16 //
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
19 //
20 //   * Redistribution's of source code must retain the above copyright notice,
21 //     this list of conditions and the following disclaimer.
22 //
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.
26 //
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.
29 //
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.
40 //
41 //M*/
42
43 #include "perf_precomp.hpp"
44
45 using namespace std;
46 using namespace testing;
47 using namespace perf;
48
49 //////////////////////////////////////////////////////////////////////
50 // Remap
51
52 enum { HALF_SIZE=0, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH };
53 CV_ENUM(RemapMode, HALF_SIZE, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH);
54
55 void generateMap(cv::Mat& map_x, cv::Mat& map_y, int remapMode)
56 {
57     for (int j = 0; j < map_x.rows; ++j)
58     {
59         for (int i = 0; i < map_x.cols; ++i)
60         {
61             switch (remapMode)
62             {
63             case HALF_SIZE:
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)
65                 {
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;
68                 }
69                 else
70                 {
71                     map_x.at<float>(j,i) = 0.f;
72                     map_y.at<float>(j,i) = 0.f;
73                 }
74                 break;
75             case UPSIDE_DOWN:
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);
78                 break;
79             case REFLECTION_X:
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);
82                 break;
83             case REFLECTION_BOTH:
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);
86                 break;
87             } // end of switch
88         }
89     }
90 }
91
92 DEF_PARAM_TEST(Sz_Depth_Cn_Inter_Border_Mode, cv::Size, MatDepth, MatCn, Interpolation, BorderMode, RemapMode);
93
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),
97                     GPU_CHANNELS_1_3_4,
98                     Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
99                     ALL_BORDER_MODES,
100                     RemapMode::all()))
101 {
102     declare.time(20.0);
103
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);
110
111     const int type = CV_MAKE_TYPE(depth, channels);
112
113     cv::Mat src(size, type);
114     declare.in(src, WARMUP_RNG);
115
116     cv::Mat xmap(size, CV_32FC1);
117     cv::Mat ymap(size, CV_32FC1);
118     generateMap(xmap, ymap, remapMode);
119
120     if (PERF_RUN_GPU())
121     {
122         const cv::gpu::GpuMat d_src(src);
123         const cv::gpu::GpuMat d_xmap(xmap);
124         const cv::gpu::GpuMat d_ymap(ymap);
125         cv::gpu::GpuMat dst;
126
127         TEST_CYCLE() cv::gpu::remap(d_src, dst, d_xmap, d_ymap, interpolation, borderMode);
128
129         GPU_SANITY_CHECK(dst);
130     }
131     else
132     {
133         cv::Mat dst;
134
135         TEST_CYCLE() cv::remap(src, dst, xmap, ymap, interpolation, borderMode);
136
137         CPU_SANITY_CHECK(dst);
138     }
139 }
140
141 //////////////////////////////////////////////////////////////////////
142 // Resize
143
144 DEF_PARAM_TEST(Sz_Depth_Cn_Inter_Scale, cv::Size, MatDepth, MatCn, Interpolation, double);
145
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),
149                     GPU_CHANNELS_1_3_4,
150                     Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
151                     Values(0.5, 0.3, 2.0)))
152 {
153     declare.time(20.0);
154
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);
160
161     const int type = CV_MAKE_TYPE(depth, channels);
162
163     cv::Mat src(size, type);
164     declare.in(src, WARMUP_RNG);
165
166     if (PERF_RUN_GPU())
167     {
168         const cv::gpu::GpuMat d_src(src);
169         cv::gpu::GpuMat dst;
170
171         TEST_CYCLE() cv::gpu::resize(d_src, dst, cv::Size(), f, f, interpolation);
172
173         GPU_SANITY_CHECK(dst, 1e-3, ERROR_RELATIVE);
174     }
175     else
176     {
177         cv::Mat dst;
178
179         TEST_CYCLE() cv::resize(src, dst, cv::Size(), f, f, interpolation);
180
181         CPU_SANITY_CHECK(dst);
182     }
183 }
184
185 //////////////////////////////////////////////////////////////////////
186 // ResizeArea
187
188 DEF_PARAM_TEST(Sz_Depth_Cn_Scale, cv::Size, MatDepth, MatCn, double);
189
190 PERF_TEST_P(Sz_Depth_Cn_Scale, ImgProc_ResizeArea,
191             Combine(GPU_TYPICAL_MAT_SIZES,
192                     Values(CV_8U, CV_16U, CV_32F),
193                     GPU_CHANNELS_1_3_4,
194                     Values(0.2, 0.1, 0.05)))
195 {
196     declare.time(1.0);
197
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);
203
204     const int type = CV_MAKE_TYPE(depth, channels);
205
206     cv::Mat src(size, type);
207     declare.in(src, WARMUP_RNG);
208
209     if (PERF_RUN_GPU())
210     {
211         const cv::gpu::GpuMat d_src(src);
212         cv::gpu::GpuMat dst;
213
214         TEST_CYCLE() cv::gpu::resize(d_src, dst, cv::Size(), f, f, interpolation);
215
216         GPU_SANITY_CHECK(dst);
217     }
218     else
219     {
220         cv::Mat dst;
221
222         TEST_CYCLE() cv::resize(src, dst, cv::Size(), f, f, interpolation);
223
224         CPU_SANITY_CHECK(dst);
225     }
226 }
227
228 //////////////////////////////////////////////////////////////////////
229 // WarpAffine
230
231 DEF_PARAM_TEST(Sz_Depth_Cn_Inter_Border, cv::Size, MatDepth, MatCn, Interpolation, BorderMode);
232
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),
236                     GPU_CHANNELS_1_3_4,
237                     Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
238                     ALL_BORDER_MODES))
239 {
240     declare.time(20.0);
241
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);
247
248     const int type = CV_MAKE_TYPE(depth, channels);
249
250     cv::Mat src(size, type);
251     declare.in(src, WARMUP_RNG);
252
253     const double aplha = CV_PI / 4;
254     const double mat[2 * 3] =
255     {
256         std::cos(aplha), -std::sin(aplha), src.cols / 2,
257         std::sin(aplha),  std::cos(aplha), 0
258     };
259     const cv::Mat M(2, 3, CV_64F, (void*) mat);
260
261     if (PERF_RUN_GPU())
262     {
263         const cv::gpu::GpuMat d_src(src);
264         cv::gpu::GpuMat dst;
265
266         TEST_CYCLE() cv::gpu::warpAffine(d_src, dst, M, size, interpolation, borderMode);
267
268         GPU_SANITY_CHECK(dst, 1);
269     }
270     else
271     {
272         cv::Mat dst;
273
274         TEST_CYCLE() cv::warpAffine(src, dst, M, size, interpolation, borderMode);
275
276         CPU_SANITY_CHECK(dst);
277     }
278 }
279
280 //////////////////////////////////////////////////////////////////////
281 // WarpPerspective
282
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),
286                     GPU_CHANNELS_1_3_4,
287                     Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
288                     ALL_BORDER_MODES))
289 {
290     declare.time(20.0);
291
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);
297
298     const int type = CV_MAKE_TYPE(depth, channels);
299
300     cv::Mat src(size, type);
301     declare.in(src, WARMUP_RNG);
302
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},
306                          {0.0,              0.0,             1.0}};
307     const cv::Mat M(3, 3, CV_64F, (void*) mat);
308
309     if (PERF_RUN_GPU())
310     {
311         const cv::gpu::GpuMat d_src(src);
312         cv::gpu::GpuMat dst;
313
314         TEST_CYCLE() cv::gpu::warpPerspective(d_src, dst, M, size, interpolation, borderMode);
315
316         GPU_SANITY_CHECK(dst, 1);
317     }
318     else
319     {
320         cv::Mat dst;
321
322         TEST_CYCLE() cv::warpPerspective(src, dst, M, size, interpolation, borderMode);
323
324         CPU_SANITY_CHECK(dst);
325     }
326 }
327
328 //////////////////////////////////////////////////////////////////////
329 // CopyMakeBorder
330
331 DEF_PARAM_TEST(Sz_Depth_Cn_Border, cv::Size, MatDepth, MatCn, BorderMode);
332
333 PERF_TEST_P(Sz_Depth_Cn_Border, ImgProc_CopyMakeBorder,
334             Combine(GPU_TYPICAL_MAT_SIZES,
335                     Values(CV_8U, CV_16U, CV_32F),
336                     GPU_CHANNELS_1_3_4,
337                     ALL_BORDER_MODES))
338 {
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);
343
344     const int type = CV_MAKE_TYPE(depth, channels);
345
346     cv::Mat src(size, type);
347     declare.in(src, WARMUP_RNG);
348
349     if (PERF_RUN_GPU())
350     {
351         const cv::gpu::GpuMat d_src(src);
352         cv::gpu::GpuMat dst;
353
354         TEST_CYCLE() cv::gpu::copyMakeBorder(d_src, dst, 5, 5, 5, 5, borderMode);
355
356         GPU_SANITY_CHECK(dst);
357     }
358     else
359     {
360         cv::Mat dst;
361
362         TEST_CYCLE() cv::copyMakeBorder(src, dst, 5, 5, 5, 5, borderMode);
363
364         CPU_SANITY_CHECK(dst);
365     }
366 }
367
368 //////////////////////////////////////////////////////////////////////
369 // Threshold
370
371 CV_ENUM(ThreshOp, THRESH_BINARY, THRESH_BINARY_INV, THRESH_TRUNC, THRESH_TOZERO, THRESH_TOZERO_INV)
372
373 DEF_PARAM_TEST(Sz_Depth_Op, cv::Size, MatDepth, ThreshOp);
374
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),
378             ThreshOp::all()))
379 {
380     const cv::Size size = GET_PARAM(0);
381     const int depth = GET_PARAM(1);
382     const int threshOp = GET_PARAM(2);
383
384     cv::Mat src(size, depth);
385     declare.in(src, WARMUP_RNG);
386
387     if (PERF_RUN_GPU())
388     {
389         const cv::gpu::GpuMat d_src(src);
390         cv::gpu::GpuMat dst;
391
392         TEST_CYCLE() cv::gpu::threshold(d_src, dst, 100.0, 255.0, threshOp);
393
394         GPU_SANITY_CHECK(dst, 1e-10);
395     }
396     else
397     {
398         cv::Mat dst;
399
400         TEST_CYCLE() cv::threshold(src, dst, 100.0, 255.0, threshOp);
401
402         CPU_SANITY_CHECK(dst);
403     }
404 }
405
406 //////////////////////////////////////////////////////////////////////
407 // Integral
408
409 PERF_TEST_P(Sz, ImgProc_Integral,
410             GPU_TYPICAL_MAT_SIZES)
411 {
412     const cv::Size size = GetParam();
413
414     cv::Mat src(size, CV_8UC1);
415     declare.in(src, WARMUP_RNG);
416
417     if (PERF_RUN_GPU())
418     {
419         const cv::gpu::GpuMat d_src(src);
420         cv::gpu::GpuMat dst;
421         cv::gpu::GpuMat d_buf;
422
423         TEST_CYCLE() cv::gpu::integralBuffered(d_src, dst, d_buf);
424
425         GPU_SANITY_CHECK(dst);
426     }
427     else
428     {
429         cv::Mat dst;
430
431         TEST_CYCLE() cv::integral(src, dst);
432
433         CPU_SANITY_CHECK(dst);
434     }
435 }
436
437 //////////////////////////////////////////////////////////////////////
438 // IntegralSqr
439
440 PERF_TEST_P(Sz, ImgProc_IntegralSqr,
441             GPU_TYPICAL_MAT_SIZES)
442 {
443     const cv::Size size = GetParam();
444
445     cv::Mat src(size, CV_8UC1);
446     declare.in(src, WARMUP_RNG);
447
448     if (PERF_RUN_GPU())
449     {
450         const cv::gpu::GpuMat d_src(src);
451         cv::gpu::GpuMat dst;
452
453         TEST_CYCLE() cv::gpu::sqrIntegral(d_src, dst);
454
455         GPU_SANITY_CHECK(dst);
456     }
457     else
458     {
459         FAIL_NO_CPU();
460     }
461 }
462
463 //////////////////////////////////////////////////////////////////////
464 // HistEvenC1
465
466 PERF_TEST_P(Sz_Depth, ImgProc_HistEvenC1,
467             Combine(GPU_TYPICAL_MAT_SIZES,
468                     Values(CV_8U, CV_16U, CV_16S)))
469 {
470     const cv::Size size = GET_PARAM(0);
471     const int depth = GET_PARAM(1);
472
473     cv::Mat src(size, depth);
474     declare.in(src, WARMUP_RNG);
475
476     if (PERF_RUN_GPU())
477     {
478         const cv::gpu::GpuMat d_src(src);
479         cv::gpu::GpuMat dst;
480         cv::gpu::GpuMat d_buf;
481
482         TEST_CYCLE() cv::gpu::histEven(d_src, dst, d_buf, 30, 0, 180);
483
484         GPU_SANITY_CHECK(dst);
485     }
486     else
487     {
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};
493
494         cv::Mat dst;
495
496         TEST_CYCLE() cv::calcHist(&src, 1, channels, cv::Mat(), dst, 1, histSize, ranges);
497
498         CPU_SANITY_CHECK(dst);
499     }
500 }
501
502 //////////////////////////////////////////////////////////////////////
503 // HistEvenC4
504
505 PERF_TEST_P(Sz_Depth, ImgProc_HistEvenC4,
506             Combine(GPU_TYPICAL_MAT_SIZES,
507                     Values(CV_8U, CV_16U, CV_16S)))
508 {
509     const cv::Size size = GET_PARAM(0);
510     const int depth = GET_PARAM(1);
511
512     cv::Mat src(size, CV_MAKE_TYPE(depth, 4));
513     declare.in(src, WARMUP_RNG);
514
515     int histSize[] = {30, 30, 30, 30};
516     int lowerLevel[] = {0, 0, 0, 0};
517     int upperLevel[] = {180, 180, 180, 180};
518
519     if (PERF_RUN_GPU())
520     {
521         const cv::gpu::GpuMat d_src(src);
522         cv::gpu::GpuMat d_hist[4];
523         cv::gpu::GpuMat d_buf;
524
525         TEST_CYCLE() cv::gpu::histEven(d_src, d_hist, d_buf, histSize, lowerLevel, upperLevel);
526
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);
536     }
537     else
538     {
539         FAIL_NO_CPU();
540     }
541 }
542
543 //////////////////////////////////////////////////////////////////////
544 // CalcHist
545
546 PERF_TEST_P(Sz, ImgProc_CalcHist,
547             GPU_TYPICAL_MAT_SIZES)
548 {
549     const cv::Size size = GetParam();
550
551     cv::Mat src(size, CV_8UC1);
552     declare.in(src, WARMUP_RNG);
553
554     if (PERF_RUN_GPU())
555     {
556         const cv::gpu::GpuMat d_src(src);
557         cv::gpu::GpuMat dst;
558
559         TEST_CYCLE() cv::gpu::calcHist(d_src, dst);
560
561         GPU_SANITY_CHECK(dst);
562     }
563     else
564     {
565         FAIL_NO_CPU();
566     }
567 }
568
569 //////////////////////////////////////////////////////////////////////
570 // EqualizeHist
571
572 PERF_TEST_P(Sz, ImgProc_EqualizeHist,
573             GPU_TYPICAL_MAT_SIZES)
574 {
575     const cv::Size size = GetParam();
576
577     cv::Mat src(size, CV_8UC1);
578     declare.in(src, WARMUP_RNG);
579
580     if (PERF_RUN_GPU())
581     {
582         const cv::gpu::GpuMat d_src(src);
583         cv::gpu::GpuMat dst;
584         cv::gpu::GpuMat d_hist;
585         cv::gpu::GpuMat d_buf;
586
587         TEST_CYCLE() cv::gpu::equalizeHist(d_src, dst, d_hist, d_buf);
588
589         GPU_SANITY_CHECK(dst);
590     }
591     else
592     {
593         cv::Mat dst;
594
595         TEST_CYCLE() cv::equalizeHist(src, dst);
596
597         CPU_SANITY_CHECK(dst);
598     }
599 }
600
601 DEF_PARAM_TEST(Sz_ClipLimit, cv::Size, double);
602
603 PERF_TEST_P(Sz_ClipLimit, ImgProc_CLAHE,
604             Combine(GPU_TYPICAL_MAT_SIZES,
605                     Values(0.0, 40.0)))
606 {
607     const cv::Size size = GET_PARAM(0);
608     const double clipLimit = GET_PARAM(1);
609
610     cv::Mat src(size, CV_8UC1);
611     declare.in(src, WARMUP_RNG);
612
613     if (PERF_RUN_GPU())
614     {
615         cv::Ptr<cv::gpu::CLAHE> clahe = cv::gpu::createCLAHE(clipLimit);
616         cv::gpu::GpuMat d_src(src);
617         cv::gpu::GpuMat dst;
618
619         TEST_CYCLE() clahe->apply(d_src, dst);
620
621         GPU_SANITY_CHECK(dst);
622     }
623     else
624     {
625         cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE(clipLimit);
626         cv::Mat dst;
627
628         TEST_CYCLE() clahe->apply(src, dst);
629
630         CPU_SANITY_CHECK(dst);
631     }
632 }
633
634 //////////////////////////////////////////////////////////////////////
635 // ColumnSum
636
637 PERF_TEST_P(Sz, ImgProc_ColumnSum,
638             GPU_TYPICAL_MAT_SIZES)
639 {
640     const cv::Size size = GetParam();
641
642     cv::Mat src(size, CV_32FC1);
643     declare.in(src, WARMUP_RNG);
644
645     if (PERF_RUN_GPU())
646     {
647         const cv::gpu::GpuMat d_src(src);
648         cv::gpu::GpuMat dst;
649
650         TEST_CYCLE() cv::gpu::columnSum(d_src, dst);
651
652         GPU_SANITY_CHECK(dst);
653     }
654     else
655     {
656         FAIL_NO_CPU();
657     }
658 }
659
660 //////////////////////////////////////////////////////////////////////
661 // Canny
662
663 DEF_PARAM_TEST(Image_AppertureSz_L2gradient, string, int, bool);
664
665 PERF_TEST_P(Image_AppertureSz_L2gradient, ImgProc_Canny,
666             Combine(Values("perf/800x600.png", "perf/1280x1024.png", "perf/1680x1050.png"),
667                     Values(3, 5),
668                     Bool()))
669 {
670     const string fileName = GET_PARAM(0);
671     const int apperture_size = GET_PARAM(1);
672     const bool useL2gradient = GET_PARAM(2);
673
674     const cv::Mat image = readImage(fileName, cv::IMREAD_GRAYSCALE);
675     ASSERT_FALSE(image.empty());
676
677     const double low_thresh = 50.0;
678     const double high_thresh = 100.0;
679
680     if (PERF_RUN_GPU())
681     {
682         const cv::gpu::GpuMat d_image(image);
683         cv::gpu::GpuMat dst;
684         cv::gpu::CannyBuf d_buf;
685
686         TEST_CYCLE() cv::gpu::Canny(d_image, d_buf, dst, low_thresh, high_thresh, apperture_size, useL2gradient);
687
688         GPU_SANITY_CHECK(dst);
689     }
690     else
691     {
692         cv::Mat dst;
693
694         TEST_CYCLE() cv::Canny(image, dst, low_thresh, high_thresh, apperture_size, useL2gradient);
695
696         CPU_SANITY_CHECK(dst);
697     }
698 }
699
700 //////////////////////////////////////////////////////////////////////
701 // MeanShiftFiltering
702
703 DEF_PARAM_TEST_1(Image, string);
704
705 PERF_TEST_P(Image, ImgProc_MeanShiftFiltering,
706             Values<string>("gpu/meanshift/cones.png"))
707 {
708     declare.time(300.0);
709
710     const cv::Mat img = readImage(GetParam());
711     ASSERT_FALSE(img.empty());
712
713     cv::Mat rgba;
714     cv::cvtColor(img, rgba, cv::COLOR_BGR2BGRA);
715
716     const int sp = 50;
717     const int sr = 50;
718
719     if (PERF_RUN_GPU())
720     {
721         const cv::gpu::GpuMat d_src(rgba);
722         cv::gpu::GpuMat dst;
723
724         TEST_CYCLE() cv::gpu::meanShiftFiltering(d_src, dst, sp, sr);
725
726         GPU_SANITY_CHECK(dst);
727     }
728     else
729     {
730         cv::Mat dst;
731
732         TEST_CYCLE() cv::pyrMeanShiftFiltering(img, dst, sp, sr);
733
734         CPU_SANITY_CHECK(dst);
735     }
736 }
737
738 //////////////////////////////////////////////////////////////////////
739 // MeanShiftProc
740
741 PERF_TEST_P(Image, ImgProc_MeanShiftProc,
742             Values<string>("gpu/meanshift/cones.png"))
743 {
744     declare.time(300.0);
745
746     const cv::Mat img = readImage(GetParam());
747     ASSERT_FALSE(img.empty());
748
749     cv::Mat rgba;
750     cv::cvtColor(img, rgba, cv::COLOR_BGR2BGRA);
751
752     const int sp = 50;
753     const int sr = 50;
754
755     if (PERF_RUN_GPU())
756     {
757         const cv::gpu::GpuMat d_src(rgba);
758         cv::gpu::GpuMat dstr;
759         cv::gpu::GpuMat dstsp;
760
761         TEST_CYCLE() cv::gpu::meanShiftProc(d_src, dstr, dstsp, sp, sr);
762
763         GPU_SANITY_CHECK(dstr);
764         GPU_SANITY_CHECK(dstsp);
765     }
766     else
767     {
768         FAIL_NO_CPU();
769     }
770 }
771
772 //////////////////////////////////////////////////////////////////////
773 // MeanShiftSegmentation
774
775 PERF_TEST_P(Image, ImgProc_MeanShiftSegmentation,
776             Values<string>("gpu/meanshift/cones.png"))
777 {
778     declare.time(300.0);
779
780     const cv::Mat img = readImage(GetParam());
781     ASSERT_FALSE(img.empty());
782
783     cv::Mat rgba;
784     cv::cvtColor(img, rgba, cv::COLOR_BGR2BGRA);
785
786     const int sp = 10;
787     const int sr = 10;
788     const int minsize = 20;
789
790     if (PERF_RUN_GPU())
791     {
792         const cv::gpu::GpuMat d_src(rgba);
793         cv::Mat dst;
794
795         TEST_CYCLE() cv::gpu::meanShiftSegmentation(d_src, dst, sp, sr, minsize);
796
797         GPU_SANITY_CHECK(dst);
798     }
799     else
800     {
801         FAIL_NO_CPU();
802     }
803 }
804
805 //////////////////////////////////////////////////////////////////////
806 // BlendLinear
807
808 PERF_TEST_P(Sz_Depth_Cn, ImgProc_BlendLinear,
809             Combine(GPU_TYPICAL_MAT_SIZES,
810                     Values(CV_8U, CV_32F),
811                     GPU_CHANNELS_1_3_4))
812 {
813     const cv::Size size = GET_PARAM(0);
814     const int depth = GET_PARAM(1);
815     const int channels = GET_PARAM(2);
816
817     const int type = CV_MAKE_TYPE(depth, channels);
818
819     cv::Mat img1(size, type);
820     cv::Mat img2(size, type);
821     declare.in(img1, img2, WARMUP_RNG);
822
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));
825
826     if (PERF_RUN_GPU())
827     {
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);
832         cv::gpu::GpuMat dst;
833
834         TEST_CYCLE() cv::gpu::blendLinear(d_img1, d_img2, d_weights1, d_weights2, dst);
835
836         GPU_SANITY_CHECK(dst);
837     }
838     else
839     {
840         FAIL_NO_CPU();
841     }
842 }
843
844 //////////////////////////////////////////////////////////////////////
845 // Convolve
846
847 DEF_PARAM_TEST(Sz_KernelSz_Ccorr, cv::Size, int, bool);
848
849 PERF_TEST_P(Sz_KernelSz_Ccorr, ImgProc_Convolve,
850             Combine(GPU_TYPICAL_MAT_SIZES,
851                     Values(17, 27, 32, 64),
852                     Bool()))
853 {
854     declare.time(10.0);
855
856     const cv::Size size = GET_PARAM(0);
857     const int templ_size = GET_PARAM(1);
858     const bool ccorr = GET_PARAM(2);
859
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);
863
864     if (PERF_RUN_GPU())
865     {
866         cv::gpu::GpuMat d_image = cv::gpu::createContinuous(size, CV_32FC1);
867         d_image.upload(image);
868
869         cv::gpu::GpuMat d_templ = cv::gpu::createContinuous(templ_size, templ_size, CV_32FC1);
870         d_templ.upload(templ);
871
872         cv::gpu::GpuMat dst;
873         cv::gpu::ConvolveBuf d_buf;
874
875         TEST_CYCLE() cv::gpu::convolve(d_image, d_templ, dst, ccorr, d_buf);
876
877         GPU_SANITY_CHECK(dst);
878     }
879     else
880     {
881         if (ccorr)
882             FAIL_NO_CPU();
883
884         cv::Mat dst;
885
886         TEST_CYCLE() cv::filter2D(image, dst, image.depth(), templ);
887
888         CPU_SANITY_CHECK(dst);
889     }
890 }
891
892 ////////////////////////////////////////////////////////////////////////////////
893 // MatchTemplate8U
894
895 CV_ENUM(TemplateMethod, TM_SQDIFF, TM_SQDIFF_NORMED, TM_CCORR, TM_CCORR_NORMED, TM_CCOEFF, TM_CCOEFF_NORMED)
896
897 DEF_PARAM_TEST(Sz_TemplateSz_Cn_Method, cv::Size, cv::Size, MatCn, TemplateMethod);
898
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)),
902                     GPU_CHANNELS_1_3_4,
903                     TemplateMethod::all()))
904 {
905     declare.time(300.0);
906
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);
911
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);
915
916     if (PERF_RUN_GPU())
917     {
918         const cv::gpu::GpuMat d_image(image);
919         const cv::gpu::GpuMat d_templ(templ);
920         cv::gpu::GpuMat dst;
921
922         TEST_CYCLE() cv::gpu::matchTemplate(d_image, d_templ, dst, method);
923
924         GPU_SANITY_CHECK(dst, 1e-5, ERROR_RELATIVE);
925     }
926     else
927     {
928         cv::Mat dst;
929
930         TEST_CYCLE() cv::matchTemplate(image, templ, dst, method);
931
932         CPU_SANITY_CHECK(dst);
933     }
934 };
935
936 ////////////////////////////////////////////////////////////////////////////////
937 // MatchTemplate32F
938
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)),
942                     GPU_CHANNELS_1_3_4,
943                     Values(TemplateMethod(cv::TM_SQDIFF), TemplateMethod(cv::TM_CCORR))))
944 {
945     declare.time(300.0);
946
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);
951
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);
955
956     if (PERF_RUN_GPU())
957     {
958         const cv::gpu::GpuMat d_image(image);
959         const cv::gpu::GpuMat d_templ(templ);
960         cv::gpu::GpuMat dst;
961
962         TEST_CYCLE() cv::gpu::matchTemplate(d_image, d_templ, dst, method);
963
964         GPU_SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
965     }
966     else
967     {
968         cv::Mat dst;
969
970         TEST_CYCLE() cv::matchTemplate(image, templ, dst, method);
971
972         CPU_SANITY_CHECK(dst);
973     }
974 };
975
976 //////////////////////////////////////////////////////////////////////
977 // MulSpectrums
978
979 CV_FLAGS(DftFlags, 0, DFT_INVERSE, DFT_SCALE, DFT_ROWS, DFT_COMPLEX_OUTPUT, DFT_REAL_OUTPUT)
980
981 DEF_PARAM_TEST(Sz_Flags, cv::Size, DftFlags);
982
983 PERF_TEST_P(Sz_Flags, ImgProc_MulSpectrums,
984             Combine(GPU_TYPICAL_MAT_SIZES,
985                     Values(0, DftFlags(cv::DFT_ROWS))))
986 {
987     const cv::Size size = GET_PARAM(0);
988     const int flag = GET_PARAM(1);
989
990     cv::Mat a(size, CV_32FC2);
991     cv::Mat b(size, CV_32FC2);
992     declare.in(a, b, WARMUP_RNG);
993
994     if (PERF_RUN_GPU())
995     {
996         const cv::gpu::GpuMat d_a(a);
997         const cv::gpu::GpuMat d_b(b);
998         cv::gpu::GpuMat dst;
999
1000         TEST_CYCLE() cv::gpu::mulSpectrums(d_a, d_b, dst, flag);
1001
1002         GPU_SANITY_CHECK(dst);
1003     }
1004     else
1005     {
1006         cv::Mat dst;
1007
1008         TEST_CYCLE() cv::mulSpectrums(a, b, dst, flag);
1009
1010         CPU_SANITY_CHECK(dst);
1011     }
1012 }
1013
1014 //////////////////////////////////////////////////////////////////////
1015 // MulAndScaleSpectrums
1016
1017 PERF_TEST_P(Sz, ImgProc_MulAndScaleSpectrums,
1018             GPU_TYPICAL_MAT_SIZES)
1019 {
1020     const cv::Size size = GetParam();
1021
1022     const float scale = 1.f / size.area();
1023
1024     cv::Mat src1(size, CV_32FC2);
1025     cv::Mat src2(size, CV_32FC2);
1026     declare.in(src1,src2, WARMUP_RNG);
1027
1028     if (PERF_RUN_GPU())
1029     {
1030         const cv::gpu::GpuMat d_src1(src1);
1031         const cv::gpu::GpuMat d_src2(src2);
1032         cv::gpu::GpuMat dst;
1033
1034         TEST_CYCLE() cv::gpu::mulAndScaleSpectrums(d_src1, d_src2, dst, cv::DFT_ROWS, scale, false);
1035
1036         GPU_SANITY_CHECK(dst);
1037     }
1038     else
1039     {
1040         FAIL_NO_CPU();
1041     }
1042 }
1043
1044 //////////////////////////////////////////////////////////////////////
1045 // Dft
1046
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))))
1050 {
1051     declare.time(10.0);
1052
1053     const cv::Size size = GET_PARAM(0);
1054     const int flag = GET_PARAM(1);
1055
1056     cv::Mat src(size, CV_32FC2);
1057     declare.in(src, WARMUP_RNG);
1058
1059     if (PERF_RUN_GPU())
1060     {
1061         const cv::gpu::GpuMat d_src(src);
1062         cv::gpu::GpuMat dst;
1063
1064         TEST_CYCLE() cv::gpu::dft(d_src, dst, size, flag);
1065
1066         GPU_SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
1067     }
1068     else
1069     {
1070         cv::Mat dst;
1071
1072         TEST_CYCLE() cv::dft(src, dst, flag);
1073
1074         CPU_SANITY_CHECK(dst);
1075     }
1076 }
1077
1078 //////////////////////////////////////////////////////////////////////
1079 // CornerHarris
1080
1081 DEF_PARAM_TEST(Image_Type_Border_BlockSz_ApertureSz, string, MatType, BorderMode, int, int);
1082
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)),
1087                     Values(3, 5, 7),
1088                     Values(0, 3, 5, 7)))
1089 {
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);
1095
1096     cv::Mat img = readImage(fileName, cv::IMREAD_GRAYSCALE);
1097     ASSERT_FALSE(img.empty());
1098
1099     img.convertTo(img, type, type == CV_32F ? 1.0 / 255.0 : 1.0);
1100
1101     const double k = 0.5;
1102
1103     if (PERF_RUN_GPU())
1104     {
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;
1110
1111         TEST_CYCLE() cv::gpu::cornerHarris(d_img, dst, d_Dx, d_Dy, d_buf, blockSize, apertureSize, k, borderMode);
1112
1113         GPU_SANITY_CHECK(dst, 1e-4);
1114     }
1115     else
1116     {
1117         cv::Mat dst;
1118
1119         TEST_CYCLE() cv::cornerHarris(img, dst, blockSize, apertureSize, k, borderMode);
1120
1121         CPU_SANITY_CHECK(dst);
1122     }
1123 }
1124
1125 //////////////////////////////////////////////////////////////////////
1126 // CornerMinEigenVal
1127
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)),
1132                     Values(3, 5, 7),
1133                     Values(0, 3, 5, 7)))
1134 {
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);
1140
1141     cv::Mat img = readImage(fileName, cv::IMREAD_GRAYSCALE);
1142     ASSERT_FALSE(img.empty());
1143
1144     img.convertTo(img, type, type == CV_32F ? 1.0 / 255.0 : 1.0);
1145
1146     if (PERF_RUN_GPU())
1147     {
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;
1153
1154         TEST_CYCLE() cv::gpu::cornerMinEigenVal(d_img, dst, d_Dx, d_Dy, d_buf, blockSize, apertureSize, borderMode);
1155
1156         GPU_SANITY_CHECK(dst, 1e-4);
1157     }
1158     else
1159     {
1160         cv::Mat dst;
1161
1162         TEST_CYCLE() cv::cornerMinEigenVal(img, dst, blockSize, apertureSize, borderMode);
1163
1164         CPU_SANITY_CHECK(dst);
1165     }
1166 }
1167
1168 //////////////////////////////////////////////////////////////////////
1169 // BuildWarpPlaneMaps
1170
1171 PERF_TEST_P(Sz, ImgProc_BuildWarpPlaneMaps,
1172             GPU_TYPICAL_MAT_SIZES)
1173 {
1174     const cv::Size size = GetParam();
1175
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);
1179
1180     if (PERF_RUN_GPU())
1181     {
1182         cv::gpu::GpuMat map_x;
1183         cv::gpu::GpuMat map_y;
1184
1185         TEST_CYCLE() cv::gpu::buildWarpPlaneMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, T, 1.0, map_x, map_y);
1186
1187         GPU_SANITY_CHECK(map_x);
1188         GPU_SANITY_CHECK(map_y);
1189     }
1190     else
1191     {
1192         FAIL_NO_CPU();
1193     }
1194 }
1195
1196 //////////////////////////////////////////////////////////////////////
1197 // BuildWarpCylindricalMaps
1198
1199 PERF_TEST_P(Sz, ImgProc_BuildWarpCylindricalMaps,
1200             GPU_TYPICAL_MAT_SIZES)
1201 {
1202     const cv::Size size = GetParam();
1203
1204     const cv::Mat K = cv::Mat::eye(3, 3, CV_32FC1);
1205     const cv::Mat R = cv::Mat::ones(3, 3, CV_32FC1);
1206
1207     if (PERF_RUN_GPU())
1208     {
1209         cv::gpu::GpuMat map_x;
1210         cv::gpu::GpuMat map_y;
1211
1212         TEST_CYCLE() cv::gpu::buildWarpCylindricalMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, 1.0, map_x, map_y);
1213
1214         GPU_SANITY_CHECK(map_x);
1215         GPU_SANITY_CHECK(map_y);
1216     }
1217     else
1218     {
1219         FAIL_NO_CPU();
1220     }
1221 }
1222
1223 //////////////////////////////////////////////////////////////////////
1224 // BuildWarpSphericalMaps
1225
1226 PERF_TEST_P(Sz, ImgProc_BuildWarpSphericalMaps,
1227             GPU_TYPICAL_MAT_SIZES)
1228 {
1229     const cv::Size size = GetParam();
1230
1231     const cv::Mat K = cv::Mat::eye(3, 3, CV_32FC1);
1232     const cv::Mat R = cv::Mat::ones(3, 3, CV_32FC1);
1233
1234     if (PERF_RUN_GPU())
1235     {
1236         cv::gpu::GpuMat map_x;
1237         cv::gpu::GpuMat map_y;
1238
1239         TEST_CYCLE() cv::gpu::buildWarpSphericalMaps(size, cv::Rect(0, 0, size.width, size.height), K, R, 1.0, map_x, map_y);
1240
1241         GPU_SANITY_CHECK(map_x);
1242         GPU_SANITY_CHECK(map_y);
1243     }
1244     else
1245     {
1246         FAIL_NO_CPU();
1247     }
1248 }
1249
1250 //////////////////////////////////////////////////////////////////////
1251 // Rotate
1252
1253 DEF_PARAM_TEST(Sz_Depth_Cn_Inter, cv::Size, MatDepth, MatCn, Interpolation);
1254
1255 PERF_TEST_P(Sz_Depth_Cn_Inter, ImgProc_Rotate,
1256             Combine(GPU_TYPICAL_MAT_SIZES,
1257                     Values(CV_8U, CV_16U, CV_32F),
1258                     GPU_CHANNELS_1_3_4,
1259                     Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC))))
1260 {
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);
1265
1266     const int type = CV_MAKE_TYPE(depth, channels);
1267
1268     cv::Mat src(size, type);
1269     declare.in(src, WARMUP_RNG);
1270
1271     if (PERF_RUN_GPU())
1272     {
1273         const cv::gpu::GpuMat d_src(src);
1274         cv::gpu::GpuMat dst;
1275
1276         TEST_CYCLE() cv::gpu::rotate(d_src, dst, size, 30.0, 0, 0, interpolation);
1277
1278         GPU_SANITY_CHECK(dst, 1e-3, ERROR_RELATIVE);
1279     }
1280     else
1281     {
1282         FAIL_NO_CPU();
1283     }
1284 }
1285
1286 //////////////////////////////////////////////////////////////////////
1287 // PyrDown
1288
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))
1293 {
1294     const cv::Size size = GET_PARAM(0);
1295     const int depth = GET_PARAM(1);
1296     const int channels = GET_PARAM(2);
1297
1298     const int type = CV_MAKE_TYPE(depth, channels);
1299
1300     cv::Mat src(size, type);
1301     declare.in(src, WARMUP_RNG);
1302
1303     if (PERF_RUN_GPU())
1304     {
1305         const cv::gpu::GpuMat d_src(src);
1306         cv::gpu::GpuMat dst;
1307
1308         TEST_CYCLE() cv::gpu::pyrDown(d_src, dst);
1309
1310         GPU_SANITY_CHECK(dst);
1311     }
1312     else
1313     {
1314         cv::Mat dst;
1315
1316         TEST_CYCLE() cv::pyrDown(src, dst);
1317
1318         CPU_SANITY_CHECK(dst);
1319     }
1320 }
1321
1322 //////////////////////////////////////////////////////////////////////
1323 // PyrUp
1324
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))
1329 {
1330     const cv::Size size = GET_PARAM(0);
1331     const int depth = GET_PARAM(1);
1332     const int channels = GET_PARAM(2);
1333
1334     const int type = CV_MAKE_TYPE(depth, channels);
1335
1336     cv::Mat src(size, type);
1337     declare.in(src, WARMUP_RNG);
1338
1339     if (PERF_RUN_GPU())
1340     {
1341         const cv::gpu::GpuMat d_src(src);
1342         cv::gpu::GpuMat dst;
1343
1344         TEST_CYCLE() cv::gpu::pyrUp(d_src, dst);
1345
1346         GPU_SANITY_CHECK(dst);
1347     }
1348     else
1349     {
1350         cv::Mat dst;
1351
1352         TEST_CYCLE() cv::pyrUp(src, dst);
1353
1354         CPU_SANITY_CHECK(dst);
1355     }
1356 }
1357
1358 //////////////////////////////////////////////////////////////////////
1359 // CvtColor
1360
1361 DEF_PARAM_TEST(Sz_Depth_Code, cv::Size, MatDepth, CvtColorInfo);
1362
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))))
1387 {
1388     const cv::Size size = GET_PARAM(0);
1389     const int depth = GET_PARAM(1);
1390     const CvtColorInfo info = GET_PARAM(2);
1391
1392     cv::Mat src(size, CV_MAKETYPE(depth, info.scn));
1393     cv::randu(src, 0, depth == CV_8U ? 255.0 : 1.0);
1394
1395     if (PERF_RUN_GPU())
1396     {
1397         const cv::gpu::GpuMat d_src(src);
1398         cv::gpu::GpuMat dst;
1399
1400         TEST_CYCLE() cv::gpu::cvtColor(d_src, dst, info.code, info.dcn);
1401
1402         GPU_SANITY_CHECK(dst, 1e-4);
1403     }
1404     else
1405     {
1406         cv::Mat dst;
1407
1408         TEST_CYCLE() cv::cvtColor(src, dst, info.code, info.dcn);
1409
1410         CPU_SANITY_CHECK(dst);
1411     }
1412 }
1413
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),
1421
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))))
1426 {
1427     const cv::Size size = GET_PARAM(0);
1428     const int depth = GET_PARAM(1);
1429     const CvtColorInfo info = GET_PARAM(2);
1430
1431     cv::Mat src(size, CV_MAKETYPE(depth, info.scn));
1432     declare.in(src, WARMUP_RNG);
1433
1434     if (PERF_RUN_GPU())
1435     {
1436         const cv::gpu::GpuMat d_src(src);
1437         cv::gpu::GpuMat dst;
1438
1439         TEST_CYCLE() cv::gpu::cvtColor(d_src, dst, info.code, info.dcn);
1440
1441         GPU_SANITY_CHECK(dst);
1442     }
1443     else
1444     {
1445         cv::Mat dst;
1446
1447         TEST_CYCLE() cv::cvtColor(src, dst, info.code, info.dcn);
1448
1449         CPU_SANITY_CHECK(dst);
1450     }
1451 }
1452
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)
1458
1459 DEF_PARAM_TEST(Sz_Code, cv::Size, DemosaicingCode);
1460
1461 PERF_TEST_P(Sz_Code, ImgProc_Demosaicing,
1462             Combine(GPU_TYPICAL_MAT_SIZES,
1463                     DemosaicingCode::all()))
1464 {
1465     const cv::Size size = GET_PARAM(0);
1466     const int code = GET_PARAM(1);
1467
1468     cv::Mat src(size, CV_8UC1);
1469     declare.in(src, WARMUP_RNG);
1470
1471     if (PERF_RUN_GPU())
1472     {
1473         const cv::gpu::GpuMat d_src(src);
1474         cv::gpu::GpuMat dst;
1475
1476         TEST_CYCLE() cv::gpu::demosaicing(d_src, dst, code);
1477
1478         GPU_SANITY_CHECK(dst);
1479     }
1480     else
1481     {
1482         if (code >= cv::COLOR_COLORCVT_MAX)
1483         {
1484             FAIL_NO_CPU();
1485         }
1486         else
1487         {
1488             cv::Mat dst;
1489
1490             TEST_CYCLE() cv::cvtColor(src, dst, code);
1491
1492             CPU_SANITY_CHECK(dst);
1493         }
1494     }
1495 }
1496
1497 //////////////////////////////////////////////////////////////////////
1498 // SwapChannels
1499
1500 PERF_TEST_P(Sz, ImgProc_SwapChannels,
1501             GPU_TYPICAL_MAT_SIZES)
1502 {
1503     const cv::Size size = GetParam();
1504
1505     cv::Mat src(size, CV_8UC4);
1506     declare.in(src, WARMUP_RNG);
1507
1508     const int dstOrder[] = {2, 1, 0, 3};
1509
1510     if (PERF_RUN_GPU())
1511     {
1512         cv::gpu::GpuMat dst(src);
1513
1514         TEST_CYCLE() cv::gpu::swapChannels(dst, dstOrder);
1515
1516         GPU_SANITY_CHECK(dst);
1517     }
1518     else
1519     {
1520         FAIL_NO_CPU();
1521     }
1522 }
1523
1524 //////////////////////////////////////////////////////////////////////
1525 // AlphaComp
1526
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)
1528
1529 DEF_PARAM_TEST(Sz_Type_Op, cv::Size, MatType, AlphaOp);
1530
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),
1534                     AlphaOp::all()))
1535 {
1536     const cv::Size size = GET_PARAM(0);
1537     const int type = GET_PARAM(1);
1538     const int alpha_op = GET_PARAM(2);
1539
1540     cv::Mat img1(size, type);
1541     cv::Mat img2(size, type);
1542     declare.in(img1, img2, WARMUP_RNG);
1543
1544     if (PERF_RUN_GPU())
1545     {
1546         const cv::gpu::GpuMat d_img1(img1);
1547         const cv::gpu::GpuMat d_img2(img2);
1548         cv::gpu::GpuMat dst;
1549
1550         TEST_CYCLE() cv::gpu::alphaComp(d_img1, d_img2, dst, alpha_op);
1551
1552         GPU_SANITY_CHECK(dst, 1e-3, ERROR_RELATIVE);
1553     }
1554     else
1555     {
1556         FAIL_NO_CPU();
1557     }
1558 }
1559
1560 //////////////////////////////////////////////////////////////////////
1561 // ImagePyramidBuild
1562
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))
1567 {
1568     const cv::Size size = GET_PARAM(0);
1569     const int depth = GET_PARAM(1);
1570     const int channels = GET_PARAM(2);
1571
1572     const int type = CV_MAKE_TYPE(depth, channels);
1573
1574     cv::Mat src(size, type);
1575     declare.in(src, WARMUP_RNG);
1576
1577     const int nLayers = 5;
1578     const cv::Size dstSize(size.width / 2 + 10, size.height / 2 + 10);
1579
1580     if (PERF_RUN_GPU())
1581     {
1582         const cv::gpu::GpuMat d_src(src);
1583
1584         cv::gpu::ImagePyramid d_pyr;
1585
1586         TEST_CYCLE() d_pyr.build(d_src, nLayers);
1587
1588         cv::gpu::GpuMat dst;
1589         d_pyr.getLayer(dst, dstSize);
1590
1591         GPU_SANITY_CHECK(dst);
1592     }
1593     else
1594     {
1595         FAIL_NO_CPU();
1596     }
1597 }
1598
1599 //////////////////////////////////////////////////////////////////////
1600 // ImagePyramidGetLayer
1601
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))
1606 {
1607     const cv::Size size = GET_PARAM(0);
1608     const int depth = GET_PARAM(1);
1609     const int channels = GET_PARAM(2);
1610
1611     const int type = CV_MAKE_TYPE(depth, channels);
1612
1613     cv::Mat src(size, type);
1614     declare.in(src, WARMUP_RNG);
1615
1616     const int nLayers = 3;
1617     const cv::Size dstSize(size.width / 2 + 10, size.height / 2 + 10);
1618
1619     if (PERF_RUN_GPU())
1620     {
1621         const cv::gpu::GpuMat d_src(src);
1622         cv::gpu::GpuMat dst;
1623
1624         cv::gpu::ImagePyramid d_pyr(d_src, nLayers);
1625
1626         TEST_CYCLE() d_pyr.getLayer(dst, dstSize);
1627
1628         GPU_SANITY_CHECK(dst);
1629     }
1630     else
1631     {
1632         FAIL_NO_CPU();
1633     }
1634 }
1635
1636 //////////////////////////////////////////////////////////////////////
1637 // HoughLines
1638
1639 namespace
1640 {
1641     struct Vec4iComparator
1642     {
1643         bool operator()(const cv::Vec4i& a, const cv::Vec4i b) const
1644         {
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];
1649         }
1650     };
1651     struct Vec3fComparator
1652     {
1653         bool operator()(const cv::Vec3f& a, const cv::Vec3f b) const
1654         {
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];
1658         }
1659     };
1660     struct Vec2fComparator
1661     {
1662         bool operator()(const cv::Vec2f& a, const cv::Vec2f b) const
1663         {
1664             if(a[0] != b[0]) return a[0] < b[0];
1665             else return a[1] < b[1];
1666         }
1667     };
1668 }
1669
1670 PERF_TEST_P(Sz, ImgProc_HoughLines,
1671             GPU_TYPICAL_MAT_SIZES)
1672 {
1673     declare.time(30.0);
1674
1675     const cv::Size size = GetParam();
1676
1677     const float rho = 1.0f;
1678     const float theta = static_cast<float>(CV_PI / 180.0);
1679     const int threshold = 300;
1680
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);
1688
1689     if (PERF_RUN_GPU())
1690     {
1691         const cv::gpu::GpuMat d_src(src);
1692         cv::gpu::GpuMat d_lines;
1693         cv::gpu::HoughLinesBuf d_buf;
1694
1695         TEST_CYCLE() cv::gpu::HoughLines(d_src, d_lines, d_buf, rho, theta, threshold);
1696
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);
1702     }
1703     else
1704     {
1705         std::vector<cv::Vec2f> cpu_lines;
1706
1707         TEST_CYCLE() cv::HoughLines(src, cpu_lines, rho, theta, threshold);
1708
1709         SANITY_CHECK(cpu_lines);
1710     }
1711 }
1712
1713 //////////////////////////////////////////////////////////////////////
1714 // HoughLinesP
1715
1716 DEF_PARAM_TEST_1(Image, std::string);
1717
1718 PERF_TEST_P(Image, ImgProc_HoughLinesP,
1719             testing::Values("cv/shared/pic5.png", "stitching/a1.png"))
1720 {
1721     declare.time(30.0);
1722
1723     const std::string fileName = getDataPath(GetParam());
1724
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;
1730
1731     const cv::Mat image = cv::imread(fileName, cv::IMREAD_GRAYSCALE);
1732     ASSERT_FALSE(image.empty());
1733
1734     cv::Mat mask;
1735     cv::Canny(image, mask, 50, 100);
1736
1737     if (PERF_RUN_GPU())
1738     {
1739         const cv::gpu::GpuMat d_mask(mask);
1740         cv::gpu::GpuMat d_lines;
1741         cv::gpu::HoughLinesBuf d_buf;
1742
1743         TEST_CYCLE() cv::gpu::HoughLinesP(d_mask, d_lines, d_buf, rho, theta, minLineLenght, maxLineGap);
1744
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);
1750     }
1751     else
1752     {
1753         std::vector<cv::Vec4i> cpu_lines;
1754
1755         TEST_CYCLE() cv::HoughLinesP(mask, cpu_lines, rho, theta, threshold, minLineLenght, maxLineGap);
1756
1757         SANITY_CHECK(cpu_lines);
1758     }
1759 }
1760
1761 //////////////////////////////////////////////////////////////////////
1762 // HoughCircles
1763
1764 DEF_PARAM_TEST(Sz_Dp_MinDist, cv::Size, float, float);
1765
1766 PERF_TEST_P(Sz_Dp_MinDist, ImgProc_HoughCircles,
1767             Combine(GPU_TYPICAL_MAT_SIZES,
1768                     Values(1.0f, 2.0f, 4.0f),
1769                     Values(1.0f)))
1770 {
1771     declare.time(30.0);
1772
1773     const cv::Size size = GET_PARAM(0);
1774     const float dp = GET_PARAM(1);
1775     const float minDist = GET_PARAM(2);
1776
1777     const int minRadius = 10;
1778     const int maxRadius = 30;
1779     const int cannyThreshold = 100;
1780     const int votesThreshold = 15;
1781
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);
1786
1787     if (PERF_RUN_GPU())
1788     {
1789         const cv::gpu::GpuMat d_src(src);
1790         cv::gpu::GpuMat d_circles;
1791         cv::gpu::HoughCirclesBuf d_buf;
1792
1793         TEST_CYCLE() cv::gpu::HoughCircles(d_src, d_circles, d_buf, CV_HOUGH_GRADIENT, dp, minDist, cannyThreshold, votesThreshold, minRadius, maxRadius);
1794
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);
1800     }
1801     else
1802     {
1803         std::vector<cv::Vec3f> cpu_circles;
1804
1805         TEST_CYCLE() cv::HoughCircles(src, cpu_circles, CV_HOUGH_GRADIENT, dp, minDist, cannyThreshold, votesThreshold, minRadius, maxRadius);
1806
1807         SANITY_CHECK(cpu_circles);
1808     }
1809 }
1810
1811 //////////////////////////////////////////////////////////////////////
1812 // GeneralizedHough
1813
1814 CV_FLAGS(GHMethod, GHT_POSITION, GHT_SCALE, GHT_ROTATION);
1815
1816 DEF_PARAM_TEST(Method_Sz, GHMethod, cv::Size);
1817
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))
1821 {
1822     declare.time(10);
1823
1824     const int method = GET_PARAM(0);
1825     const cv::Size imageSize = GET_PARAM(1);
1826
1827     const cv::Mat templ = readImage("cv/shared/templ.png", cv::IMREAD_GRAYSCALE);
1828     ASSERT_FALSE(templ.empty());
1829
1830     cv::Mat image(imageSize, CV_8UC1, cv::Scalar::all(0));
1831     templ.copyTo(image(cv::Rect(50, 50, templ.cols, templ.rows)));
1832
1833     cv::RNG rng(123456789);
1834     const int objCount = rng.uniform(5, 15);
1835     for (int i = 0; i < objCount; ++i)
1836     {
1837         double scale = rng.uniform(0.7, 1.3);
1838         bool rotate = 1 == rng.uniform(0, 2);
1839
1840         cv::Mat obj;
1841         cv::resize(templ, obj, cv::Size(), scale, scale);
1842         if (rotate)
1843             obj = obj.t();
1844
1845         cv::Point pos;
1846
1847         pos.x = rng.uniform(0, image.cols - obj.cols);
1848         pos.y = rng.uniform(0, image.rows - obj.rows);
1849
1850         cv::Mat roi = image(cv::Rect(pos, obj.size()));
1851         cv::add(roi, obj, roi);
1852     }
1853
1854     cv::Mat edges;
1855     cv::Canny(image, edges, 50, 100);
1856
1857     cv::Mat dx, dy;
1858     cv::Sobel(image, dx, CV_32F, 1, 0);
1859     cv::Sobel(image, dy, CV_32F, 0, 1);
1860
1861     if (PERF_RUN_GPU())
1862     {
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;
1867
1868         cv::Ptr<cv::gpu::GeneralizedHough_GPU> d_hough = cv::gpu::GeneralizedHough_GPU::create(method);
1869         if (method & cv::GHT_ROTATION)
1870         {
1871             d_hough->set("maxAngle", 90.0);
1872             d_hough->set("angleStep", 2.0);
1873         }
1874
1875         d_hough->setTemplate(cv::gpu::GpuMat(templ));
1876
1877         TEST_CYCLE() d_hough->detect(d_edges, d_dx, d_dy, posAndVotes);
1878
1879         const cv::gpu::GpuMat positions(1, posAndVotes.cols, CV_32FC4, posAndVotes.data);
1880         GPU_SANITY_CHECK(positions);
1881     }
1882     else
1883     {
1884         cv::Mat positions;
1885
1886         cv::Ptr<cv::GeneralizedHough> hough = cv::GeneralizedHough::create(method);
1887         if (method & cv::GHT_ROTATION)
1888         {
1889             hough->set("maxAngle", 90.0);
1890             hough->set("angleStep", 2.0);
1891         }
1892
1893         hough->setTemplate(templ);
1894
1895         TEST_CYCLE() hough->detect(edges, dx, dy, positions);
1896
1897         CPU_SANITY_CHECK(positions);
1898     }
1899 }