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) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
14 // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
15 // Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
16 // Third party copyrights are property of their respective owners.
19 // Niko Li, newlife20080214@gmail.com
20 // Jia Haipeng, jiahaipeng95@gmail.com
21 // Shengen Yan, yanshengen@gmail.com
22 // Jiang Liyuan, lyuan001.good@163.com
23 // Rock Li, Rock.Li@amd.com
24 // Wu Zailong, bullet@yeah.net
25 // Xu Pang, pangxu010@163.com
26 // Sen Liu, swjtuls1987@126.com
28 // Redistribution and use in source and binary forms, with or without modification,
29 // are permitted provided that the following conditions are met:
31 // * Redistribution's of source code must retain the above copyright notice,
32 // this list of conditions and the following disclaimer.
34 // * Redistribution's in binary form must reproduce the above copyright notice,
35 // this list of conditions and the following disclaimer in the documentation
36 // and/or other oclMaterials provided with the distribution.
38 // * The name of the copyright holders may not be used to endorse or promote products
39 // derived from this software without specific prior written permission.
41 // This software is provided by the copyright holders and contributors "as is" and
42 // any express or implied warranties, including, but not limited to, the implied
43 // warranties of merchantability and fitness for a particular purpose are disclaimed.
44 // In no event shall the Intel Corporation or contributors be liable for any direct,
45 // indirect, incidental, special, exemplary, or consequential damages
46 // (including, but not limited to, procurement of substitute goods or services;
47 // loss of use, data, or profits; or business interruption) however caused
48 // and on any theory of liability, whether in contract, strict liability,
49 // or tort (including negligence or otherwise) arising in any way out of
50 // the use of this software, even if advised of the possibility of such damage.
54 #include "test_precomp.hpp"
58 using namespace cvtest;
59 using namespace testing;
62 MatType nulltype = -1;
64 #define ONE_TYPE(type) testing::ValuesIn(typeVector(type))
65 #define NULL_TYPE testing::ValuesIn(typeVector(nulltype))
67 vector<MatType> typeVector(MatType type)
80 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)
88 int revx = 0, revy = 0;
93 // iterate meanshift procedure
94 for(iter = 0; iter < maxIter; iter++ )
97 int s0 = 0, s1 = 0, s2 = 0, sx = 0, sy = 0;
99 //mean shift: process pixels in window (p-sigmaSp)x(p+sigmaSp)
105 //deal with the image boundary
106 if(minx < 0) minx = 0;
107 if(miny < 0) miny = 0;
108 if(maxx >= size.width) maxx = size.width - 1;
109 if(maxy >= size.height) maxy = size.height - 1;
116 pstart = pstart + revy * sstep + (revx << 2); //point to the new position
119 ptr = ptr + (miny - y0) * sstep + ((minx - x0) << 2); //point to the start in the row
121 for( int y = miny; y <= maxy; y++, ptr += sstep - ((maxx - minx + 1) << 2))
125 #if CV_ENABLE_UNROLLED
126 for( ; x + 4 <= maxx; x += 4, ptr += 16)
129 t0 = ptr[0], t1 = ptr[1], t2 = ptr[2];
130 if(tab[t0 - c0 + 255] + tab[t1 - c1 + 255] + tab[t2 - c2 + 255] <= isr2)
138 t0 = ptr[4], t1 = ptr[5], t2 = ptr[6];
139 if(tab[t0 - c0 + 255] + tab[t1 - c1 + 255] + tab[t2 - c2 + 255] <= isr2)
147 t0 = ptr[8], t1 = ptr[9], t2 = ptr[10];
148 if(tab[t0 - c0 + 255] + tab[t1 - c1 + 255] + tab[t2 - c2 + 255] <= isr2)
156 t0 = ptr[12], t1 = ptr[13], t2 = ptr[14];
157 if(tab[t0 - c0 + 255] + tab[t1 - c1 + 255] + tab[t2 - c2 + 255] <= isr2)
167 for(; x <= maxx; x++, ptr += 4)
169 int t0 = ptr[0], t1 = ptr[1], t2 = ptr[2];
170 if(tab[t0 - c0 + 255] + tab[t1 - c1 + 255] + tab[t2 - c2 + 255] <= isr2)
194 bool stopFlag = (x0 == x1 && y0 == y1) || (abs(x1 - x0) + abs(y1 - y0) +
195 tab[s0 - c0 + 255] + tab[s1 - c1 + 255] + tab[s2 - c2 + 255] <= eps);
197 //revise the pointer corresponding to the new (y0,x0)
222 void meanShiftFiltering_(const Mat &src_roi, Mat &dst_roi, int sp, int sr, cv::TermCriteria crit)
224 if( src_roi.empty() )
225 CV_Error( CV_StsBadArg, "The input image is empty" );
227 if( src_roi.depth() != CV_8U || src_roi.channels() != 4 )
228 CV_Error( CV_StsUnsupportedFormat, "Only 8-bit, 4-channel images are supported" );
230 CV_Assert( (src_roi.cols == dst_roi.cols) && (src_roi.rows == dst_roi.rows) );
231 CV_Assert( !(dst_roi.step & 0x3) );
233 if( !(crit.type & cv::TermCriteria::MAX_ITER) )
235 int maxIter = std::min(std::max(crit.maxCount, 1), 100);
237 if( !(crit.type & cv::TermCriteria::EPS) )
239 eps = (float)std::max(crit.epsilon, 0.0);
242 for(int i = 0; i < 512; i++)
243 tab[i] = (i - 255) * (i - 255);
244 uchar *sptr = src_roi.data;
245 uchar *dptr = dst_roi.data;
246 int sstep = (int)src_roi.step;
247 int dstep = (int)dst_roi.step;
248 cv::Size size = src_roi.size();
250 for(int i = 0; i < size.height; i++, sptr += sstep - (size.width << 2),
251 dptr += dstep - (size.width << 2))
253 for(int j = 0; j < size.width; j++, sptr += 4, dptr += 4)
255 do_meanShift(j, i, sptr, dptr, sstep, size, sp, sr, maxIter, eps, tab);
260 void meanShiftProc_(const Mat &src_roi, Mat &dst_roi, Mat &dstCoor_roi, int sp, int sr, cv::TermCriteria crit)
263 if( src_roi.empty() )
264 CV_Error( CV_StsBadArg, "The input image is empty" );
265 if( src_roi.depth() != CV_8U || src_roi.channels() != 4 )
266 CV_Error( CV_StsUnsupportedFormat, "Only 8-bit, 4-channel images are supported" );
267 CV_Assert( (src_roi.cols == dst_roi.cols) && (src_roi.rows == dst_roi.rows) &&
268 (src_roi.cols == dstCoor_roi.cols) && (src_roi.rows == dstCoor_roi.rows));
269 CV_Assert( !(dstCoor_roi.step & 0x3) );
271 if( !(crit.type & cv::TermCriteria::MAX_ITER) )
273 int maxIter = std::min(std::max(crit.maxCount, 1), 100);
275 if( !(crit.type & cv::TermCriteria::EPS) )
277 eps = (float)std::max(crit.epsilon, 0.0);
280 for(int i = 0; i < 512; i++)
281 tab[i] = (i - 255) * (i - 255);
282 uchar *sptr = src_roi.data;
283 uchar *dptr = dst_roi.data;
284 short *dCoorptr = (short *)dstCoor_roi.data;
285 int sstep = (int)src_roi.step;
286 int dstep = (int)dst_roi.step;
287 int dCoorstep = (int)dstCoor_roi.step >> 1;
288 cv::Size size = src_roi.size();
290 for(int i = 0; i < size.height; i++, sptr += sstep - (size.width << 2),
291 dptr += dstep - (size.width << 2), dCoorptr += dCoorstep - (size.width << 1))
293 for(int j = 0; j < size.width; j++, sptr += 4, dptr += 4, dCoorptr += 2)
295 *((COOR *)dCoorptr) = do_meanShift(j, i, sptr, dptr, sstep, size, sp, sr, maxIter, eps, tab);
301 PARAM_TEST_CASE(ImgprocTestBase, MatType, MatType, MatType, MatType, MatType, bool)
303 int type1, type2, type3, type4, type5;
324 cv::Mat dst1; //bak, for two outputs
331 cv::Mat dst1_roi; //bak
334 cv::ocl::oclMat clmat1;
335 cv::ocl::oclMat clmat2;
336 cv::ocl::oclMat clmask;
337 cv::ocl::oclMat cldst;
338 cv::ocl::oclMat cldst1; //bak
341 cv::ocl::oclMat clmat1_roi;
342 cv::ocl::oclMat clmat2_roi;
343 cv::ocl::oclMat clmask_roi;
344 cv::ocl::oclMat cldst_roi;
345 cv::ocl::oclMat cldst1_roi;
349 type1 = GET_PARAM(0);
350 type2 = GET_PARAM(1);
351 type3 = GET_PARAM(2);
352 type4 = GET_PARAM(3);
353 type5 = GET_PARAM(4);
354 cv::Size size(MWIDTH, MHEIGHT);
355 double min = 1, max = 20;
357 if(type1 != nulltype)
359 mat1 = randomMat(size, type1, min, max, false);
362 if(type2 != nulltype)
364 mat2 = randomMat(size, type2, min, max, false);
367 if(type3 != nulltype)
369 dst = randomMat(size, type3, min, max, false);
372 if(type4 != nulltype)
374 dst1 = randomMat(size, type4, min, max, false);
377 if(type5 != nulltype)
379 mask = randomMat(size, CV_8UC1, 0, 2, false);
380 cv::threshold(mask, mask, 0.5, 255., type5);
383 val = cv::Scalar(rng.uniform(-10.0, 10.0), rng.uniform(-10.0, 10.0), rng.uniform(-10.0, 10.0), rng.uniform(-10.0, 10.0));
390 roicols = rng.uniform(1, mat1.cols);
391 roirows = rng.uniform(1, mat1.rows);
392 src1x = rng.uniform(0, mat1.cols - roicols);
393 src1y = rng.uniform(0, mat1.rows - roirows);
394 src2x = rng.uniform(0, mat2.cols - roicols);
395 src2y = rng.uniform(0, mat2.rows - roirows);
396 dstx = rng.uniform(0, dst.cols - roicols);
397 dsty = rng.uniform(0, dst.rows - roirows);
398 dst1x = rng.uniform(0, dst1.cols - roicols);
399 dst1y = rng.uniform(0, dst1.rows - roirows);
400 maskx = rng.uniform(0, mask.cols - roicols);
401 masky = rng.uniform(0, mask.rows - roirows);
418 if(type1 != nulltype)
420 mat1_roi = mat1(Rect(src1x, src1y, roicols, roirows));
421 clmat1_roi = clmat1(Rect(src1x, src1y, roicols, roirows));
423 if(type2 != nulltype)
425 mat2_roi = mat2(Rect(src2x, src2y, roicols, roirows));
426 clmat2_roi = clmat2(Rect(src2x, src2y, roicols, roirows));
428 if(type3 != nulltype)
430 dst_roi = dst(Rect(dstx, dsty, roicols, roirows));
431 cldst_roi = cldst(Rect(dstx, dsty, roicols, roirows));
433 if(type4 != nulltype)
435 dst1_roi = dst1(Rect(dst1x, dst1y, roicols, roirows));
436 cldst1_roi = cldst1(Rect(dst1x, dst1y, roicols, roirows));
438 if(type5 != nulltype)
440 mask_roi = mask(Rect(maskx, masky, roicols, roirows));
441 clmask_roi = clmask(Rect(maskx, masky, roicols, roirows));
445 void Near(double threshold)
448 cldst.download(cpu_cldst);
449 EXPECT_MAT_NEAR(dst, cpu_cldst, threshold);
452 ////////////////////////////////equalizeHist//////////////////////////////////////////
454 struct equalizeHist : ImgprocTestBase {};
456 OCL_TEST_P(equalizeHist, Mat)
458 if (mat1.type() != CV_8UC1 || mat1.type() != dst.type())
460 cout << "Unsupported type" << endl;
461 EXPECT_DOUBLE_EQ(0.0, 0.0);
465 for(int j = 0; j < LOOP_TIMES; j++)
468 cv::equalizeHist(mat1_roi, dst_roi);
469 cv::ocl::equalizeHist(clmat1_roi, cldst_roi);
476 ////////////////////////////////copyMakeBorder////////////////////////////////////////////
478 struct CopyMakeBorder : ImgprocTestBase {};
480 OCL_TEST_P(CopyMakeBorder, Mat)
482 int bordertype[] = {cv::BORDER_CONSTANT, cv::BORDER_REPLICATE, cv::BORDER_REFLECT, cv::BORDER_WRAP, cv::BORDER_REFLECT_101};
483 int top = rng.uniform(0, 10);
484 int bottom = rng.uniform(0, 10);
485 int left = rng.uniform(0, 10);
486 int right = rng.uniform(0, 10);
487 if (mat1.type() != dst.type())
489 cout << "Unsupported type" << endl;
490 EXPECT_DOUBLE_EQ(0.0, 0.0);
494 for(size_t i = 0; i < sizeof(bordertype) / sizeof(int); i++)
495 for(int j = 0; j < LOOP_TIMES; j++)
499 if(((bordertype[i] != cv::BORDER_CONSTANT) && (bordertype[i] != cv::BORDER_REPLICATE)) && (mat1_roi.cols <= left) || (mat1_roi.cols <= right) || (mat1_roi.rows <= top) || (mat1_roi.rows <= bottom))
503 if((dstx >= left) && (dsty >= top) && (dstx + cldst_roi.cols + right <= cldst_roi.wholecols) && (dsty + cldst_roi.rows + bottom <= cldst_roi.wholerows))
505 dst_roi.adjustROI(top, bottom, left, right);
506 cldst_roi.adjustROI(top, bottom, left, right);
513 cv::copyMakeBorder(mat1_roi, dst_roi, top, bottom, left, right, bordertype[i] | cv::BORDER_ISOLATED, cv::Scalar(1.0));
514 cv::ocl::copyMakeBorder(clmat1_roi, cldst_roi, top, bottom, left, right, bordertype[i] | cv::BORDER_ISOLATED, cv::Scalar(1.0));
518 cldst_roi.download(cpu_cldst);
519 EXPECT_MAT_NEAR(dst_roi, cpu_cldst, 0.0);
521 cldst.download(cpu_cldst);
522 EXPECT_MAT_NEAR(dst, cpu_cldst, 0.0);
531 ////////////////////////////////cornerMinEigenVal//////////////////////////////////////////
533 struct cornerMinEigenVal : ImgprocTestBase {};
535 OCL_TEST_P(cornerMinEigenVal, Mat)
537 for(int j = 0; j < LOOP_TIMES; j++)
541 int blockSize = 3, apertureSize = 3;//1 + 2 * (rand() % 4);
542 //int borderType = cv::BORDER_CONSTANT;
543 //int borderType = cv::BORDER_REPLICATE;
544 int borderType = cv::BORDER_REFLECT;
545 cv::cornerMinEigenVal(mat1_roi, dst_roi, blockSize, apertureSize, borderType);
546 cv::ocl::cornerMinEigenVal(clmat1_roi, cldst_roi, blockSize, apertureSize, borderType);
553 ////////////////////////////////cornerHarris//////////////////////////////////////////
555 struct cornerHarris : ImgprocTestBase {};
557 OCL_TEST_P(cornerHarris, Mat)
559 for(int j = 0; j < LOOP_TIMES; j++)
563 int blockSize = 3, apertureSize = 3; //1 + 2 * (rand() % 4);
565 //int borderType = cv::BORDER_CONSTANT;
566 //int borderType = cv::BORDER_REPLICATE;
567 int borderType = cv::BORDER_REFLECT;
568 cv::cornerHarris(mat1_roi, dst_roi, blockSize, apertureSize, k, borderType);
569 cv::ocl::cornerHarris(clmat1_roi, cldst_roi, blockSize, apertureSize, k, borderType);
575 ////////////////////////////////integral/////////////////////////////////////////////////
577 struct integral : ImgprocTestBase {};
579 OCL_TEST_P(integral, Mat1)
581 for(int j = 0; j < LOOP_TIMES; j++)
585 cv::ocl::integral(clmat1_roi, cldst_roi);
586 cv::integral(mat1_roi, dst_roi);
591 OCL_TEST_P(integral, Mat2)
593 for(int j = 0; j < LOOP_TIMES; j++)
597 cv::ocl::integral(clmat1_roi, cldst_roi, cldst1_roi);
598 cv::integral(mat1_roi, dst_roi, dst1_roi);
602 cldst1.download(cpu_cldst1);
603 EXPECT_MAT_NEAR(dst1, cpu_cldst1, 0.0);
608 /////////////////////////////////////////////////////////////////////////////////////////////////
609 // warpAffine & warpPerspective
611 PARAM_TEST_CASE(WarpTestBase, MatType, int)
636 //ocl dst mat for testing
637 cv::ocl::oclMat gdst_whole;
640 cv::ocl::oclMat gmat1;
641 cv::ocl::oclMat gdst;
646 interpolation = GET_PARAM(1);
647 size = cv::Size(MWIDTH, MHEIGHT);
649 mat1 = randomMat(size, type, 5, 16, false);
650 dst = randomMat(size, type, 5, 16, false);
657 src_roicols = rng.uniform(1, mat1.cols);
658 src_roirows = rng.uniform(1, mat1.rows);
659 dst_roicols = rng.uniform(1, dst.cols);
660 dst_roirows = rng.uniform(1, dst.rows);
661 src1x = rng.uniform(0, mat1.cols - src_roicols);
662 src1y = rng.uniform(0, mat1.rows - src_roirows);
663 dstx = rng.uniform(0, dst.cols - dst_roicols);
664 dsty = rng.uniform(0, dst.rows - dst_roirows);
666 src_roicols = mat1.cols;
667 src_roirows = mat1.rows;
668 dst_roicols = dst.cols;
669 dst_roirows = dst.rows;
677 mat1_roi = mat1(Rect(src1x, src1y, src_roicols, src_roirows));
678 dst_roi = dst(Rect(dstx, dsty, dst_roicols, dst_roirows));
681 gdst = gdst_whole(Rect(dstx, dsty, dst_roicols, dst_roirows));
691 struct WarpAffine : WarpTestBase {};
693 OCL_TEST_P(WarpAffine, Mat)
695 static const double coeffs[2][3] =
697 {cos(CV_PI / 6), -sin(CV_PI / 6), 100.0},
698 {sin(CV_PI / 6), cos(CV_PI / 6), -100.0}
700 Mat M(2, 3, CV_64F, (void *)coeffs);
702 for(int j = 0; j < LOOP_TIMES; j++)
706 cv::warpAffine(mat1_roi, dst_roi, M, size, interpolation);
707 cv::ocl::warpAffine(gmat1, gdst, M, size, interpolation);
710 gdst_whole.download(cpu_dst);
711 EXPECT_MAT_NEAR(dst, cpu_dst, 1.0);
719 struct WarpPerspective : WarpTestBase {};
721 OCL_TEST_P(WarpPerspective, Mat)
723 static const double coeffs[3][3] =
725 {cos(3.14 / 6), -sin(3.14 / 6), 100.0},
726 {sin(3.14 / 6), cos(3.14 / 6), -100.0},
729 Mat M(3, 3, CV_64F, (void *)coeffs);
731 for(int j = 0; j < LOOP_TIMES; j++)
735 cv::warpPerspective(mat1_roi, dst_roi, M, size, interpolation);
736 cv::ocl::warpPerspective(gmat1, gdst, M, size, interpolation);
739 gdst_whole.download(cpu_dst);
740 EXPECT_MAT_NEAR(dst, cpu_dst, 1.0);
745 /////////////////////////////////////////////////////////////////////////////////////////////////
747 //////////////////////////////////////////////////////////////////////////////////////////////////
749 PARAM_TEST_CASE(Remap, MatType, MatType, MatType, int, int)
764 //std::vector<cv::ocl::Info> oclinfo;
788 //ocl mat for testing
789 cv::ocl::oclMat gdst;
792 cv::ocl::oclMat gsrc_roi;
793 cv::ocl::oclMat gdst_roi;
794 cv::ocl::oclMat gmap1_roi;
795 cv::ocl::oclMat gmap2_roi;
799 srcType = GET_PARAM(0);
800 map1Type = GET_PARAM(1);
801 map2Type = GET_PARAM(2);
802 interpolation = GET_PARAM(3);
803 bordertype = GET_PARAM(4);
805 cv::Size srcSize = cv::Size(MWIDTH, MHEIGHT);
806 cv::Size map1Size = cv::Size(MWIDTH, MHEIGHT);
807 double min = 5, max = 16;
809 if(srcType != nulltype)
811 src = randomMat(srcSize, srcType, min, max, false);
813 if((map1Type == CV_16SC2 && map2Type == nulltype) || (map1Type == CV_32FC2 && map2Type == nulltype))
815 map1 = randomMat(map1Size, map1Type, min, max, false);
817 else if (map1Type == CV_32FC1 && map2Type == CV_32FC1)
819 map1 = randomMat(map1Size, map1Type, min, max, false);
820 map2 = randomMat(map1Size, map1Type, min, max, false);
825 cout << "The wrong input type" << endl;
829 dst = randomMat(map1Size, srcType, min, max, false);
830 switch (src.channels())
833 val = cv::Scalar(rng.uniform(0.0, 10.0), 0, 0, 0);
836 val = cv::Scalar(rng.uniform(0.0, 10.0), rng.uniform(0.0, 10.0), 0, 0);
839 val = cv::Scalar(rng.uniform(0.0, 10.0), rng.uniform(0.0, 10.0), rng.uniform(0.0, 10.0), 0);
842 val = cv::Scalar(rng.uniform(0.0, 10.0), rng.uniform(0.0, 10.0), rng.uniform(0.0, 10.0), rng.uniform(0.0, 10.0));
849 dst_roicols = rng.uniform(1, dst.cols);
850 dst_roirows = rng.uniform(1, dst.rows);
852 src_roicols = rng.uniform(1, src.cols);
853 src_roirows = rng.uniform(1, src.rows);
856 srcx = rng.uniform(0, src.cols - src_roicols);
857 srcy = rng.uniform(0, src.rows - src_roirows);
858 dstx = rng.uniform(0, dst.cols - dst_roicols);
859 dsty = rng.uniform(0, dst.rows - dst_roirows);
860 map1_roicols = dst_roicols;
861 map1_roirows = dst_roirows;
862 map2_roicols = dst_roicols;
863 map2_roirows = dst_roirows;
869 if((map1Type == CV_16SC2 && map2Type == nulltype) || (map1Type == CV_32FC2 && map2Type == nulltype))
871 map1_roi = map1(Rect(map1x, map1y, map1_roicols, map1_roirows));
872 gmap1_roi = map1_roi;
875 else if (map1Type == CV_32FC1 && map2Type == CV_32FC1)
877 map1_roi = map1(Rect(map1x, map1y, map1_roicols, map1_roirows));
878 gmap1_roi = map1_roi;
879 map2_roi = map2(Rect(map2x, map2y, map2_roicols, map2_roirows));
880 gmap2_roi = map2_roi;
882 src_roi = src(Rect(srcx, srcy, src_roicols, src_roirows));
883 dst_roi = dst(Rect(dstx, dsty, dst_roicols, dst_roirows));
886 gdst_roi = gdst(Rect(dstx, dsty, dst_roicols, dst_roirows));
890 OCL_TEST_P(Remap, Mat)
892 if((interpolation == 1 && map1Type == CV_16SC2) || (map1Type == CV_32FC1 && map2Type == nulltype) || (map1Type == CV_16SC2 && map2Type == CV_32FC1) || (map1Type == CV_32FC2 && map2Type == CV_32FC1))
894 cout << "Don't support the dataType" << endl;
897 int bordertype[] = {cv::BORDER_CONSTANT, cv::BORDER_REPLICATE/*,BORDER_REFLECT,BORDER_WRAP,BORDER_REFLECT_101*/};
899 for(int j = 0; j < LOOP_TIMES; j++)
902 cv::remap(src_roi, dst_roi, map1_roi, map2_roi, interpolation, bordertype[0], val);
903 cv::ocl::remap(gsrc_roi, gdst_roi, gmap1_roi, gmap2_roi, interpolation, bordertype[0], val);
905 gdst.download(cpu_dst);
907 if(interpolation == 0)
908 EXPECT_MAT_NEAR(dst, cpu_dst, 1.0);
909 EXPECT_MAT_NEAR(dst, cpu_dst, 2.0);
915 /////////////////////////////////////////////////////////////////////////////////////////////////
918 PARAM_TEST_CASE(Resize, MatType, cv::Size, double, double, int)
943 //ocl dst mat for testing
944 cv::ocl::oclMat gdst_whole;
947 cv::ocl::oclMat gmat1;
948 cv::ocl::oclMat gdst;
953 dsize = GET_PARAM(1);
956 interpolation = GET_PARAM(4);
958 cv::Size size(MWIDTH, MHEIGHT);
960 if(dsize == cv::Size() && !(fx > 0 && fy > 0))
962 cout << "invalid dsize and fx fy" << endl;
966 if(dsize == cv::Size())
968 dsize.width = (int)(size.width * fx);
969 dsize.height = (int)(size.height * fy);
972 mat1 = randomMat(size, type, 5, 16, false);
973 dst = randomMat(dsize, type, 5, 16, false);
981 src_roicols = rng.uniform(1, mat1.cols);
982 src_roirows = rng.uniform(1, mat1.rows);
983 dst_roicols = (int)(src_roicols * fx);
984 dst_roirows = (int)(src_roirows * fy);
985 src1x = rng.uniform(0, mat1.cols - src_roicols);
986 src1y = rng.uniform(0, mat1.rows - src_roirows);
987 dstx = rng.uniform(0, dst.cols - dst_roicols);
988 dsty = rng.uniform(0, dst.rows - dst_roirows);
990 src_roicols = mat1.cols;
991 src_roirows = mat1.rows;
992 dst_roicols = dst.cols;
993 dst_roirows = dst.rows;
999 dsize.width = dst_roicols;
1000 dsize.height = dst_roirows;
1001 mat1_roi = mat1(Rect(src1x, src1y, src_roicols, src_roirows));
1002 dst_roi = dst(Rect(dstx, dsty, dst_roicols, dst_roirows));
1005 gdst = gdst_whole(Rect(dstx, dsty, dst_roicols, dst_roirows));
1007 dsize.width = (int)(mat1_roi.size().width * fx);
1008 dsize.height = (int)(mat1_roi.size().height * fy);
1015 OCL_TEST_P(Resize, Mat)
1017 for(int j = 0; j < LOOP_TIMES; j++)
1021 // cv::resize(mat1_roi, dst_roi, dsize, fx, fy, interpolation);
1022 // cv::ocl::resize(gmat1, gdst, dsize, fx, fy, interpolation);
1023 if(dst_roicols < 1 || dst_roirows < 1) continue;
1024 cv::resize(mat1_roi, dst_roi, dsize, fx, fy, interpolation);
1025 cv::ocl::resize(gmat1, gdst, dsize, fx, fy, interpolation);
1028 gdst_whole.download(cpu_dst);
1029 EXPECT_MAT_NEAR(dst, cpu_dst, 1.0);
1035 /////////////////////////////////////////////////////////////////////////////////////////////////
1038 PARAM_TEST_CASE(Threshold, MatType, ThreshOp)
1059 //ocl dst mat for testing
1060 cv::ocl::oclMat gdst_whole;
1063 cv::ocl::oclMat gmat1;
1064 cv::ocl::oclMat gdst;
1066 virtual void SetUp()
1068 type = GET_PARAM(0);
1069 threshOp = GET_PARAM(1);
1071 cv::Size size(MWIDTH, MHEIGHT);
1073 mat1 = randomMat(size, type, 5, 16, false);
1074 dst = randomMat(size, type, 5, 16, false);
1081 roicols = rng.uniform(1, mat1.cols);
1082 roirows = rng.uniform(1, mat1.rows);
1083 src1x = rng.uniform(0, mat1.cols - roicols);
1084 src1y = rng.uniform(0, mat1.rows - roirows);
1085 dstx = rng.uniform(0, dst.cols - roicols);
1086 dsty = rng.uniform(0, dst.rows - roirows);
1088 roicols = mat1.cols;
1089 roirows = mat1.rows;
1096 mat1_roi = mat1(Rect(src1x, src1y, roicols, roirows));
1097 dst_roi = dst(Rect(dstx, dsty, roicols, roirows));
1100 gdst = gdst_whole(Rect(dstx, dsty, roicols, roirows));
1108 OCL_TEST_P(Threshold, Mat)
1110 for(int j = 0; j < LOOP_TIMES; j++)
1113 double maxVal = randomDouble(20.0, 127.0);
1114 double thresh = randomDouble(0.0, maxVal);
1116 cv::threshold(mat1_roi, dst_roi, thresh, maxVal, threshOp);
1117 cv::ocl::threshold(gmat1, gdst, thresh, maxVal, threshOp);
1120 gdst_whole.download(cpu_dst);
1121 EXPECT_MAT_NEAR(dst, cpu_dst, 1);
1126 PARAM_TEST_CASE(meanShiftTestBase, MatType, MatType, int, int, cv::TermCriteria)
1130 cv::TermCriteria crit;
1147 cv::Mat dstCoor_roi;
1150 cv::ocl::oclMat gdst;
1151 cv::ocl::oclMat gdstCoor;
1154 cv::ocl::oclMat gsrc_roi;
1155 cv::ocl::oclMat gdst_roi;
1156 cv::ocl::oclMat gdstCoor_roi;
1158 virtual void SetUp()
1160 type = GET_PARAM(0);
1161 typeCoor = GET_PARAM(1);
1164 crit = GET_PARAM(4);
1166 // MWIDTH=256, MHEIGHT=256. defined in utility.hpp
1167 cv::Size size = cv::Size(MWIDTH, MHEIGHT);
1169 src = randomMat(size, type, 5, 16, false);
1170 dst = randomMat(size, type, 5, 16, false);
1171 dstCoor = randomMat(size, typeCoor, 5, 16, false);
1179 roicols = rng.uniform(1, src.cols);
1180 roirows = rng.uniform(1, src.rows);
1181 srcx = rng.uniform(0, src.cols - roicols);
1182 srcy = rng.uniform(0, src.rows - roirows);
1183 dstx = rng.uniform(0, dst.cols - roicols);
1184 dsty = rng.uniform(0, dst.rows - roirows);
1193 src_roi = src(Rect(srcx, srcy, roicols, roirows));
1194 dst_roi = dst(Rect(dstx, dsty, roicols, roirows));
1195 dstCoor_roi = dstCoor(Rect(dstx, dsty, roicols, roirows));
1201 gdst_roi = gdst(Rect(dstx, dsty, roicols, roirows)); //gdst_roi
1202 gdstCoor_roi = gdstCoor(Rect(dstx, dsty, roicols, roirows));
1206 /////////////////////////meanShiftFiltering/////////////////////////////
1207 struct meanShiftFiltering : meanShiftTestBase {};
1209 OCL_TEST_P(meanShiftFiltering, Mat)
1212 for(int j = 0; j < LOOP_TIMES; j++)
1217 gdst.download(cpu_gdst);
1219 meanShiftFiltering_(src_roi, dst_roi, sp, sr, crit);
1220 cv::ocl::meanShiftFiltering(gsrc_roi, gdst_roi, sp, sr, crit);
1222 gdst.download(cpu_gdst);
1223 EXPECT_MAT_NEAR(dst, cpu_gdst, 0.0);
1227 ///////////////////////////meanShiftProc//////////////////////////////////
1228 struct meanShiftProc : meanShiftTestBase {};
1230 OCL_TEST_P(meanShiftProc, Mat)
1233 for(int j = 0; j < LOOP_TIMES; j++)
1238 cv::Mat cpu_gdstCoor;
1240 meanShiftProc_(src_roi, dst_roi, dstCoor_roi, sp, sr, crit);
1241 cv::ocl::meanShiftProc(gsrc_roi, gdst_roi, gdstCoor_roi, sp, sr, crit);
1243 gdst.download(cpu_gdst);
1244 gdstCoor.download(cpu_gdstCoor);
1245 EXPECT_MAT_NEAR(dst, cpu_gdst, 0.0);
1246 EXPECT_MAT_NEAR(dstCoor, cpu_gdstCoor, 0.0);
1250 ///////////////////////////////////////////////////////////////////////////////////////
1252 void calcHistGold(const cv::Mat &src, cv::Mat &hist)
1254 hist.create(1, 256, CV_32SC1);
1255 hist.setTo(cv::Scalar::all(0));
1257 int *hist_row = hist.ptr<int>();
1258 for (int y = 0; y < src.rows; ++y)
1260 const uchar *src_row = src.ptr(y);
1262 for (int x = 0; x < src.cols; ++x)
1263 ++hist_row[src_row[x]];
1267 PARAM_TEST_CASE(histTestBase, MatType, MatType)
1281 //ocl dst mat, dst_hist and gdst_hist don't have roi
1282 cv::ocl::oclMat gdst_hist;
1284 cv::ocl::oclMat gsrc_roi;
1286 virtual void SetUp()
1288 type_src = GET_PARAM(0);
1290 cv::Size size = cv::Size(MWIDTH, MHEIGHT);
1292 src = randomMat(size, type_src, 0, 256, false);
1300 roicols = rng.uniform(1, src.cols);
1301 roirows = rng.uniform(1, src.rows);
1302 srcx = rng.uniform(0, src.cols - roicols);
1303 srcy = rng.uniform(0, src.rows - roirows);
1310 src_roi = src(Rect(srcx, srcy, roicols, roirows));
1315 ///////////////////////////calcHist///////////////////////////////////////
1316 struct calcHist : histTestBase {};
1318 OCL_TEST_P(calcHist, Mat)
1320 for(int j = 0; j < LOOP_TIMES; j++)
1326 calcHistGold(src_roi, dst_hist);
1327 cv::ocl::calcHist(gsrc_roi, gdst_hist);
1329 gdst_hist.download(cpu_hist);
1330 EXPECT_MAT_NEAR(dst_hist, cpu_hist, 0.0);
1333 ///////////////////////////////////////////////////////////////////////////////////////////////////////
1336 PARAM_TEST_CASE(CLAHE, cv::Size, double)
1344 cv::ocl::oclMat g_src;
1345 cv::ocl::oclMat g_dst;
1347 virtual void SetUp()
1349 gridSize = GET_PARAM(0);
1350 clipLimit = GET_PARAM(1);
1352 src = randomMat(cv::Size(MWIDTH, MHEIGHT), CV_8UC1, 0, 256, false);
1357 OCL_TEST_P(CLAHE, Accuracy)
1359 cv::Ptr<cv::CLAHE> clahe = cv::ocl::createCLAHE(clipLimit, gridSize);
1360 clahe->apply(g_src, g_dst);
1363 cv::Ptr<cv::CLAHE> clahe_gold = cv::createCLAHE(clipLimit, gridSize);
1364 clahe_gold->apply(src, dst_gold);
1366 EXPECT_MAT_NEAR(dst_gold, dst, 1.0);
1369 ///////////////////////////Convolve//////////////////////////////////
1370 PARAM_TEST_CASE(ConvolveTestBase, MatType, bool)
1377 cv::Mat dst1; //bak, for two outputs
1391 cv::Mat dst1_roi; //bak
1392 //ocl dst mat for testing
1393 cv::ocl::oclMat gdst_whole;
1394 cv::ocl::oclMat gdst1_whole; //bak
1396 cv::ocl::oclMat gmat1;
1397 cv::ocl::oclMat gmat2;
1398 cv::ocl::oclMat gdst;
1399 cv::ocl::oclMat gdst1; //bak
1400 virtual void SetUp()
1402 type = GET_PARAM(0);
1404 cv::Size size(MWIDTH, MHEIGHT);
1406 mat1 = randomMat(size, type, 5, 16, false);
1407 mat2 = randomMat(size, type, 5, 16, false);
1408 dst = randomMat(size, type, 5, 16, false);
1409 dst1 = randomMat(size, type, 5, 16, false);
1415 roicols = rng.uniform(1, mat1.cols);
1416 roirows = rng.uniform(1, mat1.rows);
1417 src1x = rng.uniform(0, mat1.cols - roicols);
1418 src1y = rng.uniform(0, mat1.rows - roirows);
1419 dstx = rng.uniform(0, dst.cols - roicols);
1420 dsty = rng.uniform(0, dst.rows - roirows);
1422 roicols = mat1.cols;
1423 roirows = mat1.rows;
1429 src2x = rng.uniform(0, mat2.cols - roicols);
1430 src2y = rng.uniform(0, mat2.rows - roirows);
1431 mat1_roi = mat1(Rect(src1x, src1y, roicols, roirows));
1432 mat2_roi = mat2(Rect(src2x, src2y, roicols, roirows));
1433 dst_roi = dst(Rect(dstx, dsty, roicols, roirows));
1434 dst1_roi = dst1(Rect(dstx, dsty, roicols, roirows));
1437 gdst = gdst_whole(Rect(dstx, dsty, roicols, roirows));
1440 gdst1 = gdst1_whole(Rect(dstx, dsty, roicols, roirows));
1448 struct Convolve : ConvolveTestBase {};
1450 void conv2( cv::Mat x, cv::Mat y, cv::Mat z)
1461 float *kerneldata = (float *)(x.data);
1462 float *srcdata = (float *)(y.data);
1463 float *dstdata = (float *)(z.data);
1465 for(i = 0; i < N2; i++)
1466 for(j = 0; j < M2; j++)
1469 for(m = 0; m < N1; m++)
1470 for(n = 0; n < M1; n++)
1473 r = min(max((i - N1 / 2 + m), 0), N2 - 1);
1474 c = min(max((j - M1 / 2 + n), 0), M2 - 1);
1475 temp += kerneldata[m * (x.step >> 2) + n] * srcdata[r * (y.step >> 2) + c];
1477 dstdata[i * (z.step >> 2) + j] = temp;
1480 OCL_TEST_P(Convolve, Mat)
1482 if(mat1.type() != CV_32FC1)
1484 cout << "\tUnsupported type\t\n";
1486 for(int j = 0; j < LOOP_TIMES; j++)
1489 cv::ocl::oclMat temp1;
1490 cv::Mat kernel_cpu = mat2(Rect(0, 0, 7, 7));
1493 conv2(kernel_cpu, mat1_roi, dst_roi);
1494 cv::ocl::convolve(gmat1, temp1, gdst);
1497 gdst_whole.download(cpu_dst);
1498 EXPECT_MAT_NEAR(dst, cpu_dst, .1);
1503 //////////////////////////////// ColumnSum //////////////////////////////////////
1504 PARAM_TEST_CASE(ColumnSum, cv::Size)
1509 virtual void SetUp()
1511 size = GET_PARAM(0);
1515 OCL_TEST_P(ColumnSum, Accuracy)
1517 cv::Mat src = randomMat(size, CV_32FC1, 0, 255);
1518 cv::ocl::oclMat d_dst;
1519 cv::ocl::oclMat d_src(src);
1521 cv::ocl::columnSum(d_src, d_dst);
1525 for (int j = 0; j < src.cols; ++j)
1527 float gold = src.at<float>(0, j);
1528 float res = dst.at<float>(0, j);
1529 ASSERT_NEAR(res, gold, 1e-5);
1532 for (int i = 1; i < src.rows; ++i)
1534 for (int j = 0; j < src.cols; ++j)
1536 float gold = src.at<float>(i, j) += src.at<float>(i - 1, j);
1537 float res = dst.at<float>(i, j);
1538 ASSERT_NEAR(res, gold, 1e-5);
1542 /////////////////////////////////////////////////////////////////////////////////////
1544 INSTANTIATE_TEST_CASE_P(ImgprocTestBase, equalizeHist, Combine(
1550 Values(false))); // Values(false) is the reserved parameter
1553 INSTANTIATE_TEST_CASE_P(ImgprocTestBase, CopyMakeBorder, Combine(
1554 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32SC1, CV_32SC3, CV_32SC4, CV_32FC1, CV_32FC3, CV_32FC4),
1556 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32SC1, CV_32SC3, CV_32SC4, CV_32FC1, CV_32FC3, CV_32FC4),
1559 Values(false))); // Values(false) is the reserved parameter
1561 INSTANTIATE_TEST_CASE_P(ImgprocTestBase, cornerMinEigenVal, Combine(
1562 Values(CV_8UC1, CV_32FC1),
1567 Values(false))); // Values(false) is the reserved parameter
1569 INSTANTIATE_TEST_CASE_P(ImgprocTestBase, cornerHarris, Combine(
1570 Values(CV_8UC1, CV_32FC1),
1575 Values(false))); // Values(false) is the reserved parameter
1578 INSTANTIATE_TEST_CASE_P(ImgprocTestBase, integral, Combine(
1584 Values(false))); // Values(false) is the reserved parameter
1586 INSTANTIATE_TEST_CASE_P(Imgproc, WarpAffine, Combine(
1587 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4),
1588 Values((MatType)cv::INTER_NEAREST, (MatType)cv::INTER_LINEAR,
1589 (MatType)cv::INTER_CUBIC, (MatType)(cv::INTER_NEAREST | cv::WARP_INVERSE_MAP),
1590 (MatType)(cv::INTER_LINEAR | cv::WARP_INVERSE_MAP), (MatType)(cv::INTER_CUBIC | cv::WARP_INVERSE_MAP))));
1593 INSTANTIATE_TEST_CASE_P(Imgproc, WarpPerspective, Combine
1594 (Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4),
1595 Values((MatType)cv::INTER_NEAREST, (MatType)cv::INTER_LINEAR,
1596 (MatType)cv::INTER_CUBIC, (MatType)(cv::INTER_NEAREST | cv::WARP_INVERSE_MAP),
1597 (MatType)(cv::INTER_LINEAR | cv::WARP_INVERSE_MAP), (MatType)(cv::INTER_CUBIC | cv::WARP_INVERSE_MAP))));
1600 INSTANTIATE_TEST_CASE_P(Imgproc, Resize, Combine(
1601 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4), Values(cv::Size()),
1602 Values(0.5, 1.5, 2), Values(0.5, 1.5, 2), Values((MatType)cv::INTER_NEAREST, (MatType)cv::INTER_LINEAR)));
1605 INSTANTIATE_TEST_CASE_P(Imgproc, Threshold, Combine(
1606 Values(CV_8UC1, CV_32FC1), Values(ThreshOp(cv::THRESH_BINARY),
1607 ThreshOp(cv::THRESH_BINARY_INV), ThreshOp(cv::THRESH_TRUNC),
1608 ThreshOp(cv::THRESH_TOZERO), ThreshOp(cv::THRESH_TOZERO_INV))));
1611 INSTANTIATE_TEST_CASE_P(Imgproc, meanShiftFiltering, Combine(
1616 Values(cv::TermCriteria(cv::TermCriteria::COUNT + cv::TermCriteria::EPS, 5, 1))
1620 INSTANTIATE_TEST_CASE_P(Imgproc, meanShiftProc, Combine(
1625 Values(cv::TermCriteria(cv::TermCriteria::COUNT + cv::TermCriteria::EPS, 5, 1))
1628 INSTANTIATE_TEST_CASE_P(Imgproc, Remap, Combine(
1629 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4),
1630 Values(CV_32FC1, CV_16SC2, CV_32FC2), Values(-1, CV_32FC1),
1631 Values((int)cv::INTER_NEAREST, (int)cv::INTER_LINEAR),
1632 Values((int)cv::BORDER_CONSTANT)));
1635 INSTANTIATE_TEST_CASE_P(histTestBase, calcHist, Combine(
1637 ONE_TYPE(CV_32SC1) //no use
1640 INSTANTIATE_TEST_CASE_P(Imgproc, CLAHE, Combine(
1641 Values(cv::Size(4, 4), cv::Size(32, 8), cv::Size(8, 64)),
1642 Values(0.0, 10.0, 62.0, 300.0)));
1644 INSTANTIATE_TEST_CASE_P(Imgproc, ColumnSum, DIFFERENT_SIZES);
1646 #endif // HAVE_OPENCL