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, 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.
18 // Peng Xiao, pengxiao@multicorewareinc.com
20 // Redistribution and use in source and binary forms, with or without modification,
21 // are permitted provided that the following conditions are met:
23 // * Redistribution's of source code must retain the above copyright notice,
24 // this list of conditions and the following disclaimer.
26 // * Redistribution's in binary form must reproduce the above copyright notice,
27 // this list of conditions and the following disclaimer in the documentation
28 // and/or other oclMaterials provided with the distribution.
30 // * The name of the copyright holders may not be used to endorse or promote products
31 // derived from this software without specific prior written permission.
33 // This software is provided by the copyright holders and contributors as is and
34 // any express or implied warranties, including, but not limited to, the implied
35 // warranties of merchantability and fitness for a particular purpose are disclaimed.
36 // In no event shall the Intel Corporation or contributors be liable for any direct,
37 // indirect, incidental, special, exemplary, or consequential damages
38 // (including, but not limited to, procurement of substitute goods or services;
39 // loss of use, data, or profits; or business interruption) however caused
40 // and on any theory of liability, whether in contract, strict liability,
41 // or tort (including negligence or otherwise) arising in any way out of
42 // the use of this software, even if advised of the possibility of such damage.
46 #include "test_precomp.hpp"
51 #define MAT_DIFF(mat, mat2)\
53 for(int i = 0; i < mat.rows; i ++)\
55 for(int j = 0; j < mat.cols; j ++)\
57 cv::Vec4b s = mat.at<cv::Vec4b>(i, j);\
58 cv::Vec4b s2 = mat2.at<cv::Vec4b>(i, j);\
59 if(s != s2) printf("*");\
66 #define MAT_DIFF(mat, mat2)
73 ///////////////////////////////////////////////////////////////////////////////////////////////////////
75 PARAM_TEST_CASE(CvtColor, cv::Size, MatDepth)
88 img = randomMat(size, CV_MAKE_TYPE(depth, 3), 0.0, depth == CV_32F ? 1.0 : 255.0);
92 #define CVTCODE(name) cv::COLOR_ ## name
93 #define OCL_TEST_P_CVTCOLOR(name) OCL_TEST_P(CvtColor, name)\
96 cv::ocl::oclMat ocl_img, dst;\
98 cv::ocl::cvtColor(ocl_img, dst, CVTCODE(name));\
100 cv::cvtColor(src, dst_gold, CVTCODE(name));\
102 dst.download(dst_mat);\
103 EXPECT_MAT_NEAR(dst_gold, dst_mat, 1e-5);\
106 //add new ones here using macro
107 OCL_TEST_P_CVTCOLOR(RGB2GRAY)
108 OCL_TEST_P_CVTCOLOR(BGR2GRAY)
109 OCL_TEST_P_CVTCOLOR(RGBA2GRAY)
110 OCL_TEST_P_CVTCOLOR(BGRA2GRAY)
112 OCL_TEST_P_CVTCOLOR(RGB2YUV)
113 OCL_TEST_P_CVTCOLOR(BGR2YUV)
114 OCL_TEST_P_CVTCOLOR(YUV2RGB)
115 OCL_TEST_P_CVTCOLOR(YUV2BGR)
116 OCL_TEST_P_CVTCOLOR(RGB2YCrCb)
117 OCL_TEST_P_CVTCOLOR(BGR2YCrCb)
119 PARAM_TEST_CASE(CvtColor_Gray2RGB, cv::Size, MatDepth, int)
129 depth = GET_PARAM(1);
131 img = randomMat(size, CV_MAKETYPE(depth, 1), 0.0, depth == CV_32F ? 1.0 : 255.0);
134 OCL_TEST_P(CvtColor_Gray2RGB, Accuracy)
137 cv::ocl::oclMat ocl_img, dst;
139 cv::ocl::cvtColor(ocl_img, dst, code);
141 cv::cvtColor(src, dst_gold, code);
143 dst.download(dst_mat);
144 EXPECT_MAT_NEAR(dst_gold, dst_mat, 1e-5);
148 PARAM_TEST_CASE(CvtColor_YUV420, cv::Size, int)
159 img = randomMat(size, CV_8UC1, 0.0, 255.0);
163 OCL_TEST_P(CvtColor_YUV420, Accuracy)
166 cv::ocl::oclMat ocl_img, dst;
168 cv::ocl::cvtColor(ocl_img, dst, code);
170 cv::cvtColor(src, dst_gold, code);
172 dst.download(dst_mat);
173 MAT_DIFF(dst_mat, dst_gold);
174 EXPECT_MAT_NEAR(dst_gold, dst_mat, 1e-5);
177 INSTANTIATE_TEST_CASE_P(OCL_ImgProc, CvtColor, testing::Combine(
179 testing::Values(MatDepth(CV_8U), MatDepth(CV_16U), MatDepth(CV_32F))
182 INSTANTIATE_TEST_CASE_P(OCL_ImgProc, CvtColor_YUV420, testing::Combine(
183 testing::Values(cv::Size(128, 45), cv::Size(46, 132), cv::Size(1024, 1023)),
184 testing::Values((int)CV_YUV2RGBA_NV12, (int)CV_YUV2BGRA_NV12, (int)CV_YUV2RGB_NV12, (int)CV_YUV2BGR_NV12)
187 INSTANTIATE_TEST_CASE_P(OCL_ImgProc, CvtColor_Gray2RGB, testing::Combine(
189 testing::Values(MatDepth(CV_8U), MatDepth(CV_16U), MatDepth(CV_32F)),
190 testing::Values((int)CV_GRAY2BGR, (int)CV_GRAY2BGRA, (int)CV_GRAY2RGB, (int)CV_GRAY2RGBA)