1 #include "perf_precomp.hpp"
6 using namespace testing;
7 using std::tr1::make_tuple;
10 enum{HALF_SIZE=0, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH};
12 CV_ENUM(BorderMode, BORDER_CONSTANT, BORDER_REPLICATE)
13 CV_ENUM(InterType, INTER_NEAREST, INTER_LINEAR)
14 CV_ENUM(RemapMode, HALF_SIZE, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH)
16 typedef TestBaseWithParam< tr1::tuple<Size, InterType, BorderMode> > TestWarpAffine;
17 typedef TestBaseWithParam< tr1::tuple<Size, InterType, BorderMode> > TestWarpPerspective;
18 typedef TestBaseWithParam< tr1::tuple<Size, InterType, BorderMode, MatType> > TestWarpPerspectiveNear_t;
19 typedef TestBaseWithParam< tr1::tuple<MatType, Size, InterType, BorderMode, RemapMode> > TestRemap;
21 void update_map(const Mat& src, Mat& map_x, Mat& map_y, const int remapMode );
23 PERF_TEST_P( TestWarpAffine, WarpAffine,
25 Values( szVGA, sz720p, sz1080p ),
31 Size sz, szSrc(512, 512);
32 int borderMode, interType;
33 sz = get<0>(GetParam());
34 interType = get<1>(GetParam());
35 borderMode = get<2>(GetParam());
36 Scalar borderColor = Scalar::all(150);
38 Mat src(szSrc,CV_8UC4), dst(sz, CV_8UC4);
39 cvtest::fillGradient(src);
40 if(borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1);
41 Mat warpMat = getRotationMatrix2D(Point2f(src.cols/2.f, src.rows/2.f), 30., 2.2);
42 declare.in(src).out(dst);
44 TEST_CYCLE() warpAffine( src, dst, warpMat, sz, interType, borderMode, borderColor );
47 SANITY_CHECK(dst, interType==INTER_LINEAR? 5 : 10);
53 PERF_TEST_P( TestWarpPerspective, WarpPerspective,
55 Values( szVGA, sz720p, sz1080p ),
61 Size sz, szSrc(512, 512);
62 int borderMode, interType;
63 sz = get<0>(GetParam());
64 interType = get<1>(GetParam());
65 borderMode = get<2>(GetParam());
66 Scalar borderColor = Scalar::all(150);
68 Mat src(szSrc,CV_8UC4), dst(sz, CV_8UC4);
69 cvtest::fillGradient(src);
70 if(borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1);
71 Mat rotMat = getRotationMatrix2D(Point2f(src.cols/2.f, src.rows/2.f), 30., 2.2);
72 Mat warpMat(3, 3, CV_64FC1);
73 for(int r=0; r<2; r++)
74 for(int c=0; c<3; c++)
75 warpMat.at<double>(r, c) = rotMat.at<double>(r, c);
76 warpMat.at<double>(2, 0) = .3/sz.width;
77 warpMat.at<double>(2, 1) = .3/sz.height;
78 warpMat.at<double>(2, 2) = 1;
80 declare.in(src).out(dst);
82 TEST_CYCLE() warpPerspective( src, dst, warpMat, sz, interType, borderMode, borderColor );
85 SANITY_CHECK(dst, interType==INTER_LINEAR? 5 : 10);
91 PERF_TEST_P( TestWarpPerspectiveNear_t, WarpPerspectiveNear,
93 Values( Size(640,480), Size(1920,1080), Size(2592,1944) ),
96 Values( CV_8UC1, CV_8UC4 )
101 int borderMode, interType, type;
102 size = get<0>(GetParam());
103 interType = get<1>(GetParam());
104 borderMode = get<2>(GetParam());
105 type = get<3>(GetParam());
106 Scalar borderColor = Scalar::all(150);
108 Mat src(size, type), dst(size, type);
109 cvtest::fillGradient(src);
110 if(borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1);
111 int shift = static_cast<int>(src.cols*0.04);
112 Mat srcVertices = (Mat_<Vec2f>(1, 4) << Vec2f(0, 0),
113 Vec2f(static_cast<float>(size.width-1), 0),
114 Vec2f(static_cast<float>(size.width-1), static_cast<float>(size.height-1)),
115 Vec2f(0, static_cast<float>(size.height-1)));
116 Mat dstVertices = (Mat_<Vec2f>(1, 4) << Vec2f(0, static_cast<float>(shift)),
117 Vec2f(static_cast<float>(size.width-shift/2), 0),
118 Vec2f(static_cast<float>(size.width-shift), static_cast<float>(size.height-shift)),
119 Vec2f(static_cast<float>(shift/2), static_cast<float>(size.height-1)));
120 Mat warpMat = getPerspectiveTransform(srcVertices, dstVertices);
122 declare.in(src).out(dst);
127 warpPerspective( src, dst, warpMat, size, interType, borderMode, borderColor );
131 SANITY_CHECK(dst, interType==INTER_LINEAR? 5 : 10);
133 SANITY_CHECK(dst, 1);
137 PERF_TEST_P( TestRemap, remap,
139 Values( TYPICAL_MAT_TYPES ),
140 Values( szVGA, sz720p, sz1080p ),
147 int type = get<0>(GetParam());
148 Size size = get<1>(GetParam());
149 int interpolationType = get<2>(GetParam());
150 int borderMode = get<3>(GetParam());
151 int remapMode = get<4>(GetParam());
152 unsigned int height = size.height;
153 unsigned int width = size.width;
154 Mat source(height, width, type);
156 Mat map_x(height, width, CV_32F);
157 Mat map_y(height, width, CV_32F);
159 declare.in(source, WARMUP_RNG);
161 update_map(source, map_x, map_y, remapMode);
165 remap(source, destination, map_x, map_y, interpolationType, borderMode);
168 SANITY_CHECK(destination, 1);
171 void update_map(const Mat& src, Mat& map_x, Mat& map_y, const int remapMode )
173 for( int j = 0; j < src.rows; j++ )
175 for( int i = 0; i < src.cols; i++ )
180 if( i > src.cols*0.25 && i < src.cols*0.75 && j > src.rows*0.25 && j < src.rows*0.75 )
182 map_x.at<float>(j,i) = 2*( i - src.cols*0.25f ) + 0.5f ;
183 map_y.at<float>(j,i) = 2*( j - src.rows*0.25f ) + 0.5f ;
187 map_x.at<float>(j,i) = 0 ;
188 map_y.at<float>(j,i) = 0 ;
192 map_x.at<float>(j,i) = static_cast<float>(i) ;
193 map_y.at<float>(j,i) = static_cast<float>(src.rows - j) ;
196 map_x.at<float>(j,i) = static_cast<float>(src.cols - i) ;
197 map_y.at<float>(j,i) = static_cast<float>(j) ;
199 case REFLECTION_BOTH:
200 map_x.at<float>(j,i) = static_cast<float>(src.cols - i) ;
201 map_y.at<float>(j,i) = static_cast<float>(src.rows - j) ;
208 PERF_TEST(Transform, getPerspectiveTransform)
210 unsigned int size = 8;
211 Mat source(1, size/2, CV_32FC2);
212 Mat destination(1, size/2, CV_32FC2);
213 Mat transformCoefficient;
215 declare.in(source, destination, WARMUP_RNG);
219 transformCoefficient = getPerspectiveTransform(source, destination);
222 SANITY_CHECK(transformCoefficient, 1e-5);