Merge remote-tracking branch 'origin/2.4' into merge-2.4
[profile/ivi/opencv.git] / modules / ocl / 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) 2010-2012, Multicoreware, Inc., all rights reserved.
14 // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
16 //
17 // @Authors
18 //    Fangfang Bai, fangfang@multicorewareinc.com
19 //    Jin Ma,       jin@multicorewareinc.com
20 //
21 // Redistribution and use in source and binary forms, with or without modification,
22 // are permitted provided that the following conditions are met:
23 //
24 //   * Redistribution's of source code must retain the above copyright notice,
25 //     this list of conditions and the following disclaimer.
26 //
27 //   * Redistribution's in binary form must reproduce the above copyright notice,
28 //     this list of conditions and the following disclaimer in the documentation
29 //     and/or other materials provided with the distribution.
30 //
31 //   * The name of the copyright holders may not be used to endorse or promote products
32 //     derived from this software without specific prior written permission.
33 //
34 // This software is provided by the copyright holders and contributors as is and
35 // any express or implied warranties, including, but not limited to, the implied
36 // warranties of merchantability and fitness for a particular purpose are disclaimed.
37 // In no event shall the Intel Corporation or contributors be liable for any direct,
38 // indirect, incidental, special, exemplary, or consequential damages
39 // (including, but not limited to, procurement of substitute goods or services;
40 // loss of use, data, or profits; or business interruption) however caused
41 // and on any theory of liability, whether in contract, strict liability,
42 // or tort (including negligence or otherwise) arising in any way out of
43 // the use of this software, even if advised of the possibility of such damage.
44 //
45 //M*/
46 #include "perf_precomp.hpp"
47
48 using namespace perf;
49 using std::tr1::tuple;
50 using std::tr1::get;
51
52 ///////////// equalizeHist ////////////////////////
53
54 typedef TestBaseWithParam<Size> equalizeHistFixture;
55
56 PERF_TEST_P(equalizeHistFixture, equalizeHist, OCL_TYPICAL_MAT_SIZES)
57 {
58     const Size srcSize = GetParam();
59     const double eps = 1 + DBL_EPSILON;
60
61     Mat src(srcSize, CV_8UC1), dst(srcSize, CV_8UC1);
62     declare.in(src, WARMUP_RNG).out(dst);
63
64     if (RUN_OCL_IMPL)
65     {
66         ocl::oclMat oclSrc(src), oclDst(srcSize, src.type());
67
68         OCL_TEST_CYCLE() cv::ocl::equalizeHist(oclSrc, oclDst);
69
70         oclDst.download(dst);
71
72         SANITY_CHECK(dst, eps);
73     }
74     else if (RUN_PLAIN_IMPL)
75     {
76         TEST_CYCLE() cv::equalizeHist(src, dst);
77
78         SANITY_CHECK(dst, eps);
79     }
80     else
81         OCL_PERF_ELSE
82 }
83
84 /////////// CopyMakeBorder //////////////////////
85
86 CV_ENUM(Border, BORDER_CONSTANT, BORDER_REPLICATE, BORDER_REFLECT,
87         BORDER_WRAP, BORDER_REFLECT_101)
88
89 typedef tuple<Size, MatType, Border> CopyMakeBorderParamType;
90 typedef TestBaseWithParam<CopyMakeBorderParamType> CopyMakeBorderFixture;
91
92 PERF_TEST_P(CopyMakeBorderFixture, CopyMakeBorder,
93             ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
94                                OCL_PERF_ENUM(CV_8UC1, CV_8UC4),
95                                Border::all()))
96 {
97     const CopyMakeBorderParamType params = GetParam();
98     const Size srcSize = get<0>(params);
99     const int type = get<1>(params), borderType = get<2>(params);
100
101     Mat src(srcSize, type), dst;
102     const Size dstSize = srcSize + Size(12, 12);
103     dst.create(dstSize, type);
104     declare.in(src, WARMUP_RNG).out(dst);
105
106     if (RUN_OCL_IMPL)
107     {
108         ocl::oclMat oclSrc(src), oclDst(dstSize, type);
109
110         OCL_TEST_CYCLE() cv::ocl::copyMakeBorder(oclSrc, oclDst, 7, 5, 5, 7, borderType, cv::Scalar(1.0));
111
112         oclDst.download(dst);
113
114         SANITY_CHECK(dst);
115     }
116     else if (RUN_PLAIN_IMPL)
117     {
118         TEST_CYCLE() cv::copyMakeBorder(src, dst, 7, 5, 5, 7, borderType, cv::Scalar(1.0));
119
120         SANITY_CHECK(dst);
121     }
122     else
123         OCL_PERF_ELSE
124 }
125
126 ///////////// cornerMinEigenVal ////////////////////////
127
128 typedef Size_MatType cornerMinEigenValFixture;
129
130 PERF_TEST_P(cornerMinEigenValFixture, cornerMinEigenVal,
131             ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
132                                OCL_PERF_ENUM(CV_8UC1, CV_32FC1)))
133 {
134     const Size_MatType_t params = GetParam();
135     const Size srcSize = get<0>(params);
136     const int type = get<1>(params), borderType = BORDER_REFLECT;
137     const int blockSize = 7, apertureSize = 1 + 2 * 3;
138
139     Mat src(srcSize, type), dst(srcSize, CV_32FC1);
140     declare.in(src, WARMUP_RNG).out(dst)
141             .time(srcSize == OCL_SIZE_4000 ? 20 : srcSize == OCL_SIZE_2000 ? 5 : 3);
142
143     const int depth = CV_MAT_DEPTH(type);
144     const ERROR_TYPE errorType = depth == CV_8U ? ERROR_ABSOLUTE : ERROR_RELATIVE;
145
146     if (RUN_OCL_IMPL)
147     {
148         ocl::oclMat oclSrc(src), oclDst(srcSize, CV_32FC1);
149
150         OCL_TEST_CYCLE() cv::ocl::cornerMinEigenVal(oclSrc, oclDst, blockSize, apertureSize, borderType);
151
152         oclDst.download(dst);
153
154         SANITY_CHECK(dst, 1e-6, errorType);
155     }
156     else if (RUN_PLAIN_IMPL)
157     {
158         TEST_CYCLE() cv::cornerMinEigenVal(src, dst, blockSize, apertureSize, borderType);
159
160         SANITY_CHECK(dst, 1e-6, errorType);
161     }
162     else
163         OCL_PERF_ELSE
164 }
165
166 ///////////// cornerHarris ////////////////////////
167
168 typedef Size_MatType cornerHarrisFixture;
169
170 PERF_TEST_P(cornerHarrisFixture, cornerHarris,
171             ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
172                                OCL_PERF_ENUM(CV_8UC1, CV_32FC1)))
173 {
174     const Size_MatType_t params = GetParam();
175     const Size srcSize = get<0>(params);
176     const int type = get<1>(params), borderType = BORDER_REFLECT;
177
178     Mat src(srcSize, type), dst(srcSize, CV_32FC1);
179     randu(src, 0, 1);
180     declare.in(src).out(dst)
181             .time(srcSize == OCL_SIZE_4000 ? 20 : srcSize == OCL_SIZE_2000 ? 5 : 3);
182
183     if (RUN_OCL_IMPL)
184     {
185         ocl::oclMat oclSrc(src), oclDst(srcSize, CV_32FC1);
186
187         OCL_TEST_CYCLE() cv::ocl::cornerHarris(oclSrc, oclDst, 5, 7, 0.1, borderType);
188
189         oclDst.download(dst);
190
191         SANITY_CHECK(dst, 3e-5);
192     }
193     else if (RUN_PLAIN_IMPL)
194     {
195         TEST_CYCLE() cv::cornerHarris(src, dst, 5, 7, 0.1, borderType);
196
197         SANITY_CHECK(dst, 3e-5);
198     }
199     else
200         OCL_PERF_ELSE
201 }
202
203 ///////////// integral ////////////////////////
204
205 typedef TestBaseWithParam<Size> integralFixture;
206
207 PERF_TEST_P(integralFixture, integral, OCL_TYPICAL_MAT_SIZES)
208 {
209     const Size srcSize = GetParam();
210
211     Mat src(srcSize, CV_8UC1), dst;
212     declare.in(src, WARMUP_RNG);
213
214     if (RUN_OCL_IMPL)
215     {
216         ocl::oclMat oclSrc(src), oclDst;
217
218         OCL_TEST_CYCLE() cv::ocl::integral(oclSrc, oclDst);
219
220         oclDst.download(dst);
221
222         SANITY_CHECK(dst);
223     }
224     else if (RUN_PLAIN_IMPL)
225     {
226         TEST_CYCLE() cv::integral(src, dst);
227
228         SANITY_CHECK(dst);
229     }
230     else
231         OCL_PERF_ELSE
232 }
233
234 ///////////// threshold////////////////////////
235
236 CV_ENUM(ThreshType, THRESH_BINARY, THRESH_TOZERO_INV)
237
238 typedef tuple<Size, MatType, ThreshType> ThreshParams;
239 typedef TestBaseWithParam<ThreshParams> ThreshFixture;
240
241 PERF_TEST_P(ThreshFixture, threshold,
242             ::testing::Combine(OCL_TYPICAL_MAT_SIZES,
243                                OCL_PERF_ENUM(CV_8UC1, CV_8UC4, CV_16SC1, CV_16SC4, CV_32FC1),
244                                ThreshType::all()))
245 {
246     const ThreshParams params = GetParam();
247     const Size srcSize = get<0>(params);
248     const int srcType = get<1>(params);
249     const int threshType = get<2>(params);
250     const double maxValue = 220.0, threshold = 50;
251
252     Mat src(srcSize, srcType), dst(srcSize, srcType);
253     randu(src, 0, 100);
254     declare.in(src).out(dst);
255
256     if (RUN_OCL_IMPL)
257     {
258         ocl::oclMat oclSrc(src), oclDst(srcSize, CV_8U);
259
260         OCL_TEST_CYCLE() cv::ocl::threshold(oclSrc, oclDst, threshold, maxValue, threshType);
261
262         oclDst.download(dst);
263
264         SANITY_CHECK(dst);
265     }
266     else if (RUN_PLAIN_IMPL)
267     {
268         TEST_CYCLE() cv::threshold(src, dst, threshold, maxValue, threshType);
269
270         SANITY_CHECK(dst);
271     }
272     else
273         OCL_PERF_ELSE
274 }
275
276 ///////////// meanShiftFiltering////////////////////////
277
278 typedef struct _COOR
279 {
280     short x;
281     short y;
282 } COOR;
283
284 static COOR do_meanShift(int x0, int y0, uchar *sptr, uchar *dptr, int sstep, cv::Size size, int sp, int sr, int maxIter, float eps, int *tab)
285 {
286
287     int isr2 = sr * sr;
288     int c0, c1, c2, c3;
289     int iter;
290     uchar *ptr = NULL;
291     uchar *pstart = NULL;
292     int revx = 0, revy = 0;
293     c0 = sptr[0];
294     c1 = sptr[1];
295     c2 = sptr[2];
296     c3 = sptr[3];
297     // iterate meanshift procedure
298     for(iter = 0; iter < maxIter; iter++ )
299     {
300         int count = 0;
301         int s0 = 0, s1 = 0, s2 = 0, sx = 0, sy = 0;
302
303         //mean shift: process pixels in window (p-sigmaSp)x(p+sigmaSp)
304         int minx = x0 - sp;
305         int miny = y0 - sp;
306         int maxx = x0 + sp;
307         int maxy = y0 + sp;
308
309         //deal with the image boundary
310         if(minx < 0) minx = 0;
311         if(miny < 0) miny = 0;
312         if(maxx >= size.width) maxx = size.width - 1;
313         if(maxy >= size.height) maxy = size.height - 1;
314         if(iter == 0)
315         {
316             pstart = sptr;
317         }
318         else
319         {
320             pstart = pstart + revy * sstep + (revx << 2); //point to the new position
321         }
322         ptr = pstart;
323         ptr = ptr + (miny - y0) * sstep + ((minx - x0) << 2); //point to the start in the row
324
325         for( int y = miny; y <= maxy; y++, ptr += sstep - ((maxx - minx + 1) << 2))
326         {
327             int rowCount = 0;
328             int x = minx;
329 #if CV_ENABLE_UNROLLED
330             for( ; x + 4 <= maxx; x += 4, ptr += 16)
331             {
332                 int t0, t1, t2;
333                 t0 = ptr[0], t1 = ptr[1], t2 = ptr[2];
334                 if(tab[t0 - c0 + 255] + tab[t1 - c1 + 255] + tab[t2 - c2 + 255] <= isr2)
335                 {
336                     s0 += t0;
337                     s1 += t1;
338                     s2 += t2;
339                     sx += x;
340                     rowCount++;
341                 }
342                 t0 = ptr[4], t1 = ptr[5], t2 = ptr[6];
343                 if(tab[t0 - c0 + 255] + tab[t1 - c1 + 255] + tab[t2 - c2 + 255] <= isr2)
344                 {
345                     s0 += t0;
346                     s1 += t1;
347                     s2 += t2;
348                     sx += x + 1;
349                     rowCount++;
350                 }
351                 t0 = ptr[8], t1 = ptr[9], t2 = ptr[10];
352                 if(tab[t0 - c0 + 255] + tab[t1 - c1 + 255] + tab[t2 - c2 + 255] <= isr2)
353                 {
354                     s0 += t0;
355                     s1 += t1;
356                     s2 += t2;
357                     sx += x + 2;
358                     rowCount++;
359                 }
360                 t0 = ptr[12], t1 = ptr[13], t2 = ptr[14];
361                 if(tab[t0 - c0 + 255] + tab[t1 - c1 + 255] + tab[t2 - c2 + 255] <= isr2)
362                 {
363                     s0 += t0;
364                     s1 += t1;
365                     s2 += t2;
366                     sx += x + 3;
367                     rowCount++;
368                 }
369             }
370 #endif
371             for(; x <= maxx; x++, ptr += 4)
372             {
373                 int t0 = ptr[0], t1 = ptr[1], t2 = ptr[2];
374                 if(tab[t0 - c0 + 255] + tab[t1 - c1 + 255] + tab[t2 - c2 + 255] <= isr2)
375                 {
376                     s0 += t0;
377                     s1 += t1;
378                     s2 += t2;
379                     sx += x;
380                     rowCount++;
381                 }
382             }
383             if(rowCount == 0)
384                 continue;
385             count += rowCount;
386             sy += y * rowCount;
387         }
388
389         if( count == 0 )
390             break;
391
392         int x1 = sx / count;
393         int y1 = sy / count;
394         s0 = s0 / count;
395         s1 = s1 / count;
396         s2 = s2 / count;
397
398         bool stopFlag = (x0 == x1 && y0 == y1) || (abs(x1 - x0) + abs(y1 - y0) +
399             tab[s0 - c0 + 255] + tab[s1 - c1 + 255] + tab[s2 - c2 + 255] <= eps);
400
401         //revise the pointer corresponding to the new (y0,x0)
402         revx = x1 - x0;
403         revy = y1 - y0;
404
405         x0 = x1;
406         y0 = y1;
407         c0 = s0;
408         c1 = s1;
409         c2 = s2;
410
411         if( stopFlag )
412             break;
413     } //for iter
414
415     dptr[0] = (uchar)c0;
416     dptr[1] = (uchar)c1;
417     dptr[2] = (uchar)c2;
418     dptr[3] = (uchar)c3;
419
420     COOR coor;
421     coor.x = static_cast<short>(x0);
422     coor.y = static_cast<short>(y0);
423     return coor;
424 }
425
426 static void meanShiftFiltering_(const Mat &src_roi, Mat &dst_roi, int sp, int sr, cv::TermCriteria crit)
427 {
428     if( src_roi.empty() )
429         CV_Error( Error::StsBadArg, "The input image is empty" );
430
431     if( src_roi.depth() != CV_8U || src_roi.channels() != 4 )
432         CV_Error( Error::StsUnsupportedFormat, "Only 8-bit, 4-channel images are supported" );
433
434     dst_roi.create(src_roi.size(), src_roi.type());
435
436     CV_Assert( (src_roi.cols == dst_roi.cols) && (src_roi.rows == dst_roi.rows) );
437     CV_Assert( !(dst_roi.step & 0x3) );
438
439     if( !(crit.type & cv::TermCriteria::MAX_ITER) )
440         crit.maxCount = 5;
441     int maxIter = std::min(std::max(crit.maxCount, 1), 100);
442     float eps;
443     if( !(crit.type & cv::TermCriteria::EPS) )
444         eps = 1.f;
445     eps = (float)std::max(crit.epsilon, 0.0);
446
447     int tab[512];
448     for(int i = 0; i < 512; i++)
449         tab[i] = (i - 255) * (i - 255);
450     uchar *sptr = src_roi.data;
451     uchar *dptr = dst_roi.data;
452     int sstep = (int)src_roi.step;
453     int dstep = (int)dst_roi.step;
454     cv::Size size = src_roi.size();
455
456     for(int i = 0; i < size.height; i++, sptr += sstep - (size.width << 2),
457         dptr += dstep - (size.width << 2))
458     {
459         for(int j = 0; j < size.width; j++, sptr += 4, dptr += 4)
460         {
461             do_meanShift(j, i, sptr, dptr, sstep, size, sp, sr, maxIter, eps, tab);
462         }
463     }
464 }
465
466 typedef TestBaseWithParam<Size> meanShiftFilteringFixture;
467
468 PERF_TEST_P(meanShiftFilteringFixture, meanShiftFiltering,
469             OCL_TYPICAL_MAT_SIZES)
470 {
471     const Size srcSize = GetParam();
472     const int sp = 5, sr = 6;
473     cv::TermCriteria crit(cv::TermCriteria::COUNT + cv::TermCriteria::EPS, 5, 1);
474
475     Mat src(srcSize, CV_8UC4), dst(srcSize, CV_8UC4);
476     declare.in(src, WARMUP_RNG).out(dst)
477             .time(srcSize == OCL_SIZE_4000 ?
478                       56 : srcSize == OCL_SIZE_2000 ? 15 : 3.8);
479
480     if (RUN_PLAIN_IMPL)
481     {
482         TEST_CYCLE() meanShiftFiltering_(src, dst, sp, sr, crit);
483
484         SANITY_CHECK(dst);
485     }
486     else if (RUN_OCL_IMPL)
487     {
488         ocl::oclMat oclSrc(src), oclDst(srcSize, CV_8UC4);
489
490         OCL_TEST_CYCLE() ocl::meanShiftFiltering(oclSrc, oclDst, sp, sr, crit);
491
492         oclDst.download(dst);
493
494         SANITY_CHECK(dst);
495     }
496     else
497         OCL_PERF_ELSE
498 }
499
500 static void meanShiftProc_(const Mat &src_roi, Mat &dst_roi, Mat &dstCoor_roi, int sp, int sr, cv::TermCriteria crit)
501 {
502     if (src_roi.empty())
503     {
504         CV_Error(Error::StsBadArg, "The input image is empty");
505     }
506     if (src_roi.depth() != CV_8U || src_roi.channels() != 4)
507     {
508         CV_Error(Error::StsUnsupportedFormat, "Only 8-bit, 4-channel images are supported");
509     }
510
511     dst_roi.create(src_roi.size(), src_roi.type());
512     dstCoor_roi.create(src_roi.size(), CV_16SC2);
513
514     CV_Assert((src_roi.cols == dst_roi.cols) && (src_roi.rows == dst_roi.rows) &&
515               (src_roi.cols == dstCoor_roi.cols) && (src_roi.rows == dstCoor_roi.rows));
516     CV_Assert(!(dstCoor_roi.step & 0x3));
517
518     if (!(crit.type & cv::TermCriteria::MAX_ITER))
519     {
520         crit.maxCount = 5;
521     }
522
523     int maxIter = std::min(std::max(crit.maxCount, 1), 100);
524     float eps;
525
526     if (!(crit.type & cv::TermCriteria::EPS))
527     {
528         eps = 1.f;
529     }
530
531     eps = (float)std::max(crit.epsilon, 0.0);
532
533     int tab[512];
534
535     for (int i = 0; i < 512; i++)
536     {
537         tab[i] = (i - 255) * (i - 255);
538     }
539
540     uchar *sptr = src_roi.data;
541     uchar *dptr = dst_roi.data;
542     short *dCoorptr = (short *)dstCoor_roi.data;
543     int sstep = (int)src_roi.step;
544     int dstep = (int)dst_roi.step;
545     int dCoorstep = (int)dstCoor_roi.step >> 1;
546     cv::Size size = src_roi.size();
547
548     for (int i = 0; i < size.height; i++, sptr += sstep - (size.width << 2),
549             dptr += dstep - (size.width << 2), dCoorptr += dCoorstep - (size.width << 1))
550     {
551         for (int j = 0; j < size.width; j++, sptr += 4, dptr += 4, dCoorptr += 2)
552         {
553             *((COOR *)dCoorptr) = do_meanShift(j, i, sptr, dptr, sstep, size, sp, sr, maxIter, eps, tab);
554         }
555     }
556
557 }
558
559 typedef TestBaseWithParam<Size> meanShiftProcFixture;
560
561 PERF_TEST_P(meanShiftProcFixture, meanShiftProc,
562             OCL_TYPICAL_MAT_SIZES)
563 {
564     const Size srcSize = GetParam();
565     TermCriteria crit(TermCriteria::COUNT + TermCriteria::EPS, 5, 1);
566
567     Mat src(srcSize, CV_8UC4), dst1(srcSize, CV_8UC4),
568             dst2(srcSize, CV_16SC2);
569     declare.in(src, WARMUP_RNG).out(dst1, dst2)
570             .time(srcSize == OCL_SIZE_4000 ?
571                       56 : srcSize == OCL_SIZE_2000 ? 15 : 3.8);;
572
573     if (RUN_PLAIN_IMPL)
574     {
575         TEST_CYCLE() meanShiftProc_(src, dst1, dst2, 5, 6, crit);
576
577         SANITY_CHECK(dst1);
578         SANITY_CHECK(dst2);
579     }
580     else if (RUN_OCL_IMPL)
581     {
582         ocl::oclMat oclSrc(src), oclDst1(srcSize, CV_8UC4),
583                 oclDst2(srcSize, CV_16SC2);
584
585         OCL_TEST_CYCLE() ocl::meanShiftProc(oclSrc, oclDst1, oclDst2, 5, 6, crit);
586
587         oclDst1.download(dst1);
588         oclDst2.download(dst2);
589
590         SANITY_CHECK(dst1);
591         SANITY_CHECK(dst2);
592     }
593     else
594         OCL_PERF_ELSE
595 }
596
597 ///////////// CLAHE ////////////////////////
598
599 typedef TestBaseWithParam<Size> CLAHEFixture;
600
601 PERF_TEST_P(CLAHEFixture, CLAHE, OCL_TYPICAL_MAT_SIZES)
602 {
603     const Size srcSize = GetParam();
604     const string impl = getSelectedImpl();
605
606     Mat src(srcSize, CV_8UC1), dst;
607     const double clipLimit = 40.0;
608     declare.in(src, WARMUP_RNG);
609
610     if (srcSize == OCL_SIZE_4000)
611         declare.time(11);
612
613     if (RUN_OCL_IMPL)
614     {
615         ocl::oclMat oclSrc(src), oclDst;
616         cv::Ptr<cv::CLAHE> oclClahe = cv::ocl::createCLAHE(clipLimit);
617
618         OCL_TEST_CYCLE() oclClahe->apply(oclSrc, oclDst);
619
620         oclDst.download(dst);
621
622         SANITY_CHECK(dst);
623     }
624     else if (RUN_PLAIN_IMPL)
625     {
626         cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE(clipLimit);
627         TEST_CYCLE() clahe->apply(src, dst);
628
629         SANITY_CHECK(dst);
630     }
631     else
632         OCL_PERF_ELSE
633 }
634
635 ///////////// columnSum////////////////////////
636
637 typedef TestBaseWithParam<Size> columnSumFixture;
638
639 static void columnSumPerfTest(const Mat & src, Mat & dst)
640 {
641     for (int j = 0; j < src.cols; j++)
642         dst.at<float>(0, j) = src.at<float>(0, j);
643
644     for (int i = 1; i < src.rows; ++i)
645         for (int j = 0; j < src.cols; ++j)
646             dst.at<float>(i, j) = dst.at<float>(i - 1 , j) + src.at<float>(i , j);
647 }
648
649 PERF_TEST_P(columnSumFixture, columnSum, OCL_TYPICAL_MAT_SIZES)
650 {
651     const Size srcSize = GetParam();
652
653     Mat src(srcSize, CV_32FC1), dst(srcSize, CV_32FC1);
654     declare.in(src, WARMUP_RNG).out(dst);
655
656     if (srcSize == OCL_SIZE_4000)
657         declare.time(5);
658
659     if (RUN_OCL_IMPL)
660     {
661         ocl::oclMat oclSrc(src), oclDst(srcSize, CV_32FC1);
662
663         OCL_TEST_CYCLE() cv::ocl::columnSum(oclSrc, oclDst);
664
665         oclDst.download(dst);
666
667         SANITY_CHECK(dst);
668     }
669     else if (RUN_PLAIN_IMPL)
670     {
671         TEST_CYCLE() columnSumPerfTest(src, dst);
672
673         SANITY_CHECK(dst);
674     }
675     else
676         OCL_PERF_ELSE
677 }
678
679 //////////////////////////////distanceToCenters////////////////////////////////////////////////
680
681 CV_ENUM(DistType, NORM_L1, NORM_L2SQR)
682
683 typedef tuple<Size, DistType> distanceToCentersParameters;
684 typedef TestBaseWithParam<distanceToCentersParameters> distanceToCentersFixture;
685
686 static void distanceToCentersPerfTest(Mat& src, Mat& centers, Mat& dists, Mat& labels, int distType)
687 {
688     Mat batch_dists;
689     cv::batchDistance(src, centers, batch_dists, CV_32FC1, noArray(), distType);
690
691     std::vector<float> dists_v;
692     std::vector<int> labels_v;
693
694     for (int i = 0; i < batch_dists.rows; i++)
695     {
696         Mat r = batch_dists.row(i);
697         double mVal;
698         Point mLoc;
699
700         minMaxLoc(r, &mVal, NULL, &mLoc, NULL);
701         dists_v.push_back(static_cast<float>(mVal));
702         labels_v.push_back(mLoc.x);
703     }
704
705     Mat(dists_v).copyTo(dists);
706     Mat(labels_v).copyTo(labels);
707 }
708
709 PERF_TEST_P(distanceToCentersFixture, distanceToCenters, ::testing::Combine(::testing::Values(cv::Size(256,256), cv::Size(512,512)), DistType::all()) )
710 {
711     Size size = get<0>(GetParam());
712     int distType = get<1>(GetParam());
713
714     Mat src(size, CV_32FC1), centers(size, CV_32FC1);
715     Mat dists(src.rows, 1, CV_32FC1), labels(src.rows, 1, CV_32SC1);
716
717     declare.in(src, centers, WARMUP_RNG).out(dists, labels);
718
719     if (RUN_OCL_IMPL)
720     {
721         ocl::oclMat ocl_src(src), ocl_centers(centers);
722
723         OCL_TEST_CYCLE() ocl::distanceToCenters(ocl_src, ocl_centers, dists, labels, distType);
724
725         SANITY_CHECK(dists, 1e-6, ERROR_RELATIVE);
726         SANITY_CHECK(labels);
727     }
728     else if (RUN_PLAIN_IMPL)
729     {
730         TEST_CYCLE() distanceToCentersPerfTest(src, centers, dists, labels, distType);
731
732         SANITY_CHECK(dists, 1e-6, ERROR_RELATIVE);
733         SANITY_CHECK(labels);
734     }
735     else
736         OCL_PERF_ELSE
737 }