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 "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);
110 void showDiff(InputArray gold_, InputArray actual_, double eps)
113 if (gold_.kind() == _InputArray::MAT)
114 gold = gold_.getMat();
116 gold_.getGpuMat().download(gold);
119 if (actual_.kind() == _InputArray::MAT)
120 actual = actual_.getMat();
122 actual_.getGpuMat().download(actual);
125 absdiff(gold, actual, diff);
126 threshold(diff, diff, eps, 255.0, cv::THRESH_BINARY);
128 namedWindow("gold", WINDOW_NORMAL);
129 namedWindow("actual", WINDOW_NORMAL);
130 namedWindow("diff", WINDOW_NORMAL);
132 imshow("gold", gold);
133 imshow("actual", actual);
134 imshow("diff", diff);
141 bool supportFeature(const DeviceInfo& info, FeatureSet feature)
143 return TargetArchs::builtWith(feature) && info.supports(feature);
146 const vector<DeviceInfo>& devices()
148 static vector<DeviceInfo> devs;
149 static bool first = true;
153 int deviceCount = getCudaEnabledDeviceCount();
155 devs.reserve(deviceCount);
157 for (int i = 0; i < deviceCount; ++i)
160 if (info.isCompatible())
161 devs.push_back(info);
170 vector<DeviceInfo> devices(FeatureSet feature)
172 const vector<DeviceInfo>& d = devices();
174 vector<DeviceInfo> devs_filtered;
176 if (TargetArchs::builtWith(feature))
178 devs_filtered.reserve(d.size());
180 for (size_t i = 0, size = d.size(); i < size; ++i)
182 const DeviceInfo& info = d[i];
184 if (info.supports(feature))
185 devs_filtered.push_back(info);
189 return devs_filtered;
193 vector<MatType> types(int depth_start, int depth_end, int cn_start, int cn_end)
197 v.reserve((depth_end - depth_start + 1) * (cn_end - cn_start + 1));
199 for (int depth = depth_start; depth <= depth_end; ++depth)
201 for (int cn = cn_start; cn <= cn_end; ++cn)
203 v.push_back(CV_MAKETYPE(depth, cn));
210 const vector<MatType> &all_types()
212 static vector<MatType> v = types(CV_8U, CV_64F, 1, 4);
217 Mat readImage(const string &fileName, int flags)
219 return imread(string(cvtest::TS::ptr()->get_data_path()) + fileName, flags);
222 Mat readImageType(const string &fname, int type)
224 Mat src = readImage(fname, CV_MAT_CN(type) == 1 ? IMREAD_GRAYSCALE : IMREAD_COLOR);
225 if (CV_MAT_CN(type) == 4)
228 cvtColor(src, temp, cv::COLOR_BGR2BGRA);
231 src.convertTo(src, CV_MAT_DEPTH(type));
235 double checkNorm(const Mat &m)
237 return norm(m, NORM_INF);
240 double checkNorm(const Mat &m1, const Mat &m2)
242 return norm(m1, m2, NORM_INF);
245 double checkSimilarity(const Mat &m1, const Mat &m2)
248 matchTemplate(m1, m2, diff, CV_TM_CCORR_NORMED);
249 return std::abs(diff.at<float>(0, 0) - 1.f);
253 void cv::ocl::PrintTo(const DeviceInfo& info, ostream* os)
255 (*os) << info.name();
259 void PrintTo(const Inverse &inverse, std::ostream *os)