fixed some warnings and errors on windows

pull/31/head
Ilya Lavrenov 13 years ago
parent b1b5e392e6
commit fbd9bfba47
  1. 242
      modules/imgproc/test/test_imgwarp_strict.cpp

@ -58,7 +58,7 @@ namespace internal
cvtest::TS::ptr()->printf(cvtest::TS::SUMMARY, buffer);
va_end(args);
}
#define PRINT_TO_LOG __wrap_printf_func
}
@ -78,7 +78,7 @@ public:
CV_ImageWarpBaseTest();
virtual ~CV_ImageWarpBaseTest();
virtual void run(int);
protected:
virtual void generate_test_data();
@ -89,7 +89,7 @@ protected:
virtual void prepare_test_data_for_reference_func();
Size randSize(RNG& rng) const;
const char* interpolation_to_string(int inter_type) const;
int interpolation;
@ -130,8 +130,8 @@ const char* CV_ImageWarpBaseTest::interpolation_to_string(int inter) const
Size CV_ImageWarpBaseTest::randSize(RNG& rng) const
{
Size size;
size.width = saturate_cast<uint>(std::exp(rng.uniform(1.0f, 7.0f)));
size.height = saturate_cast<uint>(std::exp(rng.uniform(1.0f, 7.0f)));
size.width = static_cast<int>(std::exp(rng.uniform(1.0f, 7.0f)));
size.height = static_cast<int>(std::exp(rng.uniform(1.0f, 7.0f)));
return size;
}
@ -150,7 +150,7 @@ void CV_ImageWarpBaseTest::generate_test_data()
int cn = rng.uniform(1, 4);
while (cn == 2)
cn = rng.uniform(1, 4);
src.create(ssize, CV_MAKE_TYPE(depth, cn));
// generating the src matrix
@ -170,10 +170,10 @@ void CV_ImageWarpBaseTest::generate_test_data()
for (x = cell_size; x < src.cols; x += cell_size)
line(src, Point2i(x, 0), Point2i(x, src.rows), Scalar::all(0), 1);
}
// generating an interpolation type
interpolation = rng.uniform(0, CV_INTER_LANCZOS4 + 1);
// generating the dst matrix structure
double scale_x = 2, scale_y = 2;
if (interpolation == INTER_AREA)
@ -196,13 +196,13 @@ void CV_ImageWarpBaseTest::generate_test_data()
scale_y = rng.uniform(0.4, 4.0);
}
CV_Assert(scale_x > 0.0f && scale_y > 0.0f);
dsize.width = saturate_cast<int>((ssize.width + scale_x - 1) / scale_x);
dsize.height = saturate_cast<int>((ssize.height + scale_y - 1) / scale_y);
dst = Mat::zeros(dsize, src.type());
reference_dst = Mat::zeros(dst.size(), CV_MAKE_TYPE(CV_32F, dst.channels()));
if (interpolation == INTER_AREA && (scale_x < 1.0 || scale_y < 1.0))
interpolation = INTER_LINEAR;
}
@ -228,7 +228,7 @@ void CV_ImageWarpBaseTest::validate_results() const
{
Mat _dst;
dst.convertTo(_dst, reference_dst.depth());
Size dsize = dst.size(), ssize = src.size();
int cn = _dst.channels();
dsize.width *= cn;
@ -241,12 +241,12 @@ void CV_ImageWarpBaseTest::validate_results() const
t = 1.0f;
else if (interpolation == INTER_AREA)
t = 2.0f;
for (int dy = 0; dy < dsize.height; ++dy)
{
const float* rD = reference_dst.ptr<float>(dy);
const float* D = _dst.ptr<float>(dy);
for (int dx = 0; dx < dsize.width; ++dx)
if (fabs(rD[dx] - D[dx]) > t &&
// fabs(rD[dx] - D[dx]) < 250.0f &&
@ -257,7 +257,7 @@ void CV_ImageWarpBaseTest::validate_results() const
PRINT_TO_LOG("Tuple (rD, D): (%f, %f)\n", rD[dx], D[dx]);
PRINT_TO_LOG("Dsize: (%d, %d)\n", dsize.width / cn, dsize.height);
PRINT_TO_LOG("Ssize: (%d, %d)\n", src.cols, src.rows);
float scale_x = static_cast<float>(ssize.width) / dsize.width,
scale_y = static_cast<float>(ssize.height) / dsize.height;
PRINT_TO_LOG("Interpolation: %s\n", interpolation_to_string(interpolation == INTER_AREA &&
@ -266,32 +266,32 @@ void CV_ImageWarpBaseTest::validate_results() const
PRINT_TO_LOG("Scale (x, y): (%lf, %lf)\n", scale_x, scale_y);
PRINT_TO_LOG("Elemsize: %d\n", src.elemSize1());
PRINT_TO_LOG("Channels: %d\n", cn);
#ifdef SHOW_IMAGE
const std::string w1("OpenCV impl (run func)"), w2("Reference func"), w3("Src image"), w4("Diff");
namedWindow(w1, CV_WINDOW_KEEPRATIO);
namedWindow(w2, CV_WINDOW_KEEPRATIO);
namedWindow(w3, CV_WINDOW_KEEPRATIO);
namedWindow(w4, CV_WINDOW_KEEPRATIO);
Mat diff;
absdiff(reference_dst, _dst, diff);
imshow(w1, dst);
imshow(w2, reference_dst);
imshow(w3, src);
imshow(w4, diff);
waitKey();
#endif
const int radius = 3;
int rmin = MAX(dy - radius, 0), rmax = MIN(dy + radius, dsize.height);
int cmin = MAX(dx / cn - radius, 0), cmax = MIN(dx / cn + radius, dsize.width);
std::cout << "opencv result:\n" << dst(Range(rmin, rmax), Range(cmin, cmax)) << std::endl;
std::cout << "reference result:\n" << reference_dst(Range(rmin, rmax), Range(cmin, cmax)) << std::endl;
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
return;
}
@ -324,7 +324,7 @@ protected:
virtual void run_func();
virtual void run_reference_func();
private:
double scale_x;
double scale_y;
@ -333,7 +333,7 @@ private:
void resize_generic();
void resize_area();
double getWeight(double a, double b, int x);
typedef std::vector<std::pair<int, double> > dim;
void generate_buffer(double scale, dim& _dim);
void resize_1d(const Mat& _src, Mat& _dst, int dy, const dim& _dim);
@ -356,23 +356,23 @@ namespace internal
coeffs[0] = 1.f - x;
coeffs[1] = x;
}
void interpolateCubic(float x, float* coeffs)
{
const float A = -0.75f;
coeffs[0] = ((A*(x + 1) - 5*A)*(x + 1) + 8*A)*(x + 1) - 4*A;
coeffs[1] = ((A + 2)*x - (A + 3))*x*x + 1;
coeffs[2] = ((A + 2)*(1 - x) - (A + 3))*(1 - x)*(1 - x) + 1;
coeffs[3] = 1.f - coeffs[0] - coeffs[1] - coeffs[2];
}
void interpolateLanczos4(float x, float* coeffs)
{
static const double s45 = 0.70710678118654752440084436210485;
static const double cs[][2]=
{{1, 0}, {-s45, -s45}, {0, 1}, {s45, -s45}, {-1, 0}, {s45, s45}, {0, -1}, {-s45, s45}};
if( x < FLT_EPSILON )
{
for( int i = 0; i < 8; i++ )
@ -380,7 +380,7 @@ namespace internal
coeffs[3] = 1;
return;
}
float sum = 0;
double y0=-(x+3)*CV_PI*0.25, s0 = sin(y0), c0=cos(y0);
for(int i = 0; i < 8; i++ )
@ -389,12 +389,12 @@ namespace internal
coeffs[i] = (float)((cs[i][0]*s0 + cs[i][1]*c0)/(y*y));
sum += coeffs[i];
}
sum = 1.f/sum;
for(int i = 0; i < 8; i++ )
coeffs[i] *= sum;
}
typedef void (*interpolate_method)(float x, float* coeffs);
interpolate_method inter_array[] = { &interpolateLinear, &interpolateCubic, &interpolateLanczos4 };
}
@ -402,10 +402,10 @@ namespace internal
void CV_Resize_Test::generate_test_data()
{
CV_ImageWarpBaseTest::generate_test_data();
scale_x = src.cols / static_cast<double>(dst.cols);
scale_y = src.rows / static_cast<double>(dst.rows);
area_fast = interpolation == INTER_AREA &&
fabs(scale_x - cvRound(scale_x)) < FLT_EPSILON &&
fabs(scale_y - cvRound(scale_y)) < FLT_EPSILON;
@ -424,7 +424,7 @@ void CV_Resize_Test::run_func()
void CV_Resize_Test::run_reference_func()
{
CV_ImageWarpBaseTest::prepare_test_data_for_reference_func();
if (interpolation == INTER_AREA)
resize_area();
else
@ -433,7 +433,7 @@ void CV_Resize_Test::run_reference_func()
double CV_Resize_Test::getWeight(double a, double b, int x)
{
float w = std::min<double>(x + 1, b) - std::max<double>(x, a);
float w = std::min(static_cast<double>(x + 1), b) - std::max(static_cast<double>(x), a);
CV_Assert(w >= 0);
return w;
}
@ -441,28 +441,28 @@ double CV_Resize_Test::getWeight(double a, double b, int x)
void CV_Resize_Test::resize_area()
{
Size ssize = src.size(), dsize = reference_dst.size();
CV_Assert(ssize.area() > 0 && dsize.area() > 0);
CV_Assert(ssize.area() > 0 && dsize.area() > 0);
int cn = src.channels();
CV_Assert(scale_x >= 1.0 && scale_y >= 1.0);
CV_Assert(scale_x >= 1.0 && scale_y >= 1.0);
double fsy0 = 0, fsy1 = scale_y;
for (int dy = 0; dy < dsize.height; ++dy)
{
float* yD = reference_dst.ptr<float>(dy);
int isy0 = cvFloor(fsy0), isy1 = std::min(cvFloor(fsy1), ssize.height - 1);
CV_Assert(isy1 <= ssize.height && isy0 < ssize.height);
float fsx0 = 0, fsx1 = scale_x;
double fsx0 = 0, fsx1 = scale_x;
for (int dx = 0; dx < dsize.width; ++dx)
{
float* xyD = yD + cn * dx;
int isx0 = cvFloor(fsx0), isx1 = std::min(ssize.width - 1, cvFloor(fsx1));
CV_Assert(isx1 <= ssize.width);
CV_Assert(isx0 < ssize.width);
// for each pixel of dst
for (int r = 0; r < cn; ++r)
{
@ -476,37 +476,37 @@ void CV_Resize_Test::resize_area()
double wy = getWeight(fsy0, fsy1, sy);
double wx = getWeight(fsx0, fsx1, sx);
double w = wx * wy;
xyD[r] += yS[sx * cn + r] * w;
xyD[r] += static_cast<float>(yS[sx * cn + r] * w);
area += w;
}
}
CV_Assert(area != 0);
// norming pixel
xyD[r] /= area;
xyD[r] = static_cast<float>(xyD[r] / area);
}
fsx1 = std::min<double>((fsx0 = fsx1) + scale_x, ssize.width);
fsx1 = std::min((fsx0 = fsx1) + scale_x, static_cast<double>(ssize.width));
}
fsy1 = std::min<double>((fsy0 = fsy1) + scale_y, ssize.height);
fsy1 = std::min((fsy0 = fsy1) + scale_y, static_cast<double>(ssize.height));
}
}
// for interpolation type : INTER_LINEAR, INTER_LINEAR, INTER_CUBIC, INTER_LANCZOS4
void CV_Resize_Test::resize_1d(const Mat& _src, Mat& _dst, int dy, const dim& _dim)
{
Size dsize = _dst.size();
Size dsize = _dst.size();
int cn = _dst.channels();
float* yD = _dst.ptr<float>(dy);
if (interpolation == INTER_NEAREST)
{
const float* yS = _src.ptr<float>(dy);
for (int dx = 0; dx < dsize.width; ++dx)
{
int isx = _dim[dx].first;
const float* xyS = yS + isx * cn;
float* xyD = yD + dx * cn;
const float* xyS = yS + isx * cn;
float* xyD = yD + dx * cn;
for (int r = 0; r < cn; ++r)
xyD[r] = xyS[r];
}
@ -515,13 +515,13 @@ void CV_Resize_Test::resize_1d(const Mat& _src, Mat& _dst, int dy, const dim& _d
{
internal::interpolate_method inter_func = internal::inter_array[interpolation - (interpolation == INTER_LANCZOS4 ? 2 : 1)];
int elemsize = _src.elemSize();
int ofs = 0, ksize = 2;
if (interpolation == INTER_CUBIC)
ofs = 1, ksize = 4;
else if (interpolation == INTER_LANCZOS4)
ofs = 3, ksize = 8;
Mat _extended_src_row(1, _src.cols + ksize * 2, _src.type());
uchar* srow = _src.data + dy * _src.step;
memcpy(_extended_src_row.data + elemsize * ksize, srow, _src.step);
@ -530,7 +530,7 @@ void CV_Resize_Test::resize_1d(const Mat& _src, Mat& _dst, int dy, const dim& _d
memcpy(_extended_src_row.data + k * elemsize, srow, elemsize);
memcpy(_extended_src_row.data + (ksize + k) * elemsize + _src.step, srow + _src.step - elemsize, elemsize);
}
for (int dx = 0; dx < dsize.width; ++dx)
{
int isx = _dim[dx].first;
@ -539,8 +539,8 @@ void CV_Resize_Test::resize_1d(const Mat& _src, Mat& _dst, int dy, const dim& _d
float *xyD = yD + dx * cn;
const float* xyS = _extended_src_row.ptr<float>(0) + (isx + ksize - ofs) * cn;
float w[ksize];
inter_func(fsx, w);
float w[8];
inter_func(static_cast<float>(fsx), w);
for (int r = 0; r < cn; ++r)
{
@ -559,7 +559,7 @@ void CV_Resize_Test::generate_buffer(double scale, dim& _dim)
{
int length = _dim.size();
for (int dx = 0; dx < length; ++dx)
{
{
double fsx = scale * (dx + 0.5f) - 0.5f;
int isx = cvFloor(fsx);
_dim[dx] = std::make_pair(isx, fsx - isx);
@ -570,12 +570,12 @@ void CV_Resize_Test::resize_generic()
{
Size dsize = reference_dst.size(), ssize = src.size();
CV_Assert(dsize.area() > 0 && ssize.area() > 0);
dim dims[] = { dim(dsize.width), dim(dsize.height) };
if (interpolation == INTER_NEAREST)
{
for (int dx = 0; dx < dsize.width; ++dx)
dims[0][dx].first = std::min(cvFloor(dx * scale_x), ssize.width - 1);
dims[0][dx].first = std::min(cvFloor(dx * scale_x), ssize.width - 1);
for (int dy = 0; dy < dsize.height; ++dy)
dims[1][dy].first = std::min(cvFloor(dy * scale_y), ssize.height - 1);
}
@ -584,14 +584,14 @@ void CV_Resize_Test::resize_generic()
generate_buffer(scale_x, dims[0]);
generate_buffer(scale_y, dims[1]);
}
Mat tmp(ssize.height, dsize.width, reference_dst.type());
for (int dy = 0; dy < tmp.rows; ++dy)
resize_1d(src, tmp, dy, dims[0]);
transpose(tmp, tmp);
transpose(reference_dst, reference_dst);
for (int dy = 0; dy < tmp.rows; ++dy)
resize_1d(tmp, reference_dst, dy, dims[1]);
transpose(reference_dst, reference_dst);
@ -624,7 +624,7 @@ protected:
Scalar borderValue;
remap_func funcs[2];
private:
void remap_nearest(const Mat&, Mat&);
void remap_generic(const Mat&, Mat&);
@ -661,7 +661,7 @@ void CV_Remap_Test::generate_test_data()
const int n = std::min(std::min(src.cols, src.rows) / 10 + 1, 2);
float _n = 0; //static_cast<float>(-n);
switch (mapx.type())
{
case CV_16SC2:
@ -669,8 +669,8 @@ void CV_Remap_Test::generate_test_data()
MatIterator_<Vec2s> begin_x = mapx.begin<Vec2s>(), end_x = mapx.end<Vec2s>();
for ( ; begin_x != end_x; ++begin_x)
{
begin_x[0] = rng.uniform(static_cast<int>(_n), std::max(src.cols + n - 1, 0));
begin_x[1] = rng.uniform(static_cast<int>(_n), std::max(src.rows + n - 1, 0));
begin_x[0] = static_cast<short>(rng.uniform(static_cast<int>(_n), std::max(src.cols + n - 1, 0)));
begin_x[1] = static_cast<short>(rng.uniform(static_cast<int>(_n), std::max(src.rows + n - 1, 0)));
}
if (interpolation != INTER_NEAREST)
@ -684,7 +684,7 @@ void CV_Remap_Test::generate_test_data()
{
MatIterator_<ushort> begin_y = mapy.begin<ushort>(), end_y = mapy.end<ushort>();
for ( ; begin_y != end_y; ++begin_y)
begin_y[0] = rng.uniform(0, 1024);
begin_y[0] = static_cast<short>(rng.uniform(0, 1024));
}
break;
@ -692,7 +692,7 @@ void CV_Remap_Test::generate_test_data()
{
MatIterator_<short> begin_y = mapy.begin<short>(), end_y = mapy.end<short>();
for ( ; begin_y != end_y; ++begin_y)
begin_y[0] = rng.uniform(0, 1024);
begin_y[0] = static_cast<short>(rng.uniform(0, 1024));
}
break;
}
@ -727,7 +727,7 @@ void CV_Remap_Test::generate_test_data()
}
}
break;
default:
assert(0);
break;
@ -746,10 +746,10 @@ void CV_Remap_Test::convert_maps()
else if (interpolation != INTER_NEAREST)
if (mapy.type() != CV_16UC1)
mapy.clone().convertTo(mapy, CV_16UC1);
if (interpolation == INTER_NEAREST)
mapy = Mat();
CV_Assert(( (interpolation == INTER_NEAREST && !mapy.data) || mapy.type() == CV_16UC1 ||
CV_Assert(((interpolation == INTER_NEAREST && !mapy.data) || mapy.type() == CV_16UC1 ||
mapy.type() == CV_16SC1) && mapx.type() == CV_16SC2);
}
@ -793,7 +793,7 @@ void CV_Remap_Test::run_reference_func()
if (interpolation == INTER_AREA)
interpolation = INTER_LINEAR;
int index = interpolation == INTER_NEAREST ? 0 : 1;
(this->*funcs[index])(src, reference_dst);
}
@ -811,7 +811,7 @@ void CV_Remap_Test::remap_nearest(const Mat& _src, Mat& _dst)
{
const short* yM = mapx.ptr<short>(dy);
float* yD = _dst.ptr<float>(dy);
for (int dx = 0; dx < dsize.width; ++dx)
{
float* xyD = yD + cn * dx;
@ -828,7 +828,7 @@ void CV_Remap_Test::remap_nearest(const Mat& _src, Mat& _dst)
{
if (borderType == BORDER_CONSTANT)
for (int r = 0; r < cn; ++r)
xyD[r] = borderValue[r];
xyD[r] = saturate_cast<float>(borderValue[r]);
else
{
sx = borderInterpolate(sx, ssize.width, borderType);
@ -848,19 +848,16 @@ void CV_Remap_Test::remap_nearest(const Mat& _src, Mat& _dst)
void CV_Remap_Test::remap_generic(const Mat& _src, Mat& _dst)
{
CV_Assert(mapx.type() == CV_16SC2 && mapy.type() == CV_16UC1);
int ksize;
if (interpolation == INTER_LINEAR)
ksize = 2;
else if (interpolation == INTER_CUBIC)
int ksize = 2;
if (interpolation == INTER_CUBIC)
ksize = 4;
else if (interpolation == INTER_LANCZOS4)
ksize = 8;
else
ksize = 0;
assert(ksize);
else if (interpolation != INTER_LINEAR)
assert(0);
int ofs = (ksize / 2) - 1;
CV_Assert(_src.depth() == CV_32F && _dst.type() == _src.type());
Size ssize = _src.size(), dsize = _dst.size();
int cn = _src.channels(), width1 = std::max(ssize.width - ksize + 1, 0),
@ -875,7 +872,7 @@ void CV_Remap_Test::remap_generic(const Mat& _src, Mat& _dst)
const ushort* yMy = mapy.ptr<ushort>(dy);
float* yD = _dst.ptr<float>(dy);
for (int dx = 0; dx < dsize.width; ++dx)
{
float* xyD = yD + dx * cn;
@ -884,7 +881,7 @@ void CV_Remap_Test::remap_generic(const Mat& _src, Mat& _dst)
inter_func((yMy[dx] & (INTER_TAB_SIZE - 1)) / static_cast<float>(INTER_TAB_SIZE), w);
inter_func(((yMy[dx] >> INTER_BITS) & (INTER_TAB_SIZE - 1)) / static_cast<float>(INTER_TAB_SIZE), w + ksize);
isx -= ofs;
isy -= ofs;
@ -908,7 +905,7 @@ void CV_Remap_Test::remap_generic(const Mat& _src, Mat& _dst)
else if (borderType != BORDER_TRANSPARENT)
{
int ar_x[8], ar_y[8];
for (int k = 0; k < ksize; k++)
{
ar_x[k] = borderInterpolate(isx + k, ssize.width, borderType) * cn;
@ -925,14 +922,14 @@ void CV_Remap_Test::remap_generic(const Mat& _src, Mat& _dst)
{
const float* yS = _src.ptr<float>(ar_y[i]);
for (int j = 0; j < ksize; ++j)
ix[i] += (ar_x[j] >= 0 ? yS[ar_x[j] + r] : borderValue[r]) * w[j];
ix[i] += saturate_cast<float>((ar_x[j] >= 0 ? yS[ar_x[j] + r] : borderValue[r]) * w[j]);
}
else
for (int j = 0; j < ksize; ++j)
ix[i] += borderValue[r] * w[j];
ix[i] += saturate_cast<float>(borderValue[r] * w[j]);
}
for (int i = 0; i < ksize; ++i)
xyD[r] += w[ksize + i] * ix[i];
xyD[r] += saturate_cast<float>(w[ksize + i] * ix[i]);
}
}
}
@ -1002,7 +999,7 @@ void CV_WarpAffine_Test::generate_test_data()
M.convertTo(tmp, depth);
M = tmp;
}
// warp_matrix is inverse
if (rng.uniform(0., 1.) > 0)
interpolation |= CV_WARP_INVERSE_MAP;
@ -1035,7 +1032,7 @@ void CV_WarpAffine_Test::warpAffine(const Mat& _src, Mat& _dst)
Mat tM;
M.convertTo(tM, CV_64F);
int inter = interpolation & INTER_MAX;
if (inter == INTER_AREA)
inter = INTER_LINEAR;
@ -1045,35 +1042,35 @@ void CV_WarpAffine_Test::warpAffine(const Mat& _src, Mat& _dst)
mapy.create(dsize, CV_16SC1);
else
mapy = Mat();
if (!(interpolation & CV_WARP_INVERSE_MAP))
invertAffineTransform(tM.clone(), tM);
const int AB_BITS = MAX(10, (int)INTER_BITS);
const int AB_SCALE = 1 << AB_BITS;
const int AB_SCALE = 1 << AB_BITS;
int round_delta = (inter == INTER_NEAREST) ? AB_SCALE / 2 : (AB_SCALE / INTER_TAB_SIZE / 2);
const double* data_tM = tM.ptr<double>(0);
for (int dy = 0; dy < dsize.height; ++dy)
{
short* yM = mapx.ptr<short>(dy);
for (int dx = 0; dx < dsize.width; ++dx, yM += 2)
{
int v1 = saturate_cast<int>(saturate_cast<int>(data_tM[0] * dx * AB_SCALE) +
saturate_cast<int>((data_tM[1] * dy + data_tM[2]) * AB_SCALE) + round_delta),
v2 = saturate_cast<int>(saturate_cast<int>(data_tM[3] * dx * AB_SCALE) +
{
int v1 = saturate_cast<int>(saturate_cast<int>(data_tM[0] * dx * AB_SCALE) +
saturate_cast<int>((data_tM[1] * dy + data_tM[2]) * AB_SCALE) + round_delta),
v2 = saturate_cast<int>(saturate_cast<int>(data_tM[3] * dx * AB_SCALE) +
saturate_cast<int>((data_tM[4] * dy + data_tM[5]) * AB_SCALE) + round_delta);
v1 >>= AB_BITS - INTER_BITS;
v2 >>= AB_BITS - INTER_BITS;
yM[0] = saturate_cast<short>(v1 >> INTER_BITS);
yM[1] = saturate_cast<short>(v2 >> INTER_BITS);
if (inter != INTER_NEAREST)
mapy.ptr<short>(dy)[dx] = ((v2 & (INTER_TAB_SIZE - 1)) * INTER_TAB_SIZE + (v1 & (INTER_TAB_SIZE - 1)));
}
}
CV_Assert(mapx.type() == CV_16SC2 && ((inter == INTER_NEAREST && !mapy.data) || mapy.type() == CV_16SC1));
cv::remap(_src, _dst, mapx, mapy, inter, borderType, borderValue);
}
@ -1099,7 +1096,7 @@ protected:
private:
void warpPerspective(const Mat&, Mat&);
};
CV_WarpPerspective_Test::CV_WarpPerspective_Test() :
CV_WarpAffine_Test()
{
@ -1116,11 +1113,12 @@ void CV_WarpPerspective_Test::generate_test_data()
// generating the M 3x3 matrix
RNG& rng = ts->get_rng();
Point2f sp[] = { Point2f(0, 0), Point2f(src.cols, 0), Point2f(0, src.rows), Point2f(src.cols, src.rows) };
Point2f dp[] = { Point2f(rng.uniform(0, src.cols), rng.uniform(0, src.rows)),
Point2f(rng.uniform(0, src.cols), rng.uniform(0, src.rows)),
Point2f(rng.uniform(0, src.cols), rng.uniform(0, src.rows)),
Point2f(rng.uniform(0, src.cols), rng.uniform(0, src.rows)) };
float cols = static_cast<float>(src.cols), rows = static_cast<float>(src.rows);
Point2f sp[] = { Point2f(0.0f, 0.0f), Point2f(cols, 0.0f), Point2f(0.0f, rows), Point2f(cols, rows) };
Point2f dp[] = { Point2f(rng.uniform(0.0f, cols), rng.uniform(0.0f, rows)),
Point2f(rng.uniform(0.0f, cols), rng.uniform(0.0f, rows)),
Point2f(rng.uniform(0.0f, cols), rng.uniform(0.0f, rows)),
Point2f(rng.uniform(0.0f, cols), rng.uniform(0.0f, rows)) };
M = getPerspectiveTransform(sp, dp);
static const int depths[] = { CV_32F, CV_64F };
@ -1148,24 +1146,24 @@ void CV_WarpPerspective_Test::warpPerspective(const Mat& _src, Mat& _dst)
CV_Assert(dsize.area() > 0);
CV_Assert(_src.type() == _dst.type());
if (M.depth() != CV_64F)
{
Mat tmp;
M.convertTo(tmp, CV_64F);
M = tmp;
}
if (M.depth() != CV_64F)
{
Mat tmp;
M.convertTo(tmp, CV_64F);
M = tmp;
}
if (!(interpolation & CV_WARP_INVERSE_MAP))
{
Mat tmp;
invert(M, tmp);
M = tmp;
}
int inter = interpolation & INTER_MAX;
if (inter == INTER_AREA)
inter = INTER_LINEAR;
mapx.create(dsize, CV_16SC2);
if (inter != INTER_NEAREST)
mapy.create(dsize, CV_16SC1);
@ -1176,30 +1174,30 @@ void CV_WarpPerspective_Test::warpPerspective(const Mat& _src, Mat& _dst)
for (int dy = 0; dy < dsize.height; ++dy)
{
short* yMx = mapx.ptr<short>(dy);
for (int dx = 0; dx < dsize.width; ++dx, yMx += 2)
{
double den = tM[6] * dx + tM[7] * dy + tM[8];
den = den ? 1.0 / den : 0.0;
if (inter == INTER_NEAREST)
{
yMx[0] = saturate_cast<short>((tM[0] * dx + tM[1] * dy + tM[2]) * den);
yMx[1] = saturate_cast<short>((tM[3] * dx + tM[4] * dy + tM[5]) * den);
continue;
}
den *= INTER_TAB_SIZE;
int v0 = saturate_cast<int>((tM[0] * dx + tM[1] * dy + tM[2]) * den);
int v1 = saturate_cast<int>((tM[3] * dx + tM[4] * dy + tM[5]) * den);
yMx[0] = saturate_cast<short>(v0 >> INTER_BITS);
yMx[1] = saturate_cast<short>(v1 >> INTER_BITS);
mapy.ptr<short>(dy)[dx] = saturate_cast<short>((v1 & (INTER_TAB_SIZE - 1)) *
mapy.ptr<short>(dy)[dx] = saturate_cast<short>((v1 & (INTER_TAB_SIZE - 1)) *
INTER_TAB_SIZE + (v0 & (INTER_TAB_SIZE - 1)));
}
}
CV_Assert(mapx.type() == CV_16SC2 && ((inter == INTER_NEAREST && !mapy.data) || mapy.type() == CV_16SC1));
cv::remap(_src, _dst, mapx, mapy, inter, borderType, borderValue);
}

Loading…
Cancel
Save