1#include "perf_precomp.hpp"
2
3using namespace std;
4using namespace cv;
5using namespace perf;
6using std::tr1::make_tuple;
7using std::tr1::get;
8
9PERF_TEST_P(Size_MatType, sum, TYPICAL_MATS)
10{
11    Size sz = get<0>(GetParam());
12    int type = get<1>(GetParam());
13
14    Mat arr(sz, type);
15    Scalar s;
16
17    declare.in(arr, WARMUP_RNG).out(s);
18
19    TEST_CYCLE() s = sum(arr);
20
21    SANITY_CHECK(s, 1e-6, ERROR_RELATIVE);
22}
23
24PERF_TEST_P(Size_MatType, mean, TYPICAL_MATS)
25{
26    Size sz = get<0>(GetParam());
27    int type = get<1>(GetParam());
28
29    Mat src(sz, type);
30    Scalar s;
31
32    declare.in(src, WARMUP_RNG).out(s);
33
34    TEST_CYCLE() s = mean(src);
35
36    SANITY_CHECK(s, 1e-5);
37}
38
39PERF_TEST_P(Size_MatType, mean_mask, TYPICAL_MATS)
40{
41    Size sz = get<0>(GetParam());
42    int type = get<1>(GetParam());
43
44    Mat src(sz, type);
45    Mat mask = Mat::ones(src.size(), CV_8U);
46    Scalar s;
47
48    declare.in(src, WARMUP_RNG).in(mask).out(s);
49
50    TEST_CYCLE() s = mean(src, mask);
51
52    SANITY_CHECK(s, 5e-5);
53}
54
55PERF_TEST_P(Size_MatType, meanStdDev, TYPICAL_MATS)
56{
57    Size sz = get<0>(GetParam());
58    int matType = get<1>(GetParam());
59
60    Mat src(sz, matType);
61    Scalar mean;
62    Scalar dev;
63
64    declare.in(src, WARMUP_RNG).out(mean, dev);
65
66    TEST_CYCLE() meanStdDev(src, mean, dev);
67
68    SANITY_CHECK(mean, 1e-5, ERROR_RELATIVE);
69    SANITY_CHECK(dev, 1e-5, ERROR_RELATIVE);
70}
71
72PERF_TEST_P(Size_MatType, meanStdDev_mask, TYPICAL_MATS)
73{
74    Size sz = get<0>(GetParam());
75    int matType = get<1>(GetParam());
76
77    Mat src(sz, matType);
78    Mat mask = Mat::ones(sz, CV_8U);
79    Scalar mean;
80    Scalar dev;
81
82    declare.in(src, WARMUP_RNG).in(mask).out(mean, dev);
83
84    TEST_CYCLE() meanStdDev(src, mean, dev, mask);
85
86    SANITY_CHECK(mean, 1e-5);
87    SANITY_CHECK(dev, 1e-5);
88}
89
90PERF_TEST_P(Size_MatType, countNonZero, testing::Combine( testing::Values( TYPICAL_MAT_SIZES ), testing::Values( CV_8UC1, CV_8SC1, CV_16UC1, CV_16SC1, CV_32SC1, CV_32FC1, CV_64FC1 ) ))
91{
92    Size sz = get<0>(GetParam());
93    int matType = get<1>(GetParam());
94
95    Mat src(sz, matType);
96    int cnt = 0;
97
98    declare.in(src, WARMUP_RNG);
99
100    int runs = (sz.width <= 640) ? 8 : 1;
101    TEST_CYCLE_MULTIRUN(runs) cnt = countNonZero(src);
102
103    SANITY_CHECK(cnt);
104}
105