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) 2000-2008, Intel Corporation, all rights reserved.
14
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15
// Third party copyrights are property of their respective owners.
17
// Redistribution and use in source and binary forms, with or without modification,
18
// are permitted provided that the following conditions are met:
20
// * Redistribution's of source code must retain the above copyright notice,
21
// this list of conditions and the following disclaimer.
23
// * Redistribution's in binary form must reproduce the above copyright notice,
24
// this list of conditions and the following disclaimer in the documentation
25
// and/or other materials provided with the distribution.
27
// * The name of the copyright holders may not be used to endorse or promote products
28
// derived from this software without specific prior written permission.
30
// This software is provided by the copyright holders and contributors "as is" and
31
// any express or implied warranties, including, but not limited to, the implied
32
// warranties of merchantability and fitness for a particular purpose are disclaimed.
33
// In no event shall the Intel Corporation or contributors be liable for any direct,
34
// indirect, incidental, special, exemplary, or consequential damages
35
// (including, but not limited to, procurement of substitute goods or services;
36
// loss of use, data, or profits; or business interruption) however caused
37
// and on any theory of liability, whether in contract, strict liability,
38
// or tort (including negligence or otherwise) arising in any way out of
39
// the use of this software, even if advised of the possibility of such damage.
43
#ifndef __OPENCV_CUDA_TEST_UTILITY_HPP__
44
#define __OPENCV_CUDA_TEST_UTILITY_HPP__
48
#include "opencv2/core.hpp"
49
#include "opencv2/core/cuda.hpp"
50
#include "opencv2/imgcodecs.hpp"
51
#include "opencv2/highgui.hpp"
52
#include "opencv2/imgproc.hpp"
53
#include "opencv2/ts.hpp"
57
//////////////////////////////////////////////////////////////////////
60
CV_EXPORTS int randomInt(int minVal, int maxVal);
61
CV_EXPORTS double randomDouble(double minVal, double maxVal);
62
CV_EXPORTS cv::Size randomSize(int minVal, int maxVal);
63
CV_EXPORTS cv::Scalar randomScalar(double minVal, double maxVal);
64
CV_EXPORTS cv::Mat randomMat(cv::Size size, int type, double minVal = 0.0, double maxVal = 255.0);
66
//////////////////////////////////////////////////////////////////////
69
CV_EXPORTS cv::cuda::GpuMat createMat(cv::Size size, int type, bool useRoi = false);
70
CV_EXPORTS cv::cuda::GpuMat loadMat(const cv::Mat& m, bool useRoi = false);
72
//////////////////////////////////////////////////////////////////////
75
//! read image from testdata folder
76
CV_EXPORTS cv::Mat readImage(const std::string& fileName, int flags = cv::IMREAD_COLOR);
78
//! read image from testdata folder and convert it to specified type
79
CV_EXPORTS cv::Mat readImageType(const std::string& fname, int type);
81
//////////////////////////////////////////////////////////////////////
84
//! return true if device supports specified feature and gpu module was built with support the feature.
85
CV_EXPORTS bool supportFeature(const cv::cuda::DeviceInfo& info, cv::cuda::FeatureSet feature);
87
class CV_EXPORTS DeviceManager
90
static DeviceManager& instance();
95
const std::vector<cv::cuda::DeviceInfo>& values() const { return devices_; }
98
std::vector<cv::cuda::DeviceInfo> devices_;
101
#define ALL_DEVICES testing::ValuesIn(cvtest::DeviceManager::instance().values())
103
//////////////////////////////////////////////////////////////////////
104
// Additional assertion
106
CV_EXPORTS 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());
108
CV_EXPORTS cv::Mat getMat(cv::InputArray arr);
110
CV_EXPORTS testing::AssertionResult assertMatNear(const char* expr1, const char* expr2, const char* eps_expr, cv::InputArray m1, cv::InputArray m2, double eps);
112
#define EXPECT_MAT_NEAR(m1, m2, eps) EXPECT_PRED_FORMAT3(cvtest::assertMatNear, m1, m2, eps)
113
#define ASSERT_MAT_NEAR(m1, m2, eps) ASSERT_PRED_FORMAT3(cvtest::assertMatNear, m1, m2, eps)
115
#define EXPECT_SCALAR_NEAR(s1, s2, eps) \
117
EXPECT_NEAR(s1[0], s2[0], eps); \
118
EXPECT_NEAR(s1[1], s2[1], eps); \
119
EXPECT_NEAR(s1[2], s2[2], eps); \
120
EXPECT_NEAR(s1[3], s2[3], eps); \
122
#define ASSERT_SCALAR_NEAR(s1, s2, eps) \
124
ASSERT_NEAR(s1[0], s2[0], eps); \
125
ASSERT_NEAR(s1[1], s2[1], eps); \
126
ASSERT_NEAR(s1[2], s2[2], eps); \
127
ASSERT_NEAR(s1[3], s2[3], eps); \
130
#define EXPECT_POINT2_NEAR(p1, p2, eps) \
132
EXPECT_NEAR(p1.x, p2.x, eps); \
133
EXPECT_NEAR(p1.y, p2.y, eps); \
135
#define ASSERT_POINT2_NEAR(p1, p2, eps) \
137
ASSERT_NEAR(p1.x, p2.x, eps); \
138
ASSERT_NEAR(p1.y, p2.y, eps); \
141
#define EXPECT_POINT3_NEAR(p1, p2, eps) \
143
EXPECT_NEAR(p1.x, p2.x, eps); \
144
EXPECT_NEAR(p1.y, p2.y, eps); \
145
EXPECT_NEAR(p1.z, p2.z, eps); \
147
#define ASSERT_POINT3_NEAR(p1, p2, eps) \
149
ASSERT_NEAR(p1.x, p2.x, eps); \
150
ASSERT_NEAR(p1.y, p2.y, eps); \
151
ASSERT_NEAR(p1.z, p2.z, eps); \
154
CV_EXPORTS double checkSimilarity(cv::InputArray m1, cv::InputArray m2);
156
#define EXPECT_MAT_SIMILAR(mat1, mat2, eps) \
158
ASSERT_EQ(mat1.type(), mat2.type()); \
159
ASSERT_EQ(mat1.size(), mat2.size()); \
160
EXPECT_LE(checkSimilarity(mat1, mat2), eps); \
162
#define ASSERT_MAT_SIMILAR(mat1, mat2, eps) \
164
ASSERT_EQ(mat1.type(), mat2.type()); \
165
ASSERT_EQ(mat1.size(), mat2.size()); \
166
ASSERT_LE(checkSimilarity(mat1, mat2), eps); \
169
//////////////////////////////////////////////////////////////////////
170
// Helper structs for value-parameterized tests
172
#define CUDA_TEST_P(test_case_name, test_name) \
173
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
174
: public test_case_name { \
176
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \
177
virtual void TestBody(); \
179
void UnsafeTestBody(); \
180
static int AddToRegistry() { \
181
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
182
GetTestCasePatternHolder<test_case_name>(\
183
#test_case_name, __FILE__, __LINE__)->AddTestPattern(\
186
new ::testing::internal::TestMetaFactory< \
187
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>()); \
190
static int gtest_registering_dummy_; \
191
GTEST_DISALLOW_COPY_AND_ASSIGN_(\
192
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \
194
int GTEST_TEST_CLASS_NAME_(test_case_name, \
195
test_name)::gtest_registering_dummy_ = \
196
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \
197
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() \
205
cv::cuda::resetDevice(); \
209
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::UnsafeTestBody()
211
#define PARAM_TEST_CASE(name, ...) struct name : testing::TestWithParam< std::tr1::tuple< __VA_ARGS__ > >
212
#define GET_PARAM(k) std::tr1::get< k >(GetParam())
214
#define DIFFERENT_SIZES testing::Values(cv::Size(128, 128), cv::Size(113, 113))
218
using perf::MatDepth;
220
#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))
222
#define DEPTH_PAIRS testing::Values(std::make_pair(MatDepth(CV_8U), MatDepth(CV_8U)), \
223
std::make_pair(MatDepth(CV_8U), MatDepth(CV_16U)), \
224
std::make_pair(MatDepth(CV_8U), MatDepth(CV_16S)), \
225
std::make_pair(MatDepth(CV_8U), MatDepth(CV_32S)), \
226
std::make_pair(MatDepth(CV_8U), MatDepth(CV_32F)), \
227
std::make_pair(MatDepth(CV_8U), MatDepth(CV_64F)), \
229
std::make_pair(MatDepth(CV_16U), MatDepth(CV_16U)), \
230
std::make_pair(MatDepth(CV_16U), MatDepth(CV_32S)), \
231
std::make_pair(MatDepth(CV_16U), MatDepth(CV_32F)), \
232
std::make_pair(MatDepth(CV_16U), MatDepth(CV_64F)), \
234
std::make_pair(MatDepth(CV_16S), MatDepth(CV_16S)), \
235
std::make_pair(MatDepth(CV_16S), MatDepth(CV_32S)), \
236
std::make_pair(MatDepth(CV_16S), MatDepth(CV_32F)), \
237
std::make_pair(MatDepth(CV_16S), MatDepth(CV_64F)), \
239
std::make_pair(MatDepth(CV_32S), MatDepth(CV_32S)), \
240
std::make_pair(MatDepth(CV_32S), MatDepth(CV_32F)), \
241
std::make_pair(MatDepth(CV_32S), MatDepth(CV_64F)), \
243
std::make_pair(MatDepth(CV_32F), MatDepth(CV_32F)), \
244
std::make_pair(MatDepth(CV_32F), MatDepth(CV_64F)), \
246
std::make_pair(MatDepth(CV_64F), MatDepth(CV_64F)))
252
//! return vector with types from specified range.
253
CV_EXPORTS std::vector<MatType> types(int depth_start, int depth_end, int cn_start, int cn_end);
255
//! return vector with all types (depth: CV_8U-CV_64F, channels: 1-4).
256
CV_EXPORTS const std::vector<MatType>& all_types();
258
#define ALL_TYPES testing::ValuesIn(all_types())
259
#define TYPES(depth_start, depth_end, cn_start, cn_end) testing::ValuesIn(types(depth_start, depth_end, cn_start, cn_end))
266
inline UseRoi(bool val = false) : val_(val) {}
268
inline operator bool() const { return val_; }
274
CV_EXPORTS void PrintTo(const UseRoi& useRoi, std::ostream* os);
276
#define WHOLE_SUBMAT testing::Values(UseRoi(false), UseRoi(true))
283
inline Inverse(bool val = false) : val_(val) {}
285
inline operator bool() const { return val_; }
291
CV_EXPORTS void PrintTo(const Inverse& useRoi, std::ostream* os);
293
#define DIRECT_INVERSE testing::Values(Inverse(false), Inverse(true))
297
#define IMPLEMENT_PARAM_CLASS(name, type) \
301
name ( type arg = type ()) : val_(arg) {} \
302
operator type () const {return val_;} \
306
inline void PrintTo( name param, std::ostream* os) \
308
*os << #name << "(" << testing::PrintToString(static_cast< type >(param)) << ")"; \
311
IMPLEMENT_PARAM_CLASS(Channels, int)
313
#define ALL_CHANNELS testing::Values(Channels(1), Channels(2), Channels(3), Channels(4))
314
#define IMAGE_CHANNELS testing::Values(Channels(1), Channels(3), Channels(4))
318
CV_ENUM(NormCode, NORM_INF, NORM_L1, NORM_L2, NORM_TYPE_MASK, NORM_RELATIVE, NORM_MINMAX)
320
CV_ENUM(Interpolation, INTER_NEAREST, INTER_LINEAR, INTER_CUBIC, INTER_AREA)
322
CV_ENUM(BorderType, BORDER_REFLECT101, BORDER_REPLICATE, BORDER_CONSTANT, BORDER_REFLECT, BORDER_WRAP)
323
#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))
325
CV_FLAGS(WarpFlags, INTER_NEAREST, INTER_LINEAR, INTER_CUBIC, WARP_INVERSE_MAP)
327
//////////////////////////////////////////////////////////////////////
330
CV_EXPORTS testing::AssertionResult assertKeyPointsEquals(const char* gold_expr, const char* actual_expr, std::vector<cv::KeyPoint>& gold, std::vector<cv::KeyPoint>& actual);
332
#define ASSERT_KEYPOINTS_EQ(gold, actual) EXPECT_PRED_FORMAT2(assertKeyPointsEquals, gold, actual)
334
CV_EXPORTS int getMatchedPointsCount(std::vector<cv::KeyPoint>& gold, std::vector<cv::KeyPoint>& actual);
335
CV_EXPORTS int getMatchedPointsCount(const std::vector<cv::KeyPoint>& keypoints1, const std::vector<cv::KeyPoint>& keypoints2, const std::vector<cv::DMatch>& matches);
337
//////////////////////////////////////////////////////////////////////
340
CV_EXPORTS void dumpImage(const std::string& fileName, const cv::Mat& image);
341
CV_EXPORTS void showDiff(cv::InputArray gold, cv::InputArray actual, double eps);
343
CV_EXPORTS void parseCudaDeviceOptions(int argc, char **argv);
344
CV_EXPORTS void printCudaInfo();
347
namespace cv { namespace cuda
349
CV_EXPORTS void PrintTo(const DeviceInfo& info, std::ostream* os);
354
#define CV_CUDA_TEST_MAIN(resourcesubdir) \
355
CV_TEST_MAIN(resourcesubdir, cvtest::parseCudaDeviceOptions(argc, argv), cvtest::printCudaInfo(), cv::setUseOptimized(false))
359
#define CV_CUDA_TEST_MAIN(resourcesubdir) \
362
printf("OpenCV was built without CUDA support\n"); \
369
#endif // __OPENCV_CUDA_TEST_UTILITY_HPP__