Path: blob/master/modules/imgproc/perf/perf_warp.cpp
16339 views
// This file is part of OpenCV project.1// It is subject to the license terms in the LICENSE file found in the top-level directory2// of this distribution and at http://opencv.org/license.html.3#include "perf_precomp.hpp"45namespace opencv_test {67enum{HALF_SIZE=0, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH};89CV_ENUM(BorderMode, BORDER_CONSTANT, BORDER_REPLICATE)10CV_ENUM(InterType, INTER_NEAREST, INTER_LINEAR)11CV_ENUM(RemapMode, HALF_SIZE, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH)1213typedef TestBaseWithParam< tuple<Size, InterType, BorderMode> > TestWarpAffine;14typedef TestBaseWithParam< tuple<Size, InterType, BorderMode> > TestWarpPerspective;15typedef TestBaseWithParam< tuple<Size, InterType, BorderMode, MatType> > TestWarpPerspectiveNear_t;16typedef TestBaseWithParam< tuple<MatType, Size, InterType, BorderMode, RemapMode> > TestRemap;1718void update_map(const Mat& src, Mat& map_x, Mat& map_y, const int remapMode );1920PERF_TEST_P( TestWarpAffine, WarpAffine,21Combine(22Values( szVGA, sz720p, sz1080p ),23InterType::all(),24BorderMode::all()25)26)27{28Size sz, szSrc(512, 512);29int borderMode, interType;30sz = get<0>(GetParam());31interType = get<1>(GetParam());32borderMode = get<2>(GetParam());33Scalar borderColor = Scalar::all(150);3435Mat src(szSrc,CV_8UC4), dst(sz, CV_8UC4);36cvtest::fillGradient(src);37if(borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1);38Mat warpMat = getRotationMatrix2D(Point2f(src.cols/2.f, src.rows/2.f), 30., 2.2);39declare.in(src).out(dst);4041TEST_CYCLE() warpAffine( src, dst, warpMat, sz, interType, borderMode, borderColor );4243#ifdef __ANDROID__44SANITY_CHECK(dst, interType==INTER_LINEAR? 5 : 10);45#else46SANITY_CHECK(dst, 1);47#endif48}4950PERF_TEST_P(TestWarpAffine, WarpAffine_ovx,51Combine(52Values(szVGA, sz720p, sz1080p),53InterType::all(),54BorderMode::all()55)56)57{58Size sz, szSrc(512, 512);59int borderMode, interType;60sz = get<0>(GetParam());61interType = get<1>(GetParam());62borderMode = get<2>(GetParam());63Scalar borderColor = Scalar::all(150);6465Mat src(szSrc, CV_8UC1), dst(sz, CV_8UC1);66cvtest::fillGradient(src);67if (borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1);68Mat warpMat = getRotationMatrix2D(Point2f(src.cols / 2.f, src.rows / 2.f), 30., 2.2);69declare.in(src).out(dst);7071TEST_CYCLE() warpAffine(src, dst, warpMat, sz, interType, borderMode, borderColor);7273#ifdef __ANDROID__74SANITY_CHECK(dst, interType == INTER_LINEAR ? 5 : 10);75#else76SANITY_CHECK(dst, 1);77#endif78}7980PERF_TEST_P( TestWarpPerspective, WarpPerspective,81Combine(82Values( szVGA, sz720p, sz1080p ),83InterType::all(),84BorderMode::all()85)86)87{88Size sz, szSrc(512, 512);89int borderMode, interType;90sz = get<0>(GetParam());91interType = get<1>(GetParam());92borderMode = get<2>(GetParam());93Scalar borderColor = Scalar::all(150);9495Mat src(szSrc,CV_8UC4), dst(sz, CV_8UC4);96cvtest::fillGradient(src);97if(borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1);98Mat rotMat = getRotationMatrix2D(Point2f(src.cols/2.f, src.rows/2.f), 30., 2.2);99Mat warpMat(3, 3, CV_64FC1);100for(int r=0; r<2; r++)101for(int c=0; c<3; c++)102warpMat.at<double>(r, c) = rotMat.at<double>(r, c);103warpMat.at<double>(2, 0) = .3/sz.width;104warpMat.at<double>(2, 1) = .3/sz.height;105warpMat.at<double>(2, 2) = 1;106107declare.in(src).out(dst);108109TEST_CYCLE() warpPerspective( src, dst, warpMat, sz, interType, borderMode, borderColor );110111#ifdef __ANDROID__112SANITY_CHECK(dst, interType==INTER_LINEAR? 5 : 10);113#else114SANITY_CHECK(dst, 1);115#endif116}117118PERF_TEST_P(TestWarpPerspective, WarpPerspective_ovx,119Combine(120Values(szVGA, sz720p, sz1080p),121InterType::all(),122BorderMode::all()123)124)125{126Size sz, szSrc(512, 512);127int borderMode, interType;128sz = get<0>(GetParam());129interType = get<1>(GetParam());130borderMode = get<2>(GetParam());131Scalar borderColor = Scalar::all(150);132133Mat src(szSrc, CV_8UC1), dst(sz, CV_8UC1);134cvtest::fillGradient(src);135if (borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1);136Mat rotMat = getRotationMatrix2D(Point2f(src.cols / 2.f, src.rows / 2.f), 30., 2.2);137Mat warpMat(3, 3, CV_64FC1);138for (int r = 0; r<2; r++)139for (int c = 0; c<3; c++)140warpMat.at<double>(r, c) = rotMat.at<double>(r, c);141warpMat.at<double>(2, 0) = .3 / sz.width;142warpMat.at<double>(2, 1) = .3 / sz.height;143warpMat.at<double>(2, 2) = 1;144145declare.in(src).out(dst);146147TEST_CYCLE() warpPerspective(src, dst, warpMat, sz, interType, borderMode, borderColor);148149#ifdef __ANDROID__150SANITY_CHECK(dst, interType == INTER_LINEAR ? 5 : 10);151#else152SANITY_CHECK(dst, 1);153#endif154}155156PERF_TEST_P( TestWarpPerspectiveNear_t, WarpPerspectiveNear,157Combine(158Values( Size(640,480), Size(1920,1080), Size(2592,1944) ),159InterType::all(),160BorderMode::all(),161Values( CV_8UC1, CV_8UC4 )162)163)164{165Size size;166int borderMode, interType, type;167size = get<0>(GetParam());168interType = get<1>(GetParam());169borderMode = get<2>(GetParam());170type = get<3>(GetParam());171Scalar borderColor = Scalar::all(150);172173Mat src(size, type), dst(size, type);174cvtest::fillGradient(src);175if(borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1);176int shift = static_cast<int>(src.cols*0.04);177Mat srcVertices = (Mat_<Vec2f>(1, 4) << Vec2f(0, 0),178Vec2f(static_cast<float>(size.width-1), 0),179Vec2f(static_cast<float>(size.width-1), static_cast<float>(size.height-1)),180Vec2f(0, static_cast<float>(size.height-1)));181Mat dstVertices = (Mat_<Vec2f>(1, 4) << Vec2f(0, static_cast<float>(shift)),182Vec2f(static_cast<float>(size.width-shift/2), 0),183Vec2f(static_cast<float>(size.width-shift), static_cast<float>(size.height-shift)),184Vec2f(static_cast<float>(shift/2), static_cast<float>(size.height-1)));185Mat warpMat = getPerspectiveTransform(srcVertices, dstVertices);186187declare.in(src).out(dst);188declare.time(100);189190TEST_CYCLE()191{192warpPerspective( src, dst, warpMat, size, interType, borderMode, borderColor );193}194195#ifdef __ANDROID__196SANITY_CHECK(dst, interType==INTER_LINEAR? 5 : 10);197#else198SANITY_CHECK(dst, 1);199#endif200}201202PERF_TEST_P( TestRemap, remap,203Combine(204Values( CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1 ),205Values( szVGA, sz1080p ),206InterType::all(),207BorderMode::all(),208RemapMode::all()209)210)211{212int type = get<0>(GetParam());213Size size = get<1>(GetParam());214int interpolationType = get<2>(GetParam());215int borderMode = get<3>(GetParam());216int remapMode = get<4>(GetParam());217unsigned int height = size.height;218unsigned int width = size.width;219Mat source(height, width, type);220Mat destination;221Mat map_x(height, width, CV_32F);222Mat map_y(height, width, CV_32F);223224declare.in(source, WARMUP_RNG);225226update_map(source, map_x, map_y, remapMode);227228TEST_CYCLE()229{230remap(source, destination, map_x, map_y, interpolationType, borderMode);231}232233SANITY_CHECK_NOTHING();234}235236void update_map(const Mat& src, Mat& map_x, Mat& map_y, const int remapMode )237{238for( int j = 0; j < src.rows; j++ )239{240for( int i = 0; i < src.cols; i++ )241{242switch( remapMode )243{244case HALF_SIZE:245if( i > src.cols*0.25 && i < src.cols*0.75 && j > src.rows*0.25 && j < src.rows*0.75 )246{247map_x.at<float>(j,i) = 2*( i - src.cols*0.25f ) + 0.5f ;248map_y.at<float>(j,i) = 2*( j - src.rows*0.25f ) + 0.5f ;249}250else251{252map_x.at<float>(j,i) = 0 ;253map_y.at<float>(j,i) = 0 ;254}255break;256case UPSIDE_DOWN:257map_x.at<float>(j,i) = static_cast<float>(i) ;258map_y.at<float>(j,i) = static_cast<float>(src.rows - j) ;259break;260case REFLECTION_X:261map_x.at<float>(j,i) = static_cast<float>(src.cols - i) ;262map_y.at<float>(j,i) = static_cast<float>(j) ;263break;264case REFLECTION_BOTH:265map_x.at<float>(j,i) = static_cast<float>(src.cols - i) ;266map_y.at<float>(j,i) = static_cast<float>(src.rows - j) ;267break;268} // end of switch269}270}271}272273PERF_TEST(Transform, getPerspectiveTransform_1000)274{275unsigned int size = 8;276Mat source(1, size/2, CV_32FC2);277Mat destination(1, size/2, CV_32FC2);278Mat transformCoefficient;279280declare.in(source, destination, WARMUP_RNG);281282PERF_SAMPLE_BEGIN()283for (int i = 0; i < 1000; i++)284{285transformCoefficient = getPerspectiveTransform(source, destination);286}287PERF_SAMPLE_END()288289SANITY_CHECK_NOTHING();290}291292PERF_TEST(Transform, getPerspectiveTransform_QR_1000)293{294unsigned int size = 8;295Mat source(1, size/2, CV_32FC2);296Mat destination(1, size/2, CV_32FC2);297Mat transformCoefficient;298299declare.in(source, destination, WARMUP_RNG);300301PERF_SAMPLE_BEGIN()302for (int i = 0; i < 1000; i++)303{304transformCoefficient = getPerspectiveTransform(source, destination, DECOMP_QR);305}306PERF_SAMPLE_END()307308SANITY_CHECK_NOTHING();309}310311} // namespace312313314