From 81721d0dce7026b2c0db3fc90d9e715f08d1ace4 Mon Sep 17 00:00:00 2001 From: Andrey Pavlenko Date: Wed, 23 Jan 2013 17:25:30 +0400 Subject: [PATCH] enabling sanity checks for warp and resize functions on Android - add syntetic images generation function to ts - use generated syntetic images --- modules/imgproc/perf/perf_resize.cpp | 20 ++++------ modules/imgproc/perf/perf_warp.cpp | 59 +++++++++++----------------- modules/ts/include/opencv2/ts/ts.hpp | 9 +++++ modules/ts/src/ts.cpp | 74 ++++++++++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+), 48 deletions(-) diff --git a/modules/imgproc/perf/perf_resize.cpp b/modules/imgproc/perf/perf_resize.cpp index 82bf0d3..58e0583 100644 --- a/modules/imgproc/perf/perf_resize.cpp +++ b/modules/imgproc/perf/perf_resize.cpp @@ -21,16 +21,14 @@ PERF_TEST_P(MatInfo_Size_Size, resizeUpLinear, Size from = get<1>(GetParam()); Size to = get<2>(GetParam()); - cv::Mat src(from, matType); - cv::Mat dst(to, matType); - - declare.in(src, WARMUP_RNG).out(dst); + cv::Mat src(from, matType), dst(to, matType); + cvtest::fillGradient(src); + declare.in(src).out(dst); TEST_CYCLE() resize(src, dst, to); - // Test case temporary disabled for Android Platform #ifdef ANDROID - SANITY_CHECK(dst, 255); // TODO: Reimplement check in future versions + SANITY_CHECK(dst, 5); #else SANITY_CHECK(dst, 1 + 1e-6); #endif @@ -50,16 +48,14 @@ PERF_TEST_P(MatInfo_Size_Size, resizeDownLinear, Size from = get<1>(GetParam()); Size to = get<2>(GetParam()); - cv::Mat src(from, matType); - cv::Mat dst(to, matType); - - declare.in(src, WARMUP_RNG).out(dst); + cv::Mat src(from, matType), dst(to, matType); + cvtest::fillGradient(src); + declare.in(src).out(dst); TEST_CYCLE() resize(src, dst, to); - // Test case temporary disabled for Android Platform #ifdef ANDROID - SANITY_CHECK(dst, 255); // TODO: Reimplement check in future versions + SANITY_CHECK(dst, 5); #else SANITY_CHECK(dst, 1 + 1e-6); #endif diff --git a/modules/imgproc/perf/perf_warp.cpp b/modules/imgproc/perf/perf_warp.cpp index 1f2ffb6..f530df1 100644 --- a/modules/imgproc/perf/perf_warp.cpp +++ b/modules/imgproc/perf/perf_warp.cpp @@ -28,24 +28,23 @@ PERF_TEST_P( TestWarpAffine, WarpAffine, ) ) { - Size sz; + 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, img = imread(getDataPath("cv/shared/fruits.png")); - cvtColor(img, src, COLOR_BGR2RGBA, 4); + Mat src(szSrc,CV_8UC4), dst(sz, CV_8UC4); + 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); - Mat dst(sz, CV_8UC4); - declare.in(src).out(dst); - TEST_CYCLE() warpAffine( src, dst, warpMat, sz, interType, borderMode, Scalar::all(150) ); + TEST_CYCLE() warpAffine( src, dst, warpMat, sz, interType, borderMode, borderColor ); - // Test case temporary disabled for Android Platform #ifdef ANDROID - SANITY_CHECK(dst, 255); // TODO: Reimplement check in future versions + SANITY_CHECK(dst, interType==INTER_LINEAR? 5 : 10); #else SANITY_CHECK(dst, 1); #endif @@ -59,15 +58,16 @@ PERF_TEST_P( TestWarpPerspective, WarpPerspective, ) ) { - Size sz; + 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, img = imread(getDataPath("cv/shared/fruits.png")); - cvtColor(img, src, COLOR_BGR2RGBA, 4); + Mat src(szSrc,CV_8UC4), dst(sz, CV_8UC4); + 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++) @@ -76,13 +76,16 @@ PERF_TEST_P( TestWarpPerspective, WarpPerspective, warpMat.at(2, 0) = .3/sz.width; warpMat.at(2, 1) = .3/sz.height; warpMat.at(2, 2) = 1; - Mat dst(sz, CV_8UC4); declare.in(src).out(dst); - TEST_CYCLE() warpPerspective( src, dst, warpMat, sz, interType, borderMode, Scalar::all(150) ); + 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, @@ -105,24 +108,11 @@ PERF_TEST_P( TestWarpPerspectiveNear_t, WarpPerspectiveNear, interType = get<1>(GetParam()); borderMode = get<2>(GetParam()); type = get<3>(GetParam()); + Scalar borderColor = Scalar::all(150); - Mat src, img = imread(getDataPath("cv/shared/5MP.png")); - - if( type == CV_8UC1 ) - { - cvtColor(img, src, COLOR_BGR2GRAY, 1); - } - else if( type == CV_8UC4 ) - { - cvtColor(img, src, COLOR_BGR2BGRA, 4); - } - else - { - FAIL(); - } - - resize(src, src, size); - + Mat src(size, type), dst(size, type); + cvtest::fillGradient(src); + if(borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1); int shift = static_cast(src.cols*0.04); Mat srcVertices = (Mat_(1, 4) << Vec2f(0, 0), Vec2f(static_cast(size.width-1), 0), @@ -134,19 +124,16 @@ PERF_TEST_P( TestWarpPerspectiveNear_t, WarpPerspectiveNear, Vec2f(static_cast(shift/2), static_cast(size.height-1))); Mat warpMat = getPerspectiveTransform(srcVertices, dstVertices); - Mat dst(size, type); - declare.in(src).out(dst); declare.time(100); TEST_CYCLE() { - warpPerspective( src, dst, warpMat, size, interType, borderMode, Scalar::all(150) ); + warpPerspective( src, dst, warpMat, size, interType, borderMode, borderColor ); } - // Test case temporary disabled for Android Platform #ifdef ANDROID - SANITY_CHECK(dst, 255); // TODO: Reimplement check in future versions + SANITY_CHECK(dst, interType==INTER_LINEAR? 5 : 10); #else SANITY_CHECK(dst, 1); #endif diff --git a/modules/ts/include/opencv2/ts/ts.hpp b/modules/ts/include/opencv2/ts/ts.hpp index 061f53a..2ae94fd 100644 --- a/modules/ts/include/opencv2/ts/ts.hpp +++ b/modules/ts/include/opencv2/ts/ts.hpp @@ -547,6 +547,15 @@ struct CV_EXPORTS DefaultRngAuto } +namespace cvtest +{ + +// test images generation functions +CV_EXPORTS void fillGradient(Mat& img, int delta = 5); +CV_EXPORTS void smoothBorder(Mat& img, const Scalar& color, int delta = 3); + +} //namespace cvtest + // fills c with zeros CV_EXPORTS void cvTsZero( CvMat* c, const CvMat* mask=0 ); diff --git a/modules/ts/src/ts.cpp b/modules/ts/src/ts.cpp index 681f9bf..b611bf4 100644 --- a/modules/ts/src/ts.cpp +++ b/modules/ts/src/ts.cpp @@ -47,6 +47,7 @@ #include #if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64 #include +#define NOMINMAX #include #ifdef _MSC_VER @@ -582,6 +583,79 @@ void TS::printf( int streams, const char* fmt, ... ) TS ts; TS* TS::ptr() { return &ts; } +void fillGradient(Mat& img, int delta) +{ + const int ch = img.channels(); + CV_Assert(!img.empty() && img.depth() == CV_8U && ch <= 4); + + int n = 255 / delta; + int r, c, i; + for(r=0; r