1 #ifndef __OPENCV_TS_PERF_HPP__
2 #define __OPENCV_TS_PERF_HPP__
10 #include "tbb/task_scheduler_init.h"
13 #if !(defined(LOGD) || defined(LOGI) || defined(LOGW) || defined(LOGE))
14 # if defined(ANDROID) && defined(USE_ANDROID_LOGGING)
15 # include <android/log.h>
17 # define PERF_TESTS_LOG_TAG "OpenCV_perf"
18 # define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, PERF_TESTS_LOG_TAG, __VA_ARGS__))
19 # define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, PERF_TESTS_LOG_TAG, __VA_ARGS__))
20 # define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, PERF_TESTS_LOG_TAG, __VA_ARGS__))
21 # define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, PERF_TESTS_LOG_TAG, __VA_ARGS__))
23 # define LOGD(_str, ...) do{printf(_str , ## __VA_ARGS__); printf("\n");fflush(stdout);} while(0)
24 # define LOGI(_str, ...) do{printf(_str , ## __VA_ARGS__); printf("\n");fflush(stdout);} while(0)
25 # define LOGW(_str, ...) do{printf(_str , ## __VA_ARGS__); printf("\n");fflush(stdout);} while(0)
26 # define LOGE(_str, ...) do{printf(_str , ## __VA_ARGS__); printf("\n");fflush(stdout);} while(0)
31 namespace cv {
namespace gpu {}
namespace ocl {} }
67 #define SZ_ALL_VGA ::testing::Values(::perf::szQVGA, ::perf::szVGA, ::perf::szSVGA)
68 #define SZ_ALL_GA ::testing::Values(::perf::szQVGA, ::perf::szVGA, ::perf::szSVGA, ::perf::szXGA, ::perf::szSXGA)
69 #define SZ_ALL_HD ::testing::Values(::perf::sznHD, ::perf::szqHD, ::perf::sz720p, ::perf::sz1080p)
70 #define SZ_ALL_SMALL ::testing::Values(::perf::szSmall24, ::perf::szSmall32, ::perf::szSmall64, ::perf::szSmall128)
71 #define SZ_ALL ::testing::Values(::perf::szQVGA, ::perf::szVGA, ::perf::szSVGA, ::perf::szXGA, ::perf::szSXGA, ::perf::sznHD, ::perf::szqHD, ::perf::sz720p, ::perf::sz1080p)
72 #define SZ_TYPICAL ::testing::Values(::perf::szVGA, ::perf::szqHD, ::perf::sz720p, ::perf::szODD)
75 #define TYPICAL_MAT_SIZES ::perf::szVGA, ::perf::sz720p, ::perf::sz1080p, ::perf::szODD
76 #define TYPICAL_MAT_TYPES CV_8UC1, CV_8UC4, CV_32FC1
77 #define TYPICAL_MATS testing::Combine( testing::Values( TYPICAL_MAT_SIZES ), testing::Values( TYPICAL_MAT_TYPES ) )
78 #define TYPICAL_MATS_C1 testing::Combine( testing::Values( TYPICAL_MAT_SIZES ), testing::Values( CV_8UC1, CV_32FC1 ) )
79 #define TYPICAL_MATS_C4 testing::Combine( testing::Values( TYPICAL_MAT_SIZES ), testing::Values( CV_8UC4 ) )
89 operator int()
const {
return _type;}
99 #define CV_ENUM(class_name, ...) \
101 struct class_name { \
102 class_name(int val = 0) : val_(val) {} \
103 operator int() const { return val_; } \
104 void PrintTo(std::ostream* os) const { \
105 using namespace cv;using namespace cv::gpu; using namespace cv::ocl; \
106 const int vals[] = { __VA_ARGS__ }; \
107 const char* svals = #__VA_ARGS__; \
108 for(int i = 0, pos = 0; i < (int)(sizeof(vals)/sizeof(int)); ++i) { \
109 while(isspace(svals[pos]) || svals[pos] == ',') ++pos; \
111 while(!(isspace(svals[pos]) || svals[pos] == ',' || svals[pos] == 0)) \
113 if (val_ == vals[i]) { \
114 *os << std::string(svals + start, svals + pos); \
120 static ::testing::internal::ParamGenerator<class_name> all() { \
121 using namespace cv;using namespace cv::gpu; using namespace cv::ocl; \
122 static class_name vals[] = { __VA_ARGS__ }; \
123 return ::testing::ValuesIn(vals); \
127 inline void PrintTo(const class_name& t, std::ostream* os) { t.PrintTo(os); } }
129 #define CV_FLAGS(class_name, ...) \
131 struct class_name { \
132 class_name(int val = 0) : val_(val) {} \
133 operator int() const { return val_; } \
134 void PrintTo(std::ostream* os) const { \
135 using namespace cv;using namespace cv::gpu; using namespace cv::ocl; \
136 const int vals[] = { __VA_ARGS__ }; \
137 const char* svals = #__VA_ARGS__; \
140 for(int i = 0, pos = 0; i < (int)(sizeof(vals)/sizeof(int)); ++i) { \
141 while(isspace(svals[pos]) || svals[pos] == ',') ++pos; \
143 while(!(isspace(svals[pos]) || svals[pos] == ',' || svals[pos] == 0)) \
145 if ((value & vals[i]) == vals[i]) { \
147 if (first) first = false; else *os << "|"; \
148 *os << std::string(svals + start, svals + pos); \
149 if (!value) return; \
152 if (first) *os << "UNKNOWN"; \
156 inline void PrintTo(const class_name& t, std::ostream* os) { t.PrintTo(os); } }
158 CV_ENUM(MatDepth, CV_8U, CV_8S, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F, CV_USRTYPE1)
173 static Regression& addKeypoints(
TestBase* test,
const std::string& name,
const std::vector<cv::KeyPoint>& array,
double eps = DBL_EPSILON, ERROR_TYPE err = ERROR_ABSOLUTE);
174 static Regression& addMatches(
TestBase* test,
const std::string& name,
const std::vector<cv::DMatch>& array,
double eps = DBL_EPSILON, ERROR_TYPE err = ERROR_ABSOLUTE);
175 static void Init(
const std::string& testSuitName,
const std::string& ext =
".xml");
188 std::string storageInPath;
189 std::string storageOutPath;
193 std::string currentTestNodeName;
194 std::string suiteName;
198 static std::string getCurrentTestNodeName();
200 static double getElem(
cv::Mat&
m,
int x,
int y,
int cn = 0);
202 void init(
const std::string& testSuitName,
const std::string& ext);
206 void verify(
cv::FileNode node,
cv::Mat actual,
double eps, std::string argname, ERROR_TYPE err);
209 #define SANITY_CHECK(array, ...) ::perf::Regression::add(this, #array, array , ## __VA_ARGS__)
210 #define SANITY_CHECK_KEYPOINTS(array, ...) ::perf::Regression::addKeypoints(this, #array, array , ## __VA_ARGS__)
211 #define SANITY_CHECK_MATCHES(array, ...) ::perf::Regression::addMatches(this, #array, array , ## __VA_ARGS__)
212 #define SANITY_CHECK_NOTHING() this->setVerified()
217 static bool targetDevice();
220 #define PERF_RUN_GPU() ::perf::GpuPerf::targetDevice()
273 static void Init(
int argc,
const char*
const argv[]);
274 static void Init(
const std::vector<std::string> & availableImpls,
275 int argc,
const char*
const argv[]);
276 static void RecordRunParameters();
277 static std::string getDataPath(
const std::string& relativePath);
278 static std::string getSelectedImpl();
286 virtual void PerfTestBody() = 0;
288 virtual void SetUp();
289 virtual void TearDown();
305 void reportMetrics(
bool toJUnitXML =
false);
309 void RunPerfTestBody();
311 typedef std::vector<std::pair<int, cv::Size> > SizeVector;
312 typedef std::vector<int64> TimeVector;
314 SizeVector inputData;
315 SizeVector outputData;
316 unsigned int getTotalInputSize()
const;
317 unsigned int getTotalOutputSize()
const;
323 static int64 timeLimitDefault;
324 static unsigned int iterationsLimitDefault;
327 unsigned int currentIter;
328 unsigned int runsPerIteration;
331 void validateMetrics();
333 static int64 _timeadjustment;
334 static int64 _calibrate();
336 static void warmup_impl(
cv::Mat m,
int wtype);
341 class CV_EXPORTS _declareHelper
355 _declareHelper& time(
double timeLimitSecs);
356 _declareHelper& tbb_threads(
int n = -1);
357 _declareHelper& runs(
unsigned int runsNumber);
361 _declareHelper(
const _declareHelper&);
362 _declareHelper& operator=(
const _declareHelper&);
365 friend class _declareHelper;
390 CV_EXPORTS
void PrintTo(
const Size& sz, ::std::ostream* os);
398 #define PERF_PROXY_NAMESPACE_NAME_(test_case_name, test_name) \
399 test_case_name##_##test_name##_perf_namespace_proxy
413 #define PERF_TEST(test_case_name, test_name)\
414 namespace PERF_PROXY_NAMESPACE_NAME_(test_case_name, test_name) {\
416 class test_case_name : public ::perf::TestBase {\
420 virtual void PerfTestBody();\
422 TEST_F(test_case_name, test_name){ RunPerfTestBody(); }\
424 void PERF_PROXY_NAMESPACE_NAME_(test_case_name, test_name)::test_case_name::PerfTestBody()
451 #define PERF_TEST_F(fixture, testname) \
452 namespace PERF_PROXY_NAMESPACE_NAME_(fixture, testname) {\
454 class fixture : public ::fixture {\
458 virtual void PerfTestBody();\
460 TEST_F(fixture, testname){ RunPerfTestBody(); }\
462 void PERF_PROXY_NAMESPACE_NAME_(fixture, testname)::fixture::PerfTestBody()
486 #define PERF_TEST_P(fixture, name, params) \
487 class fixture##_##name : public fixture {\
489 fixture##_##name() {}\
491 virtual void PerfTestBody();\
493 TEST_P(fixture##_##name, name ){ RunPerfTestBody(); }\
494 INSTANTIATE_TEST_CASE_P(, fixture##_##name, params);\
495 void fixture##_##name::PerfTestBody()
497 #ifndef __CV_TEST_EXEC_ARGS
498 #if defined(_MSC_VER) && (_MSC_VER <= 1400)
499 #define __CV_TEST_EXEC_ARGS(...) \
500 while (++argc >= (--argc,-1)) {__VA_ARGS__; break;}
502 #define __CV_TEST_EXEC_ARGS(...) \
507 #define CV_PERF_TEST_MAIN_INTERNALS(modulename, impls, ...) \
508 ::perf::Regression::Init(#modulename); \
509 ::perf::TestBase::Init(std::vector<std::string>(impls, impls + sizeof impls / sizeof *impls), \
511 ::testing::InitGoogleTest(&argc, argv); \
512 cvtest::printVersionInfo(); \
513 ::testing::Test::RecordProperty("cv_module_name", #modulename); \
514 ::perf::TestBase::RecordRunParameters(); \
515 __CV_TEST_EXEC_ARGS(__VA_ARGS__) \
516 return RUN_ALL_TESTS();
519 #define CV_PERF_TEST_MAIN_WITH_IMPLS(modulename, impls, ...) \
520 int main(int argc, char **argv)\
522 CV_PERF_TEST_MAIN_INTERNALS(modulename, impls, __VA_ARGS__)\
525 #define CV_PERF_TEST_MAIN(modulename, ...) \
526 int main(int argc, char **argv)\
528 const char * plain_only[] = { "plain" };\
529 CV_PERF_TEST_MAIN_INTERNALS(modulename, plain_only, __VA_ARGS__)\
532 #define TEST_CYCLE_N(n) for(declare.iterations(n); startTimer(), next(); stopTimer())
533 #define TEST_CYCLE() for(; startTimer(), next(); stopTimer())
534 #define TEST_CYCLE_MULTIRUN(runsNum) for(declare.runs(runsNum); startTimer(), next(); stopTimer()) for(int r = 0; r < runsNum; ++r)
538 namespace comparators
547 || (r1.
x == r2.
x && r1.
y < r2.
y)
561 if(kp1.
size > kp2.
size)
return true;
562 if(kp1.
size < kp2.
size)
return false;
565 if(kp1.
pt.
y < kp2.
pt.
y)
return false;
566 if(kp1.
pt.
y > kp2.
pt.
y)
return true;
567 return kp1.
pt.
x < kp2.
pt.
x;
576 #endif //__OPENCV_TS_PERF_HPP__
Definition: ts_perf.hpp:214
CV_ENUM(BorderMode, BORDER_REFLECT101, BORDER_REPLICATE, BORDER_CONSTANT, BORDER_REFLECT, BORDER_WRAP) CV_ENUM(Interpolation
CV_PROP_RW float size
diameter of the meaningful keypoint neighborhood
Definition: features2d.hpp:102
GLenum GLint GLint y
Definition: core_c.h:613
CV_PROP_RW Point2f pt
coordinates of the keypoints
Definition: features2d.hpp:101
CvFileNode * node
Definition: core_c.h:1638
Random Number Generator.
Definition: core.hpp:2019
const int * sizes
Definition: core_c.h:212
const cv::Size sz3MP
Definition: ts_perf.hpp:56
RectLess_< int > RectLess
Definition: ts_perf.hpp:553
Definition: ts_perf.hpp:299
File Storage Node class.
Definition: core.hpp:4119
Size2i Size
Definition: core.hpp:896
const cv::Size szSVGA
Definition: ts_perf.hpp:42
bool operator()(const cv::KeyPoint &kp1, const cv::KeyPoint &kp2) const
Definition: ts_perf.hpp:557
Definition: ts_perf.hpp:169
CV_PROP_RW float response
the response by which the most strong keypoints have been selected.
Definition: features2d.hpp:106
_Tp x
Definition: core.hpp:766
Definition: ts_gtest.h:799
bool operator()(const cv::Rect_< T > &r1, const cv::Rect_< T > &r2) const
Definition: ts_perf.hpp:544
TestBaseWithParam< Size_MatType_t > Size_MatType
Definition: ts_perf.hpp:378
The Keypoint Class.
Definition: features2d.hpp:69
int CvMemStorage int double eps
Definition: imgproc_c.h:353
const cv::Size szSmall24
Definition: ts_perf.hpp:62
const cv::Size sz720p
Definition: ts_perf.hpp:50
const cv::Size szVGA
Definition: ts_perf.hpp:41
_Tp height
Definition: core.hpp:883
CV_EXPORTS_W void write(FileStorage &fs, const string &name, int value)
Definition: ts_perf.hpp:300
void clear(const ColorA &color=ColorA::black(), bool clearDepthBuffer=true)
Definition: ts_perf.hpp:375
const cv::Size sz1440p
Definition: ts_perf.hpp:52
const cv::Size szWQHD
Definition: ts_perf.hpp:45
The 2D size class.
Definition: core.hpp:81
const cv::Size szODD
Definition: ts_perf.hpp:60
Definition: ts_perf.hpp:542
struct CV_EXPORTS perf::performance_metrics performance_metrics
const cv::Size sz1080p
Definition: ts_perf.hpp:51
void CV_EXPORTS sort(std::vector< cv::KeyPoint > &pts, cv::InputOutputArray descriptors)
Definition: ts_perf.hpp:260
Definition: ts_perf.hpp:283
const cv::Size szQVGA
Definition: ts_perf.hpp:40
_Tp y
Definition: core.hpp:883
CV_EXPORTS void PrintTo(const CvtColorInfo &info, std::ostream *os)
std::tr1::tuple< cv::Size, MatType > Size_MatType_t
Definition: ts_perf.hpp:377
const CvPoint * pts
Definition: core_c.h:1315
const cv::Size sz2160p
Definition: ts_perf.hpp:53
const cv::Size szSmall64
Definition: ts_perf.hpp:64
GLenum GLint x
Definition: core_c.h:632
_Tp x
Definition: core.hpp:883
void setVerified()
Definition: ts_perf.hpp:372
const CvArr CvArr double int int int iterations
Definition: tracking.hpp:102
XML/YAML File Storage Class.
Definition: core.hpp:4040
The n-dimensional matrix class.
Definition: core.hpp:1688
Definition: ts_perf.hpp:301
const CvArr CvSeq CvSeq ** descriptors
Definition: compat.hpp:647
__int64 int64
Definition: types_c.h:158
GLuint const GLchar * name
Definition: core_c.h:1546
const cv::Size sz4320p
Definition: ts_perf.hpp:54
Definition: ts_perf.hpp:85
Definition: ts_gtest.h:17824
GLboolean GLboolean GLboolean GLboolean a
Definition: legacy.hpp:633
const cv::Size sz240p
Definition: ts_perf.hpp:49
char int argc
Definition: highgui_c.h:81
char * argv[]
Definition: highgui_c.h:81
The 2D up-right rectangle class.
Definition: core.hpp:83
_Tp y
Definition: core.hpp:766
CV_EXPORTS void PrintTo(const Size &sz,::std::ostream *os)
The standard OpenCV exception class.
Definition: core.hpp:143
const cv::Size szSmall32
Definition: ts_perf.hpp:63
::max::max int
Definition: functional.hpp:324
Definition: ts_gtest.h:19277
CV_EXPORTS_W void add(InputArray src1, InputArray src2, OutputArray dst, InputArray mask=noArray(), int dtype=-1)
adds one matrix to another (dst = src1 + src2)
const cv::Size sz2K
Definition: ts_perf.hpp:58
MatType(int val=0)
Definition: ts_perf.hpp:88
Definition: ts_perf.hpp:555
const cv::Size szSXGA
Definition: ts_perf.hpp:44
const cv::Size szXGA
Definition: ts_perf.hpp:43
const cv::Size szSmall128
Definition: ts_perf.hpp:65
const cv::Size sz5MP
Definition: ts_perf.hpp:57
PERF_STRATEGY
Definition: ts_perf.hpp:258
Definition: ts_perf.hpp:268
const cv::Size sznHD
Definition: ts_perf.hpp:47
Proxy datatype for passing Mat's and vector<>'s as input parameters.
Definition: core.hpp:1400
Definition: ts_perf.hpp:261
const CvArr * next
Definition: tracking.hpp:102
_Tp width
Definition: core.hpp:883
CV_PROP_RW int octave
octave (pyramid layer) from which the keypoint has been extracted
Definition: features2d.hpp:107
_declareHelper declare
Definition: ts_perf.hpp:370
const cv::Size szqHD
Definition: ts_perf.hpp:48