opencv/modules/imgproc/perf/perf_warp.cpp

313 lines
9.9 KiB
C++
Raw Normal View History

// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
2012-08-10 21:17:09 +08:00
#include "perf_precomp.hpp"
namespace opencv_test {
2012-08-10 21:17:09 +08:00
enum{HALF_SIZE=0, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH};
2012-10-09 01:31:07 +08:00
CV_ENUM(BorderMode, BORDER_CONSTANT, BORDER_REPLICATE)
CV_ENUM(InterType, INTER_NEAREST, INTER_LINEAR)
CV_ENUM(RemapMode, HALF_SIZE, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH)
2012-08-10 21:17:09 +08:00
typedef TestBaseWithParam< tuple<Size, InterType, BorderMode> > TestWarpAffine;
typedef TestBaseWithParam< tuple<Size, InterType, BorderMode> > TestWarpPerspective;
typedef TestBaseWithParam< tuple<Size, InterType, BorderMode, MatType> > TestWarpPerspectiveNear_t;
typedef TestBaseWithParam< tuple<MatType, Size, InterType, BorderMode, RemapMode> > TestRemap;
2012-08-10 21:17:09 +08:00
void update_map(const Mat& src, Mat& map_x, Mat& map_y, const int remapMode );
PERF_TEST_P( TestWarpAffine, WarpAffine,
Combine(
Values( szVGA, sz720p, sz1080p ),
InterType::all(),
BorderMode::all()
2012-08-10 21:17:09 +08:00
)
)
{
Size sz, szSrc(512, 512);
2012-08-10 21:17:09 +08:00
int borderMode, interType;
sz = get<0>(GetParam());
interType = get<1>(GetParam());
borderMode = get<2>(GetParam());
Scalar borderColor = Scalar::all(150);
2012-08-10 21:17:09 +08:00
Mat src(szSrc,CV_8UC4), dst(sz, CV_8UC4);
cvtest::fillGradient(src);
if(borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1);
2012-08-10 21:17:09 +08:00
Mat warpMat = getRotationMatrix2D(Point2f(src.cols/2.f, src.rows/2.f), 30., 2.2);
declare.in(src).out(dst);
TEST_CYCLE() warpAffine( src, dst, warpMat, sz, interType, borderMode, borderColor );
2012-08-10 21:17:09 +08:00
#ifdef __ANDROID__
SANITY_CHECK(dst, interType==INTER_LINEAR? 5 : 10);
#else
SANITY_CHECK(dst, 1);
#endif
2012-08-10 21:17:09 +08:00
}
2019-03-06 20:52:23 +08:00
PERF_TEST_P(TestWarpAffine, DISABLED_WarpAffine_ovx,
Combine(
Values(szVGA, sz720p, sz1080p),
InterType::all(),
BorderMode::all()
)
)
{
Size sz, szSrc(512, 512);
int borderMode, interType;
sz = get<0>(GetParam());
interType = get<1>(GetParam());
borderMode = get<2>(GetParam());
Scalar borderColor = Scalar::all(150);
Mat src(szSrc, CV_8UC1), dst(sz, CV_8UC1);
cvtest::fillGradient(src);
if (borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1);
Mat warpMat = getRotationMatrix2D(Point2f(src.cols / 2.f, src.rows / 2.f), 30., 2.2);
declare.in(src).out(dst);
TEST_CYCLE() warpAffine(src, dst, warpMat, sz, interType, borderMode, borderColor);
#ifdef __ANDROID__
SANITY_CHECK(dst, interType == INTER_LINEAR ? 5 : 10);
#else
SANITY_CHECK(dst, 1);
#endif
}
2012-08-10 21:17:09 +08:00
PERF_TEST_P( TestWarpPerspective, WarpPerspective,
Combine(
Values( szVGA, sz720p, sz1080p ),
InterType::all(),
BorderMode::all()
2012-08-10 21:17:09 +08:00
)
)
{
Size sz, szSrc(512, 512);
2012-08-10 21:17:09 +08:00
int borderMode, interType;
sz = get<0>(GetParam());
interType = get<1>(GetParam());
borderMode = get<2>(GetParam());
Scalar borderColor = Scalar::all(150);
2012-08-10 21:17:09 +08:00
Mat src(szSrc,CV_8UC4), dst(sz, CV_8UC4);
cvtest::fillGradient(src);
if(borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1);
2012-08-10 21:17:09 +08:00
Mat rotMat = getRotationMatrix2D(Point2f(src.cols/2.f, src.rows/2.f), 30., 2.2);
Mat warpMat(3, 3, CV_64FC1);
for(int r=0; r<2; r++)
for(int c=0; c<3; c++)
warpMat.at<double>(r, c) = rotMat.at<double>(r, c);
warpMat.at<double>(2, 0) = .3/sz.width;
warpMat.at<double>(2, 1) = .3/sz.height;
warpMat.at<double>(2, 2) = 1;
declare.in(src).out(dst);
TEST_CYCLE() warpPerspective( src, dst, warpMat, sz, interType, borderMode, borderColor );
2012-08-10 21:17:09 +08:00
#ifdef __ANDROID__
SANITY_CHECK(dst, interType==INTER_LINEAR? 5 : 10);
#else
SANITY_CHECK(dst, 1);
#endif
2012-08-10 21:17:09 +08:00
}
2019-03-06 20:52:23 +08:00
PERF_TEST_P(TestWarpPerspective, DISABLED_WarpPerspective_ovx,
Combine(
Values(szVGA, sz720p, sz1080p),
InterType::all(),
BorderMode::all()
)
)
{
Size sz, szSrc(512, 512);
int borderMode, interType;
sz = get<0>(GetParam());
interType = get<1>(GetParam());
borderMode = get<2>(GetParam());
Scalar borderColor = Scalar::all(150);
Mat src(szSrc, CV_8UC1), dst(sz, CV_8UC1);
cvtest::fillGradient(src);
if (borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1);
Mat rotMat = getRotationMatrix2D(Point2f(src.cols / 2.f, src.rows / 2.f), 30., 2.2);
Mat warpMat(3, 3, CV_64FC1);
for (int r = 0; r<2; r++)
for (int c = 0; c<3; c++)
warpMat.at<double>(r, c) = rotMat.at<double>(r, c);
warpMat.at<double>(2, 0) = .3 / sz.width;
warpMat.at<double>(2, 1) = .3 / sz.height;
warpMat.at<double>(2, 2) = 1;
declare.in(src).out(dst);
TEST_CYCLE() warpPerspective(src, dst, warpMat, sz, interType, borderMode, borderColor);
#ifdef __ANDROID__
SANITY_CHECK(dst, interType == INTER_LINEAR ? 5 : 10);
#else
SANITY_CHECK(dst, 1);
#endif
}
PERF_TEST_P( TestWarpPerspectiveNear_t, WarpPerspectiveNear,
Combine(
Values( Size(640,480), Size(1920,1080), Size(2592,1944) ),
InterType::all(),
BorderMode::all(),
Values( CV_8UC1, CV_8UC4 )
)
)
{
Size size;
int borderMode, interType, type;
size = get<0>(GetParam());
interType = get<1>(GetParam());
borderMode = get<2>(GetParam());
type = get<3>(GetParam());
Scalar borderColor = Scalar::all(150);
Mat src(size, type), dst(size, type);
cvtest::fillGradient(src);
if(borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1);
2012-10-25 00:27:20 +08:00
int shift = static_cast<int>(src.cols*0.04);
2012-10-23 17:08:43 +08:00
Mat srcVertices = (Mat_<Vec2f>(1, 4) << Vec2f(0, 0),
Vec2f(static_cast<float>(size.width-1), 0),
Vec2f(static_cast<float>(size.width-1), static_cast<float>(size.height-1)),
Vec2f(0, static_cast<float>(size.height-1)));
Mat dstVertices = (Mat_<Vec2f>(1, 4) << Vec2f(0, static_cast<float>(shift)),
Vec2f(static_cast<float>(size.width-shift/2), 0),
Vec2f(static_cast<float>(size.width-shift), static_cast<float>(size.height-shift)),
Vec2f(static_cast<float>(shift/2), static_cast<float>(size.height-1)));
Mat warpMat = getPerspectiveTransform(srcVertices, dstVertices);
declare.in(src).out(dst);
2012-11-28 18:13:24 +08:00
declare.time(100);
TEST_CYCLE()
{
warpPerspective( src, dst, warpMat, size, interType, borderMode, borderColor );
}
#ifdef __ANDROID__
SANITY_CHECK(dst, interType==INTER_LINEAR? 5 : 10);
#else
SANITY_CHECK(dst, 1);
#endif
}
2012-08-10 21:17:09 +08:00
PERF_TEST_P( TestRemap, remap,
Combine(
Values( CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1 ),
Values( szVGA, sz1080p ),
InterType::all(),
BorderMode::all(),
RemapMode::all()
2012-08-10 21:17:09 +08:00
)
)
{
int type = get<0>(GetParam());
Size size = get<1>(GetParam());
int interpolationType = get<2>(GetParam());
int borderMode = get<3>(GetParam());
int remapMode = get<4>(GetParam());
unsigned int height = size.height;
unsigned int width = size.width;
Mat source(height, width, type);
Mat destination;
Mat map_x(height, width, CV_32F);
Mat map_y(height, width, CV_32F);
declare.in(source, WARMUP_RNG);
update_map(source, map_x, map_y, remapMode);
TEST_CYCLE()
{
remap(source, destination, map_x, map_y, interpolationType, borderMode);
}
SANITY_CHECK_NOTHING();
2012-08-10 21:17:09 +08:00
}
void update_map(const Mat& src, Mat& map_x, Mat& map_y, const int remapMode )
{
for( int j = 0; j < src.rows; j++ )
{
for( int i = 0; i < src.cols; i++ )
{
switch( remapMode )
{
case HALF_SIZE:
if( i > src.cols*0.25 && i < src.cols*0.75 && j > src.rows*0.25 && j < src.rows*0.75 )
{
2012-08-19 23:36:43 +08:00
map_x.at<float>(j,i) = 2*( i - src.cols*0.25f ) + 0.5f ;
map_y.at<float>(j,i) = 2*( j - src.rows*0.25f ) + 0.5f ;
2012-08-10 21:17:09 +08:00
}
else
{
map_x.at<float>(j,i) = 0 ;
map_y.at<float>(j,i) = 0 ;
}
break;
case UPSIDE_DOWN:
2012-08-19 23:36:43 +08:00
map_x.at<float>(j,i) = static_cast<float>(i) ;
map_y.at<float>(j,i) = static_cast<float>(src.rows - j) ;
2012-08-10 21:17:09 +08:00
break;
case REFLECTION_X:
2012-08-19 23:36:43 +08:00
map_x.at<float>(j,i) = static_cast<float>(src.cols - i) ;
map_y.at<float>(j,i) = static_cast<float>(j) ;
2012-08-10 21:17:09 +08:00
break;
case REFLECTION_BOTH:
2012-08-19 23:36:43 +08:00
map_x.at<float>(j,i) = static_cast<float>(src.cols - i) ;
map_y.at<float>(j,i) = static_cast<float>(src.rows - j) ;
2012-08-10 21:17:09 +08:00
break;
} // end of switch
}
}
}
PERF_TEST(Transform, getPerspectiveTransform_1000)
2012-08-10 21:17:09 +08:00
{
unsigned int size = 8;
Mat source(1, size/2, CV_32FC2);
Mat destination(1, size/2, CV_32FC2);
Mat transformCoefficient;
declare.in(source, destination, WARMUP_RNG);
PERF_SAMPLE_BEGIN()
for (int i = 0; i < 1000; i++)
2012-08-10 21:17:09 +08:00
{
transformCoefficient = getPerspectiveTransform(source, destination);
}
PERF_SAMPLE_END()
2012-10-09 01:31:07 +08:00
SANITY_CHECK_NOTHING();
2012-08-10 21:17:09 +08:00
}
PERF_TEST(Transform, getPerspectiveTransform_QR_1000)
{
unsigned int size = 8;
Mat source(1, size/2, CV_32FC2);
Mat destination(1, size/2, CV_32FC2);
Mat transformCoefficient;
declare.in(source, destination, WARMUP_RNG);
PERF_SAMPLE_BEGIN()
for (int i = 0; i < 1000; i++)
{
transformCoefficient = getPerspectiveTransform(source, destination, DECOMP_QR);
}
PERF_SAMPLE_END()
SANITY_CHECK_NOTHING();
}
} // namespace