1 /*M///////////////////////////////////////////////////////////////////////////////////////
\r
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
\r
5 // By downloading, copying, installing or using the software you agree to this license.
\r
6 // If you do not agree to this license, do not download, install,
\r
7 // copy or use the software.
\r
10 // Intel License Agreement
\r
11 // For Open Source Computer Vision Library
\r
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
\r
14 // Third party copyrights are property of their respective owners.
\r
16 // Redistribution and use in source and binary forms, with or without modification,
\r
17 // are permitted provided that the following conditions are met:
\r
19 // * Redistribution's of source code must retain the above copyright notice,
\r
20 // this list of conditions and the following disclaimer.
\r
22 // * Redistribution's in binary form must reproduce the above copyright notice,
\r
23 // this list of conditions and the following disclaimer in the documentation
\r
24 // and/or other materials provided with the distribution.
\r
26 // * The name of Intel Corporation may not be used to endorse or promote products
\r
27 // derived from this software without specific prior written permission.
\r
29 // This software is provided by the copyright holders and contributors "as is" and
\r
30 // any express or implied warranties, including, but not limited to, the implied
\r
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
\r
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
\r
33 // indirect, incidental, special, exemplary, or consequential damages
\r
34 // (including, but not limited to, procurement of substitute goods or services;
\r
35 // loss of use, data, or profits; or business interruption) however caused
\r
36 // and on any theory of liability, whether in contract, strict liability,
\r
37 // or tort (including negligence or otherwise) arising in any way out of
\r
38 // the use of this software, even if advised of the possibility of such damage.
\r
42 #ifndef __OPENCV_TEST_UTILITY_HPP__
\r
43 #define __OPENCV_TEST_UTILITY_HPP__
\r
47 #include "opencv2/core/core.hpp"
\r
48 #include "opencv2/highgui/highgui.hpp"
\r
49 #include "opencv2/gpu/gpu.hpp"
\r
50 #include "opencv2/ts/ts.hpp"
\r
51 #include "opencv2/ts/ts_perf.hpp"
\r
53 //////////////////////////////////////////////////////////////////////
\r
54 // random generators
\r
56 int randomInt(int minVal, int maxVal);
\r
57 double randomDouble(double minVal, double maxVal);
\r
58 cv::Size randomSize(int minVal, int maxVal);
\r
59 cv::Scalar randomScalar(double minVal, double maxVal);
\r
60 cv::Mat randomMat(cv::Size size, int type, double minVal = 0.0, double maxVal = 255.0);
\r
62 //////////////////////////////////////////////////////////////////////
\r
65 cv::gpu::GpuMat createMat(cv::Size size, int type, bool useRoi = false);
\r
66 cv::gpu::GpuMat loadMat(const cv::Mat& m, bool useRoi = false);
\r
68 //////////////////////////////////////////////////////////////////////
\r
71 //! read image from testdata folder
\r
72 cv::Mat readImage(const std::string& fileName, int flags = cv::IMREAD_COLOR);
\r
74 //! read image from testdata folder and convert it to specified type
\r
75 cv::Mat readImageType(const std::string& fname, int type);
\r
77 //////////////////////////////////////////////////////////////////////
\r
80 //! return true if device supports specified feature and gpu module was built with support the feature.
\r
81 bool supportFeature(const cv::gpu::DeviceInfo& info, cv::gpu::FeatureSet feature);
\r
86 static DeviceManager& instance();
\r
91 const std::vector<cv::gpu::DeviceInfo>& values() const { return devices_; }
\r
94 std::vector<cv::gpu::DeviceInfo> devices_;
\r
97 #define ALL_DEVICES testing::ValuesIn(DeviceManager::instance().values())
\r
99 //////////////////////////////////////////////////////////////////////
\r
100 // Additional assertion
\r
102 cv::Mat getMat(cv::InputArray arr);
\r
104 double checkNorm(cv::InputArray m1, cv::InputArray m2);
\r
106 void minMaxLocGold(const cv::Mat& src, double* minVal_, double* maxVal_ = 0, cv::Point* minLoc_ = 0, cv::Point* maxLoc_ = 0, const cv::Mat& mask = cv::Mat());
\r
108 testing::AssertionResult assertMatNear(const char* expr1, const char* expr2, const char* eps_expr, cv::InputArray m1, cv::InputArray m2, double eps);
\r
110 #define EXPECT_MAT_NEAR(m1, m2, eps) EXPECT_PRED_FORMAT3(assertMatNear, m1, m2, eps)
\r
111 #define ASSERT_MAT_NEAR(m1, m2, eps) ASSERT_PRED_FORMAT3(assertMatNear, m1, m2, eps)
\r
113 #define EXPECT_SCALAR_NEAR(s1, s2, eps) \
\r
115 EXPECT_NEAR(s1[0], s2[0], eps); \
\r
116 EXPECT_NEAR(s1[1], s2[1], eps); \
\r
117 EXPECT_NEAR(s1[2], s2[2], eps); \
\r
118 EXPECT_NEAR(s1[3], s2[3], eps); \
\r
120 #define ASSERT_SCALAR_NEAR(s1, s2, eps) \
\r
122 ASSERT_NEAR(s1[0], s2[0], eps); \
\r
123 ASSERT_NEAR(s1[1], s2[1], eps); \
\r
124 ASSERT_NEAR(s1[2], s2[2], eps); \
\r
125 ASSERT_NEAR(s1[3], s2[3], eps); \
\r
128 #define EXPECT_POINT2_NEAR(p1, p2, eps) \
\r
130 EXPECT_NEAR(p1.x, p2.x, eps); \
\r
131 EXPECT_NEAR(p1.y, p2.y, eps); \
\r
133 #define ASSERT_POINT2_NEAR(p1, p2, eps) \
\r
135 ASSERT_NEAR(p1.x, p2.x, eps); \
\r
136 ASSERT_NEAR(p1.y, p2.y, eps); \
\r
139 #define EXPECT_POINT3_NEAR(p1, p2, eps) \
\r
141 EXPECT_NEAR(p1.x, p2.x, eps); \
\r
142 EXPECT_NEAR(p1.y, p2.y, eps); \
\r
143 EXPECT_NEAR(p1.z, p2.z, eps); \
\r
145 #define ASSERT_POINT3_NEAR(p1, p2, eps) \
\r
147 ASSERT_NEAR(p1.x, p2.x, eps); \
\r
148 ASSERT_NEAR(p1.y, p2.y, eps); \
\r
149 ASSERT_NEAR(p1.z, p2.z, eps); \
\r
152 double checkSimilarity(cv::InputArray m1, cv::InputArray m2);
\r
154 #define EXPECT_MAT_SIMILAR(mat1, mat2, eps) \
\r
156 ASSERT_EQ(mat1.type(), mat2.type()); \
\r
157 ASSERT_EQ(mat1.size(), mat2.size()); \
\r
158 EXPECT_LE(checkSimilarity(mat1, mat2), eps); \
\r
160 #define ASSERT_MAT_SIMILAR(mat1, mat2, eps) \
\r
162 ASSERT_EQ(mat1.type(), mat2.type()); \
\r
163 ASSERT_EQ(mat1.size(), mat2.size()); \
\r
164 ASSERT_LE(checkSimilarity(mat1, mat2), eps); \
\r
167 //////////////////////////////////////////////////////////////////////
\r
168 // Helper structs for value-parameterized tests
\r
170 #define PARAM_TEST_CASE(name, ...) struct name : testing::TestWithParam< std::tr1::tuple< __VA_ARGS__ > >
\r
171 #define GET_PARAM(k) std::tr1::get< k >(GetParam())
\r
173 namespace cv { namespace gpu
\r
175 void PrintTo(const DeviceInfo& info, std::ostream* os);
\r
178 #define DIFFERENT_SIZES testing::Values(cv::Size(128, 128), cv::Size(113, 113))
\r
182 using perf::MatDepth;
\r
184 //! return vector with depths from specified range.
\r
185 std::vector<MatDepth> depths(int depth_start, int depth_end);
\r
187 #define ALL_DEPTH testing::Values(MatDepth(CV_8U), MatDepth(CV_8S), MatDepth(CV_16U), MatDepth(CV_16S), MatDepth(CV_32S), MatDepth(CV_32F), MatDepth(CV_64F))
\r
188 #define DEPTHS(depth_start, depth_end) testing::ValuesIn(depths(depth_start, depth_end))
\r
189 #define DEPTH_PAIRS testing::Values(std::make_pair(MatDepth(CV_8U), MatDepth(CV_8U)), \
\r
190 std::make_pair(MatDepth(CV_8U), MatDepth(CV_16U)), \
\r
191 std::make_pair(MatDepth(CV_8U), MatDepth(CV_16S)), \
\r
192 std::make_pair(MatDepth(CV_8U), MatDepth(CV_32S)), \
\r
193 std::make_pair(MatDepth(CV_8U), MatDepth(CV_32F)), \
\r
194 std::make_pair(MatDepth(CV_8U), MatDepth(CV_64F)), \
\r
196 std::make_pair(MatDepth(CV_16U), MatDepth(CV_16U)), \
\r
197 std::make_pair(MatDepth(CV_16U), MatDepth(CV_32S)), \
\r
198 std::make_pair(MatDepth(CV_16U), MatDepth(CV_32F)), \
\r
199 std::make_pair(MatDepth(CV_16U), MatDepth(CV_64F)), \
\r
201 std::make_pair(MatDepth(CV_16S), MatDepth(CV_16S)), \
\r
202 std::make_pair(MatDepth(CV_16S), MatDepth(CV_32S)), \
\r
203 std::make_pair(MatDepth(CV_16S), MatDepth(CV_32F)), \
\r
204 std::make_pair(MatDepth(CV_16S), MatDepth(CV_64F)), \
\r
206 std::make_pair(MatDepth(CV_32S), MatDepth(CV_32S)), \
\r
207 std::make_pair(MatDepth(CV_32S), MatDepth(CV_32F)), \
\r
208 std::make_pair(MatDepth(CV_32S), MatDepth(CV_64F)), \
\r
210 std::make_pair(MatDepth(CV_32F), MatDepth(CV_32F)), \
\r
211 std::make_pair(MatDepth(CV_32F), MatDepth(CV_64F)), \
\r
213 std::make_pair(MatDepth(CV_64F), MatDepth(CV_64F)))
\r
217 using perf::MatType;
\r
219 //! return vector with types from specified range.
\r
220 std::vector<MatType> types(int depth_start, int depth_end, int cn_start, int cn_end);
\r
222 //! return vector with all types (depth: CV_8U-CV_64F, channels: 1-4).
\r
223 const std::vector<MatType>& all_types();
\r
225 #define ALL_TYPES testing::ValuesIn(all_types())
\r
226 #define TYPES(depth_start, depth_end, cn_start, cn_end) testing::ValuesIn(types(depth_start, depth_end, cn_start, cn_end))
\r
233 inline UseRoi(bool val = false) : val_(val) {}
\r
235 inline operator bool() const { return val_; }
\r
241 void PrintTo(const UseRoi& useRoi, std::ostream* os);
\r
243 #define WHOLE testing::Values(UseRoi(false))
\r
244 #define SUBMAT testing::Values(UseRoi(true))
\r
245 #define WHOLE_SUBMAT testing::Values(UseRoi(false), UseRoi(true))
\r
252 inline Inverse(bool val = false) : val_(val) {}
\r
254 inline operator bool() const { return val_; }
\r
259 void PrintTo(const Inverse& useRoi, std::ostream* os);
\r
260 #define DIRECT_INVERSE testing::Values(Inverse(false), Inverse(true))
\r
264 #define IMPLEMENT_PARAM_CLASS(name, type) \
\r
268 name ( type arg = type ()) : val_(arg) {} \
\r
269 operator type () const {return val_;} \
\r
273 inline void PrintTo( name param, std::ostream* os) \
\r
275 *os << #name << "(" << testing::PrintToString(static_cast< type >(param)) << ")"; \
\r
278 IMPLEMENT_PARAM_CLASS(Channels, int)
\r
280 #define ALL_CHANNELS testing::Values(Channels(1), Channels(2), Channels(3), Channels(4))
\r
281 #define IMAGE_CHANNELS testing::Values(Channels(1), Channels(3), Channels(4))
\r
285 CV_ENUM(NormCode, cv::NORM_INF, cv::NORM_L1, cv::NORM_L2, cv::NORM_TYPE_MASK, cv::NORM_RELATIVE, cv::NORM_MINMAX)
\r
287 CV_ENUM(Interpolation, cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_CUBIC, cv::INTER_AREA)
\r
289 CV_ENUM(BorderType, cv::BORDER_REFLECT101, cv::BORDER_REPLICATE, cv::BORDER_CONSTANT, cv::BORDER_REFLECT, cv::BORDER_WRAP)
\r
290 #define ALL_BORDER_TYPES testing::Values(BorderType(cv::BORDER_REFLECT101), BorderType(cv::BORDER_REPLICATE), BorderType(cv::BORDER_CONSTANT), BorderType(cv::BORDER_REFLECT), BorderType(cv::BORDER_WRAP))
\r
292 CV_FLAGS(WarpFlags, cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_CUBIC, cv::WARP_INVERSE_MAP)
\r
294 //////////////////////////////////////////////////////////////////////
\r
297 void showDiff(cv::InputArray gold, cv::InputArray actual, double eps);
\r
299 #endif // __OPENCV_TEST_UTILITY_HPP__
\r