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.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
42 #include "test_precomp.hpp"
46 using namespace cv::gpu;
47 using namespace cvtest;
50 //std::string generateVarList(int first,...)
52 // vector<std::string> varname;
57 // va_start(argp,first);
62 // i=va_arg(argp,int);
69 //std::string generateVarList(int& p1,int& p2)
72 // ss<<VARNAME(p1)<<":"<<src1x<<","<<VARNAME(p2)<<":"<<src1y;
76 int randomInt(int minVal, int maxVal)
78 RNG &rng = TS::ptr()->get_rng();
79 return rng.uniform(minVal, maxVal);
82 double randomDouble(double minVal, double maxVal)
84 RNG &rng = TS::ptr()->get_rng();
85 return rng.uniform(minVal, maxVal);
88 Size randomSize(int minVal, int maxVal)
90 return cv::Size(randomInt(minVal, maxVal), randomInt(minVal, maxVal));
93 Scalar randomScalar(double minVal, double maxVal)
95 return Scalar(randomDouble(minVal, maxVal), randomDouble(minVal, maxVal), randomDouble(minVal, maxVal), randomDouble(minVal, maxVal));
98 Mat randomMat(Size size, int type, double minVal, double maxVal)
100 return randomMat(TS::ptr()->get_rng(), size, type, minVal, maxVal, false);
104 void showDiff(InputArray gold_, InputArray actual_, double eps)
107 if (gold_.kind() == _InputArray::MAT)
108 gold = gold_.getMat();
110 gold_.getGpuMat().download(gold);
113 if (actual_.kind() == _InputArray::MAT)
114 actual = actual_.getMat();
116 actual_.getGpuMat().download(actual);
119 absdiff(gold, actual, diff);
120 threshold(diff, diff, eps, 255.0, cv::THRESH_BINARY);
122 namedWindow("gold", WINDOW_NORMAL);
123 namedWindow("actual", WINDOW_NORMAL);
124 namedWindow("diff", WINDOW_NORMAL);
126 imshow("gold", gold);
127 imshow("actual", actual);
128 imshow("diff", diff);
136 vector<MatType> types(int depth_start, int depth_end, int cn_start, int cn_end)
140 v.reserve((depth_end - depth_start + 1) * (cn_end - cn_start + 1));
142 for (int depth = depth_start; depth <= depth_end; ++depth)
144 for (int cn = cn_start; cn <= cn_end; ++cn)
146 v.push_back(CV_MAKETYPE(depth, cn));
153 const vector<MatType> &all_types()
155 static vector<MatType> v = types(CV_8U, CV_64F, 1, 4);
160 Mat readImage(const string &fileName, int flags)
162 return imread(string(cvtest::TS::ptr()->get_data_path()) + fileName, flags);
165 Mat readImageType(const string &fname, int type)
167 Mat src = readImage(fname, CV_MAT_CN(type) == 1 ? IMREAD_GRAYSCALE : IMREAD_COLOR);
168 if (CV_MAT_CN(type) == 4)
171 cvtColor(src, temp, cv::COLOR_BGR2BGRA);
174 src.convertTo(src, CV_MAT_DEPTH(type));
178 double checkNorm(const Mat &m)
180 return norm(m, NORM_INF);
183 double checkNorm(const Mat &m1, const Mat &m2)
185 return norm(m1, m2, NORM_INF);
188 double checkSimilarity(const Mat &m1, const Mat &m2)
191 matchTemplate(m1, m2, diff, CV_TM_CCORR_NORMED);
192 return std::abs(diff.at<float>(0, 0) - 1.f);
196 void cv::ocl::PrintTo(const DeviceInfo& info, ostream* os)
198 (*os) << info.name();
202 void PrintTo(const Inverse &inverse, std::ostream *os)
210 double checkRectSimilarity(Size sz, std::vector<Rect>& ob1, std::vector<Rect>& ob2)
212 double final_test_result = 0.0;
213 size_t sz1 = ob1.size();
214 size_t sz2 = ob2.size();
218 return sz1 > sz2 ? (double)(sz1 - sz2) : (double)(sz2 - sz1);
224 cv::Mat cpu_result(sz, CV_8UC1);
227 for(vector<Rect>::const_iterator r = ob1.begin(); r != ob1.end(); r++)
229 cv::Mat cpu_result_roi(cpu_result, *r);
230 cpu_result_roi.setTo(1);
231 cpu_result.copyTo(cpu_result);
233 int cpu_area = cv::countNonZero(cpu_result > 0);
235 cv::Mat gpu_result(sz, CV_8UC1);
237 for(vector<Rect>::const_iterator r2 = ob2.begin(); r2 != ob2.end(); r2++)
239 cv::Mat gpu_result_roi(gpu_result, *r2);
240 gpu_result_roi.setTo(1);
241 gpu_result.copyTo(gpu_result);
245 multiply(cpu_result, gpu_result, result_);
246 int result = cv::countNonZero(result_ > 0);
247 if(cpu_area!=0 && result!=0)
248 final_test_result = 1.0 - (double)result/(double)cpu_area;
249 else if(cpu_area==0 && result!=0)
250 final_test_result = -1;
252 return final_test_result;