Home | History | Annotate | Download | only in test
      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 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
     16 // Third party copyrights are property of their respective owners.
     17 //
     18 // Redistribution and use in source and binary forms, with or without modification,
     19 // are permitted provided that the following conditions are met:
     20 //
     21 //   * Redistribution's of source code must retain the above copyright notice,
     22 //     this list of conditions and the following disclaimer.
     23 //
     24 //   * Redistribution's in binary form must reproduce the above copyright notice,
     25 //     this list of conditions and the following disclaimer in the documentation
     26 //     and/or other materials provided with the distribution.
     27 //
     28 //   * The name of the copyright holders may not be used to endorse or promote products
     29 //     derived from this software without specific prior written permission.
     30 //
     31 // This software is provided by the copyright holders and contributors "as is" and
     32 // any express or implied warranties, including, but not limited to, the implied
     33 // warranties of merchantability and fitness for a particular purpose are disclaimed.
     34 // In no event shall the Intel Corporation or contributors be liable for any direct,
     35 // indirect, incidental, special, exemplary, or consequential damages
     36 // (including, but not limited to, procurement of substitute goods or services;
     37 // loss of use, data, or profits; or business interruption) however caused
     38 // and on any theory of liability, whether in contract, strict liability,
     39 // or tort (including negligence or otherwise) arising in any way out of
     40 // the use of this software, even if advised of the possibility of such damage.
     41 //
     42 //M*/
     43 
     44 #include "test_precomp.hpp"
     45 
     46 using namespace cv;
     47 using namespace cv::cuda;
     48 using namespace cv::cudev;
     49 using namespace cvtest;
     50 
     51 namespace cv {
     52 
     53 enum {
     54     COLOR_BGR2BGR = COLOR_BGR2RGB,
     55     COLOR_BGR2LRGB = COLOR_BGR2RGB,
     56     COLOR_BGR2LBGR = COLOR_BGR2RGB
     57 };
     58 
     59 }
     60 
     61 #define CVT_COLOR_TEST(src_space, dst_space, src_cn, dst_cn) \
     62     TEST(CvtColor, src_space ## _to_ ## dst_space) \
     63     { \
     64         const Size size = randomSize(100, 400); \
     65         Mat bgrb = randomMat(size, CV_8UC3); \
     66         Mat srcb; \
     67         cv::cvtColor(bgrb, srcb, COLOR_BGR ## 2 ## src_space, src_cn); \
     68         GpuMat_<SelectIf<src_cn == 1, uchar, uchar ## src_cn>::type> d_srcb(srcb); \
     69         GpuMat_<SelectIf<dst_cn == 1, uchar, uchar ## dst_cn>::type> dstb = src_space ## _to_ ## dst_space ## _(d_srcb); \
     70         Mat dstb_gold; \
     71         cv::cvtColor(srcb, dstb_gold, COLOR_ ## src_space ## 2 ## dst_space); \
     72         EXPECT_MAT_NEAR(dstb_gold, dstb, 2.0); \
     73         Mat bgrf = randomMat(size, CV_32FC3, 0, 1); \
     74         Mat srcf; \
     75         cv::cvtColor(bgrf, srcf, COLOR_BGR ## 2 ## src_space, src_cn); \
     76         GpuMat_<SelectIf<src_cn == 1, float, float ## src_cn>::type> d_srcf(srcf); \
     77         GpuMat_<SelectIf<dst_cn == 1, float, float ## dst_cn>::type> dstf = src_space ## _to_ ## dst_space ## _(d_srcf); \
     78         Mat dstf_gold; \
     79         cv::cvtColor(srcf, dstf_gold, COLOR_ ## src_space ## 2 ## dst_space); \
     80         EXPECT_MAT_NEAR(dstf_gold, dstf, 2.0); \
     81     }
     82 
     83 // RGB <-> BGR
     84 
     85 CVT_COLOR_TEST(BGR, RGB, 3, 3)
     86 CVT_COLOR_TEST(BGR, BGRA, 3, 4)
     87 CVT_COLOR_TEST(BGR, RGBA, 3, 4)
     88 CVT_COLOR_TEST(BGRA, BGR, 4, 3)
     89 CVT_COLOR_TEST(BGRA, RGB, 4, 3)
     90 CVT_COLOR_TEST(BGRA, RGBA, 4, 4)
     91 
     92 // RGB <-> Gray
     93 
     94 CVT_COLOR_TEST(BGR, GRAY, 3, 1)
     95 CVT_COLOR_TEST(RGB, GRAY, 3, 1)
     96 CVT_COLOR_TEST(BGRA, GRAY, 4, 1)
     97 CVT_COLOR_TEST(RGBA, GRAY, 4, 1)
     98 
     99 CVT_COLOR_TEST(GRAY, BGR, 1, 3)
    100 CVT_COLOR_TEST(GRAY, BGRA, 1, 4)
    101 
    102 // RGB <-> YUV
    103 
    104 CVT_COLOR_TEST(RGB, YUV, 3, 3)
    105 CVT_COLOR_TEST(BGR, YUV, 3, 3)
    106 
    107 CVT_COLOR_TEST(YUV, RGB, 3, 3)
    108 CVT_COLOR_TEST(YUV, BGR, 3, 3)
    109 
    110 // RGB <-> YCrCb
    111 
    112 CVT_COLOR_TEST(RGB, YCrCb, 3, 3)
    113 CVT_COLOR_TEST(BGR, YCrCb, 3, 3)
    114 
    115 CVT_COLOR_TEST(YCrCb, RGB, 3, 3)
    116 CVT_COLOR_TEST(YCrCb, BGR, 3, 3)
    117 
    118 // RGB <-> XYZ
    119 
    120 CVT_COLOR_TEST(RGB, XYZ, 3, 3)
    121 CVT_COLOR_TEST(BGR, XYZ, 3, 3)
    122 
    123 CVT_COLOR_TEST(XYZ, RGB, 3, 3)
    124 CVT_COLOR_TEST(XYZ, BGR, 3, 3)
    125 
    126 // RGB <-> HSV
    127 
    128 CVT_COLOR_TEST(RGB, HSV, 3, 3)
    129 CVT_COLOR_TEST(BGR, HSV, 3, 3)
    130 
    131 CVT_COLOR_TEST(HSV, RGB, 3, 3)
    132 CVT_COLOR_TEST(HSV, BGR, 3, 3)
    133 
    134 CVT_COLOR_TEST(RGB, HSV_FULL, 3, 3)
    135 CVT_COLOR_TEST(BGR, HSV_FULL, 3, 3)
    136 
    137 CVT_COLOR_TEST(HSV, RGB_FULL, 3, 3)
    138 CVT_COLOR_TEST(HSV, BGR_FULL, 3, 3)
    139 
    140 // RGB <-> HLS
    141 
    142 CVT_COLOR_TEST(RGB, HLS, 3, 3)
    143 CVT_COLOR_TEST(BGR, HLS, 3, 3)
    144 
    145 CVT_COLOR_TEST(HLS, RGB, 3, 3)
    146 CVT_COLOR_TEST(HLS, BGR, 3, 3)
    147 
    148 CVT_COLOR_TEST(RGB, HLS_FULL, 3, 3)
    149 CVT_COLOR_TEST(BGR, HLS_FULL, 3, 3)
    150 
    151 CVT_COLOR_TEST(HLS, RGB_FULL, 3, 3)
    152 CVT_COLOR_TEST(HLS, BGR_FULL, 3, 3)
    153 
    154 // RGB <-> Lab
    155 
    156 CVT_COLOR_TEST(RGB, Lab, 3, 3)
    157 CVT_COLOR_TEST(BGR, Lab, 3, 3)
    158 
    159 CVT_COLOR_TEST(Lab, RGB, 3, 3)
    160 CVT_COLOR_TEST(Lab, BGR, 3, 3)
    161 
    162 CVT_COLOR_TEST(LRGB, Lab, 3, 3)
    163 CVT_COLOR_TEST(LBGR, Lab, 3, 3)
    164 
    165 CVT_COLOR_TEST(Lab, LRGB, 3, 3)
    166 CVT_COLOR_TEST(Lab, LBGR, 3, 3)
    167 
    168 // RGB <-> Luv
    169 
    170 CVT_COLOR_TEST(RGB, Luv, 3, 3)
    171 CVT_COLOR_TEST(BGR, Luv, 3, 3)
    172 
    173 CVT_COLOR_TEST(Luv, RGB, 3, 3)
    174 CVT_COLOR_TEST(Luv, BGR, 3, 3)
    175 
    176 CVT_COLOR_TEST(LRGB, Luv, 3, 3)
    177 CVT_COLOR_TEST(LBGR, Luv, 3, 3)
    178 
    179 CVT_COLOR_TEST(Luv, LRGB, 3, 3)
    180 CVT_COLOR_TEST(Luv, LBGR, 3, 3)
    181