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-2013, Advanced Micro Devices, Inc., 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 the copyright holders 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 OpenCV Foundation 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"
44 #include "opencv2/ts/ocl_test.hpp"
48 #define DUMP_CONFIG_PROPERTY(propertyName, propertyValue) \
50 std::stringstream ssName, ssValue;\
51 ssName << propertyName;\
52 ssValue << (propertyValue); \
53 ::testing::Test::RecordProperty(ssName.str(), ssValue.str()); \
56 #define DUMP_MESSAGE_STDOUT(msg) \
58 std::cout << msg << std::endl; \
61 #include <opencv2/core/opencl/opencl_info.hpp>
70 int test_loop_times = 1; // TODO Read from command line / environment
73 void dumpOpenCLDevice()
75 cv::dumpOpenCLInformation();
79 Mat TestUtils::readImage(const String &fileName, int flags)
81 return cv::imread(cvtest::TS::ptr()->get_data_path() + fileName, flags);
84 Mat TestUtils::readImageType(const String &fname, int type)
86 Mat src = readImage(fname, CV_MAT_CN(type) == 1 ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR);
87 if (CV_MAT_CN(type) == 4)
90 cv::cvtColor(src, temp, cv::COLOR_BGR2BGRA);
93 src.convertTo(src, CV_MAT_DEPTH(type));
97 double TestUtils::checkNorm1(InputArray m, InputArray mask)
99 return cvtest::norm(m.getMat(), NORM_INF, mask.getMat());
102 double TestUtils::checkNorm2(InputArray m1, InputArray m2, InputArray mask)
104 return cvtest::norm(m1.getMat(), m2.getMat(), NORM_INF, mask.getMat());
107 double TestUtils::checkSimilarity(InputArray m1, InputArray m2)
110 matchTemplate(m1.getMat(), m2.getMat(), diff, CV_TM_CCORR_NORMED);
111 return std::abs(diff.at<float>(0, 0) - 1.f);
114 double TestUtils::checkRectSimilarity(const Size & sz, std::vector<Rect>& ob1, std::vector<Rect>& ob2)
116 double final_test_result = 0.0;
117 size_t sz1 = ob1.size();
118 size_t sz2 = ob2.size();
121 return sz1 > sz2 ? (double)(sz1 - sz2) : (double)(sz2 - sz1);
124 if (sz1 == 0 && sz2 == 0)
126 cv::Mat cpu_result(sz, CV_8UC1);
129 for (vector<Rect>::const_iterator r = ob1.begin(); r != ob1.end(); ++r)
131 cv::Mat cpu_result_roi(cpu_result, *r);
132 cpu_result_roi.setTo(1);
133 cpu_result.copyTo(cpu_result);
135 int cpu_area = cv::countNonZero(cpu_result > 0);
137 cv::Mat gpu_result(sz, CV_8UC1);
139 for(vector<Rect>::const_iterator r2 = ob2.begin(); r2 != ob2.end(); ++r2)
141 cv::Mat gpu_result_roi(gpu_result, *r2);
142 gpu_result_roi.setTo(1);
143 gpu_result.copyTo(gpu_result);
147 multiply(cpu_result, gpu_result, result_);
148 int result = cv::countNonZero(result_ > 0);
149 if (cpu_area!=0 && result!=0)
150 final_test_result = 1.0 - (double)result/(double)cpu_area;
151 else if(cpu_area==0 && result!=0)
152 final_test_result = -1;
154 return final_test_result;
157 void TestUtils::showDiff(InputArray _src, InputArray _gold, InputArray _actual, double eps, bool alwaysShow)
159 Mat src = _src.getMat(), actual = _actual.getMat(), gold = _gold.getMat();
161 Mat diff, diff_thresh;
162 absdiff(gold, actual, diff);
163 diff.convertTo(diff, CV_32F);
164 threshold(diff, diff_thresh, eps, 255.0, cv::THRESH_BINARY);
166 if (alwaysShow || cv::countNonZero(diff_thresh.reshape(1)) > 0)
169 std::cout << "Source: " << std::endl << src << std::endl;
170 std::cout << "Expected: " << std::endl << gold << std::endl;
171 std::cout << "Actual: " << std::endl << actual << std::endl;
174 namedWindow("src", WINDOW_NORMAL);
175 namedWindow("gold", WINDOW_NORMAL);
176 namedWindow("actual", WINDOW_NORMAL);
177 namedWindow("diff", WINDOW_NORMAL);
180 imshow("gold", gold);
181 imshow("actual", actual);
182 imshow("diff", diff);
188 } } // namespace cvtest::ocl