mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 06:03:15 +08:00
Merge pull request #321 from apavlenko:warp_sanity_check
This commit is contained in:
commit
3c4cfccc88
@ -21,16 +21,14 @@ PERF_TEST_P(MatInfo_Size_Size, resizeUpLinear,
|
|||||||
Size from = get<1>(GetParam());
|
Size from = get<1>(GetParam());
|
||||||
Size to = get<2>(GetParam());
|
Size to = get<2>(GetParam());
|
||||||
|
|
||||||
cv::Mat src(from, matType);
|
cv::Mat src(from, matType), dst(to, matType);
|
||||||
cv::Mat dst(to, matType);
|
cvtest::fillGradient(src);
|
||||||
|
declare.in(src).out(dst);
|
||||||
declare.in(src, WARMUP_RNG).out(dst);
|
|
||||||
|
|
||||||
TEST_CYCLE() resize(src, dst, to);
|
TEST_CYCLE() resize(src, dst, to);
|
||||||
|
|
||||||
// Test case temporary disabled for Android Platform
|
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
SANITY_CHECK(dst, 255); // TODO: Reimplement check in future versions
|
SANITY_CHECK(dst, 5);
|
||||||
#else
|
#else
|
||||||
SANITY_CHECK(dst, 1 + 1e-6);
|
SANITY_CHECK(dst, 1 + 1e-6);
|
||||||
#endif
|
#endif
|
||||||
@ -50,16 +48,14 @@ PERF_TEST_P(MatInfo_Size_Size, resizeDownLinear,
|
|||||||
Size from = get<1>(GetParam());
|
Size from = get<1>(GetParam());
|
||||||
Size to = get<2>(GetParam());
|
Size to = get<2>(GetParam());
|
||||||
|
|
||||||
cv::Mat src(from, matType);
|
cv::Mat src(from, matType), dst(to, matType);
|
||||||
cv::Mat dst(to, matType);
|
cvtest::fillGradient(src);
|
||||||
|
declare.in(src).out(dst);
|
||||||
declare.in(src, WARMUP_RNG).out(dst);
|
|
||||||
|
|
||||||
TEST_CYCLE() resize(src, dst, to);
|
TEST_CYCLE() resize(src, dst, to);
|
||||||
|
|
||||||
// Test case temporary disabled for Android Platform
|
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
SANITY_CHECK(dst, 255); // TODO: Reimplement check in future versions
|
SANITY_CHECK(dst, 5);
|
||||||
#else
|
#else
|
||||||
SANITY_CHECK(dst, 1 + 1e-6);
|
SANITY_CHECK(dst, 1 + 1e-6);
|
||||||
#endif
|
#endif
|
||||||
|
@ -28,24 +28,23 @@ PERF_TEST_P( TestWarpAffine, WarpAffine,
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Size sz;
|
Size sz, szSrc(512, 512);
|
||||||
int borderMode, interType;
|
int borderMode, interType;
|
||||||
sz = get<0>(GetParam());
|
sz = get<0>(GetParam());
|
||||||
interType = get<1>(GetParam());
|
interType = get<1>(GetParam());
|
||||||
borderMode = get<2>(GetParam());
|
borderMode = get<2>(GetParam());
|
||||||
|
Scalar borderColor = Scalar::all(150);
|
||||||
|
|
||||||
Mat src, img = imread(getDataPath("cv/shared/fruits.png"));
|
Mat src(szSrc,CV_8UC4), dst(sz, CV_8UC4);
|
||||||
cvtColor(img, src, COLOR_BGR2RGBA, 4);
|
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 warpMat = getRotationMatrix2D(Point2f(src.cols/2.f, src.rows/2.f), 30., 2.2);
|
||||||
Mat dst(sz, CV_8UC4);
|
|
||||||
|
|
||||||
declare.in(src).out(dst);
|
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
|
#ifdef ANDROID
|
||||||
SANITY_CHECK(dst, 255); // TODO: Reimplement check in future versions
|
SANITY_CHECK(dst, interType==INTER_LINEAR? 5 : 10);
|
||||||
#else
|
#else
|
||||||
SANITY_CHECK(dst, 1);
|
SANITY_CHECK(dst, 1);
|
||||||
#endif
|
#endif
|
||||||
@ -59,15 +58,16 @@ PERF_TEST_P( TestWarpPerspective, WarpPerspective,
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Size sz;
|
Size sz, szSrc(512, 512);
|
||||||
int borderMode, interType;
|
int borderMode, interType;
|
||||||
sz = get<0>(GetParam());
|
sz = get<0>(GetParam());
|
||||||
interType = get<1>(GetParam());
|
interType = get<1>(GetParam());
|
||||||
borderMode = get<2>(GetParam());
|
borderMode = get<2>(GetParam());
|
||||||
|
Scalar borderColor = Scalar::all(150);
|
||||||
|
|
||||||
|
Mat src(szSrc,CV_8UC4), dst(sz, CV_8UC4);
|
||||||
Mat src, img = imread(getDataPath("cv/shared/fruits.png"));
|
cvtest::fillGradient(src);
|
||||||
cvtColor(img, src, COLOR_BGR2RGBA, 4);
|
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 rotMat = getRotationMatrix2D(Point2f(src.cols/2.f, src.rows/2.f), 30., 2.2);
|
||||||
Mat warpMat(3, 3, CV_64FC1);
|
Mat warpMat(3, 3, CV_64FC1);
|
||||||
for(int r=0; r<2; r++)
|
for(int r=0; r<2; r++)
|
||||||
@ -76,13 +76,16 @@ PERF_TEST_P( TestWarpPerspective, WarpPerspective,
|
|||||||
warpMat.at<double>(2, 0) = .3/sz.width;
|
warpMat.at<double>(2, 0) = .3/sz.width;
|
||||||
warpMat.at<double>(2, 1) = .3/sz.height;
|
warpMat.at<double>(2, 1) = .3/sz.height;
|
||||||
warpMat.at<double>(2, 2) = 1;
|
warpMat.at<double>(2, 2) = 1;
|
||||||
Mat dst(sz, CV_8UC4);
|
|
||||||
|
|
||||||
declare.in(src).out(dst);
|
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);
|
SANITY_CHECK(dst, 1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
PERF_TEST_P( TestWarpPerspectiveNear_t, WarpPerspectiveNear,
|
PERF_TEST_P( TestWarpPerspectiveNear_t, WarpPerspectiveNear,
|
||||||
@ -105,24 +108,11 @@ PERF_TEST_P( TestWarpPerspectiveNear_t, WarpPerspectiveNear,
|
|||||||
interType = get<1>(GetParam());
|
interType = get<1>(GetParam());
|
||||||
borderMode = get<2>(GetParam());
|
borderMode = get<2>(GetParam());
|
||||||
type = get<3>(GetParam());
|
type = get<3>(GetParam());
|
||||||
|
Scalar borderColor = Scalar::all(150);
|
||||||
|
|
||||||
Mat src, img = imread(getDataPath("cv/shared/5MP.png"));
|
Mat src(size, type), dst(size, type);
|
||||||
|
cvtest::fillGradient(src);
|
||||||
if( type == CV_8UC1 )
|
if(borderMode == BORDER_CONSTANT) cvtest::smoothBorder(src, borderColor, 1);
|
||||||
{
|
|
||||||
cvtColor(img, src, COLOR_BGR2GRAY, 1);
|
|
||||||
}
|
|
||||||
else if( type == CV_8UC4 )
|
|
||||||
{
|
|
||||||
cvtColor(img, src, COLOR_BGR2BGRA, 4);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
FAIL();
|
|
||||||
}
|
|
||||||
|
|
||||||
resize(src, src, size);
|
|
||||||
|
|
||||||
int shift = static_cast<int>(src.cols*0.04);
|
int shift = static_cast<int>(src.cols*0.04);
|
||||||
Mat srcVertices = (Mat_<Vec2f>(1, 4) << Vec2f(0, 0),
|
Mat srcVertices = (Mat_<Vec2f>(1, 4) << Vec2f(0, 0),
|
||||||
Vec2f(static_cast<float>(size.width-1), 0),
|
Vec2f(static_cast<float>(size.width-1), 0),
|
||||||
@ -134,19 +124,16 @@ PERF_TEST_P( TestWarpPerspectiveNear_t, WarpPerspectiveNear,
|
|||||||
Vec2f(static_cast<float>(shift/2), static_cast<float>(size.height-1)));
|
Vec2f(static_cast<float>(shift/2), static_cast<float>(size.height-1)));
|
||||||
Mat warpMat = getPerspectiveTransform(srcVertices, dstVertices);
|
Mat warpMat = getPerspectiveTransform(srcVertices, dstVertices);
|
||||||
|
|
||||||
Mat dst(size, type);
|
|
||||||
|
|
||||||
declare.in(src).out(dst);
|
declare.in(src).out(dst);
|
||||||
declare.time(100);
|
declare.time(100);
|
||||||
|
|
||||||
TEST_CYCLE()
|
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
|
#ifdef ANDROID
|
||||||
SANITY_CHECK(dst, 255); // TODO: Reimplement check in future versions
|
SANITY_CHECK(dst, interType==INTER_LINEAR? 5 : 10);
|
||||||
#else
|
#else
|
||||||
SANITY_CHECK(dst, 1);
|
SANITY_CHECK(dst, 1);
|
||||||
#endif
|
#endif
|
||||||
|
@ -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
|
// fills c with zeros
|
||||||
CV_EXPORTS void cvTsZero( CvMat* c, const CvMat* mask=0 );
|
CV_EXPORTS void cvTsZero( CvMat* c, const CvMat* mask=0 );
|
||||||
|
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
|
#if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
|
#define NOMINMAX
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
@ -582,6 +583,79 @@ void TS::printf( int streams, const char* fmt, ... )
|
|||||||
TS ts;
|
TS ts;
|
||||||
TS* TS::ptr() { return &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<img.rows; r++)
|
||||||
|
{
|
||||||
|
int kR = r % (2*n);
|
||||||
|
int valR = (kR<=n) ? delta*kR : delta*(2*n-kR);
|
||||||
|
for(c=0; c<img.cols; c++)
|
||||||
|
{
|
||||||
|
int kC = c % (2*n);
|
||||||
|
int valC = (kC<=n) ? delta*kC : delta*(2*n-kC);
|
||||||
|
uchar vals[] = {uchar(valR), uchar(valC), uchar(200*r/img.rows), uchar(255)};
|
||||||
|
uchar *p = img.ptr(r, c);
|
||||||
|
for(i=0; i<ch; i++) p[i] = vals[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void smoothBorder(Mat& img, const Scalar& color, int delta)
|
||||||
|
{
|
||||||
|
const int ch = img.channels();
|
||||||
|
CV_Assert(!img.empty() && img.depth() == CV_8U && ch <= 4);
|
||||||
|
|
||||||
|
Scalar s;
|
||||||
|
uchar *p = NULL;
|
||||||
|
int n = 100/delta;
|
||||||
|
int nR = std::min(n, (img.rows+1)/2), nC = std::min(n, (img.cols+1)/2);
|
||||||
|
|
||||||
|
int r, c, i;
|
||||||
|
for(r=0; r<nR; r++)
|
||||||
|
{
|
||||||
|
double k1 = r*delta/100., k2 = 1-k1;
|
||||||
|
for(c=0; c<img.cols; c++)
|
||||||
|
{
|
||||||
|
p = img.ptr(r, c);
|
||||||
|
for(i=0; i<ch; i++) s[i] = p[i];
|
||||||
|
s = s * k1 + color * k2;
|
||||||
|
for(i=0; i<ch; i++) p[i] = uchar(s[i]);
|
||||||
|
}
|
||||||
|
for(c=0; c<img.cols; c++)
|
||||||
|
{
|
||||||
|
p = img.ptr(img.rows-r-1, c);
|
||||||
|
for(i=0; i<ch; i++) s[i] = p[i];
|
||||||
|
s = s * k1 + color * k2;
|
||||||
|
for(i=0; i<ch; i++) p[i] = uchar(s[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(r=0; r<img.rows; r++)
|
||||||
|
{
|
||||||
|
for(c=0; c<nC; c++)
|
||||||
|
{
|
||||||
|
double k1 = c*delta/100., k2 = 1-k1;
|
||||||
|
p = img.ptr(r, c);
|
||||||
|
for(i=0; i<ch; i++) s[i] = p[i];
|
||||||
|
s = s * k1 + color * k2;
|
||||||
|
for(i=0; i<ch; i++) p[i] = uchar(s[i]);
|
||||||
|
}
|
||||||
|
for(c=0; c<n; c++)
|
||||||
|
{
|
||||||
|
double k1 = c*delta/100., k2 = 1-k1;
|
||||||
|
p = img.ptr(r, img.cols-c-1);
|
||||||
|
for(i=0; i<ch; i++) s[i] = p[i];
|
||||||
|
s = s * k1 + color * k2;
|
||||||
|
for(i=0; i<ch; i++) p[i] = uchar(s[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} //namespace cvtest
|
||||||
|
|
||||||
/* End of file. */
|
/* End of file. */
|
||||||
|
Loading…
Reference in New Issue
Block a user