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 #ifndef __OPENCV_TEST_UTILITY_HPP__
43 #define __OPENCV_TEST_UTILITY_HPP__
48 int randomInt(int minVal, int maxVal);
49 double randomDouble(double minVal, double maxVal);
50 //std::string generateVarList(int first,...);
51 std::string generateVarList(int &p1, int &p2);
52 cv::Size randomSize(int minVal, int maxVal);
53 cv::Scalar randomScalar(double minVal, double maxVal);
54 cv::Mat randomMat(cv::Size size, int type, double minVal = 0.0, double maxVal = 255.0);
56 void showDiff(cv::InputArray gold, cv::InputArray actual, double eps);
58 //! return true if device supports specified feature and gpu module was built with support the feature.
59 //bool supportFeature(const cv::gpu::DeviceInfo& info, cv::gpu::FeatureSet feature);
61 //! return all devices compatible with current gpu module build.
62 //const std::vector<cv::ocl::DeviceInfo>& devices();
63 //! return all devices compatible with current gpu module build which support specified feature.
64 //std::vector<cv::ocl::DeviceInfo> devices(cv::gpu::FeatureSet feature);
66 //! read image from testdata folder.
67 cv::Mat readImage(const std::string &fileName, int flags = cv::IMREAD_COLOR);
68 cv::Mat readImageType(const std::string &fname, int type);
70 double checkNorm(const cv::Mat &m);
71 double checkNorm(const cv::Mat &m1, const cv::Mat &m2);
72 double checkSimilarity(const cv::Mat &m1, const cv::Mat &m2);
74 #define EXPECT_MAT_NORM(mat, eps) \
76 EXPECT_LE(checkNorm(cv::Mat(mat)), eps) \
79 #define EXPECT_MAT_NEAR(mat1, mat2, eps) \
81 ASSERT_EQ(mat1.type(), mat2.type()); \
82 ASSERT_EQ(mat1.size(), mat2.size()); \
83 EXPECT_LE(checkNorm(cv::Mat(mat1), cv::Mat(mat2)), eps); \
86 #define EXPECT_MAT_NEAR(mat1, mat2, eps,s) \
88 ASSERT_EQ(mat1.type(), mat2.type()); \
89 ASSERT_EQ(mat1.size(), mat2.size()); \
90 EXPECT_LE(checkNorm(cv::Mat(mat1), cv::Mat(mat2)), eps)<<s; \
93 #define EXPECT_MAT_SIMILAR(mat1, mat2, eps) \
95 ASSERT_EQ(mat1.type(), mat2.type()); \
96 ASSERT_EQ(mat1.size(), mat2.size()); \
97 EXPECT_LE(checkSimilarity(cv::Mat(mat1), cv::Mat(mat2)), eps); \
104 // void PrintTo(const DeviceInfo& info, std::ostream* os);
108 using perf::MatDepth;
111 //! return vector with types from specified range.
112 std::vector<MatType> types(int depth_start, int depth_end, int cn_start, int cn_end);
114 //! return vector with all types (depth: CV_8U-CV_64F, channels: 1-4).
115 const std::vector<MatType> &all_types();
120 inline Inverse(bool val = false) : val_(val) {}
122 inline operator bool() const
131 void PrintTo(const Inverse &useRoi, std::ostream *os);
133 enum {FLIP_BOTH = 0, FLIP_X = 1, FLIP_Y = -1};
134 CV_ENUM(FlipCode, FLIP_BOTH, FLIP_X, FLIP_Y)
136 CV_ENUM(CmpCode, CMP_EQ, CMP_GT, CMP_GE, CMP_LT, CMP_LE, CMP_NE)
137 CV_ENUM(NormCode, NORM_INF, NORM_L1, NORM_L2, NORM_TYPE_MASK, NORM_RELATIVE, NORM_MINMAX)
138 CV_ENUM(ReduceOp, CV_REDUCE_SUM, CV_REDUCE_AVG, CV_REDUCE_MAX, CV_REDUCE_MIN)
139 CV_ENUM(MorphOp, MORPH_OPEN, MORPH_CLOSE, MORPH_GRADIENT, MORPH_TOPHAT, MORPH_BLACKHAT)
140 CV_ENUM(ThreshOp, THRESH_BINARY, THRESH_BINARY_INV, THRESH_TRUNC, THRESH_TOZERO, THRESH_TOZERO_INV)
141 CV_ENUM(Interpolation, INTER_NEAREST, INTER_LINEAR, INTER_CUBIC)
142 CV_ENUM(Border, BORDER_REFLECT101, BORDER_REPLICATE, BORDER_CONSTANT, BORDER_REFLECT, BORDER_WRAP)
143 CV_ENUM(TemplateMethod, TM_SQDIFF, TM_SQDIFF_NORMED, TM_CCORR, TM_CCORR_NORMED, TM_CCOEFF, TM_CCOEFF_NORMED)
145 CV_FLAGS(GemmFlags, GEMM_1_T, GEMM_2_T, GEMM_3_T);
146 CV_FLAGS(WarpFlags, INTER_NEAREST, INTER_LINEAR, INTER_CUBIC, WARP_INVERSE_MAP)
147 CV_FLAGS(DftFlags, DFT_INVERSE, DFT_SCALE, DFT_ROWS, DFT_COMPLEX_OUTPUT, DFT_REAL_OUTPUT)
149 void run_perf_test();
151 #define PARAM_TEST_CASE(name, ...) struct name : testing::TestWithParam< std::tr1::tuple< __VA_ARGS__ > >
153 #define GET_PARAM(k) std::tr1::get< k >(GetParam())
155 #define ALL_DEVICES testing::ValuesIn(devices())
156 #define DEVICES(feature) testing::ValuesIn(devices(feature))
158 #define ALL_TYPES testing::ValuesIn(all_types())
159 #define TYPES(depth_start, depth_end, cn_start, cn_end) testing::ValuesIn(types(depth_start, depth_end, cn_start, cn_end))
161 #define DIFFERENT_SIZES testing::Values(cv::Size(128, 128), cv::Size(113, 113), cv::Size(1300, 1300))
163 #define DIRECT_INVERSE testing::Values(Inverse(false), Inverse(true))
166 #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))
169 #define COUNT_U 0 // count the uploading execution time for ocl mat structures
171 // the following macro section tests the target function (kernel) performance
172 // upload is the code snippet for converting cv::mat to cv::ocl::oclMat
173 // downloading is the code snippet for converting cv::ocl::oclMat back to cv::mat
174 // change COUNT_U and COUNT_D to take downloading and uploading time into account
175 #define P_TEST_FULL( upload, kernel_call, download ) \
177 std::cout<< "\n" #kernel_call "\n----------------------"; \
179 R_TEST( kernel_call, 2 ); \
180 double t = (double)cvGetTickCount(); \
182 if( COUNT_U ) {upload;} \
184 if( COUNT_D ) {download;} \
186 t = (double)cvGetTickCount() - t; \
187 std::cout << "runtime is " << t/((double)cvGetTickFrequency()* 1000.) << "ms" << std::endl; \
190 #define R_T2( test ) \
192 std::cout<< "\n" #test "\n----------------------"; \
194 clock_t st = clock(); \
196 std::cout<< clock() - st << "ms\n"; \
198 #define R_T( test ) \
199 R_TEST( test, REPEAT )
200 #define R_TEST( test, repeat ) \
202 for( int i = 0; i < repeat; i ++ ) { test; } \
203 } catch( ... ) { std::cout << "||||| Exception catched! |||||\n"; return; }
207 #define IMAGE_CHANNELS testing::Values(Channels(1), Channels(3), Channels(4))
208 #ifndef IMPLEMENT_PARAM_CLASS
209 #define IMPLEMENT_PARAM_CLASS(name, type) \
213 name ( type arg = type ()) : val_(arg) {} \
214 operator type () const {return val_;} \
218 inline void PrintTo( name param, std::ostream* os) \
220 *os << #name << "(" << testing::PrintToString(static_cast< type >(param)) << ")"; \
223 IMPLEMENT_PARAM_CLASS(Channels, int)
224 #endif // IMPLEMENT_PARAM_CLASS
226 #endif // __OPENCV_TEST_UTILITY_HPP__