Skip to content

Commit

Permalink
merged GPU resize became same as CPU implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Marina Kolpakova committed Jul 3, 2012
1 parent 13735de commit cdbda45
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion modules/gpu/src/opencv2/gpu/device/filters.hpp
Expand Up @@ -64,7 +64,7 @@ namespace cv { namespace gpu { namespace device

__device__ __forceinline__ elem_type operator ()(float y, float x) const
{
return src(__float2int_rn(y), __float2int_rn(x));
return src(__float2int_rz(y), __float2int_rz(x));
}

const Ptr2D src;
Expand Down
2 changes: 1 addition & 1 deletion modules/gpu/test/interpolation.hpp
Expand Up @@ -54,7 +54,7 @@ template <typename T> struct NearestInterpolator
{
static T getValue(const cv::Mat& src, float y, float x, int c, int border_type, cv::Scalar borderVal = cv::Scalar())
{
return readVal<T>(src, cvRound(y), cvRound(x), c, border_type, borderVal);
return readVal<T>(src, int(y), int(x), c, border_type, borderVal);
}
};

Expand Down
15 changes: 8 additions & 7 deletions modules/gpu/test/test_resize.cpp
Expand Up @@ -159,7 +159,7 @@ INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Resize, testing::Combine(


/////////////////
PARAM_TEST_CASE(ResizeArea, cv::gpu::DeviceInfo, cv::Size, MatType, double, Interpolation, UseRoi)
PARAM_TEST_CASE(ResizeSameAsHost, cv::gpu::DeviceInfo, cv::Size, MatType, double, Interpolation, UseRoi)
{
cv::gpu::DeviceInfo devInfo;
cv::Size size;
Expand All @@ -181,25 +181,26 @@ PARAM_TEST_CASE(ResizeArea, cv::gpu::DeviceInfo, cv::Size, MatType, double, Inte
}
};

TEST_P(ResizeArea, Accuracy)
// downscaling only: used for classifiers
TEST_P(ResizeSameAsHost, Accuracy)
{
cv::Mat src = randomMat(size, type);

cv::gpu::GpuMat dst = createMat(cv::Size(cv::saturate_cast<int>(src.cols * coeff), cv::saturate_cast<int>(src.rows * coeff)), type, useRoi);
cv::gpu::resize(loadMat(src, useRoi), dst, cv::Size(), coeff, coeff, interpolation);

cv::Mat dst_cpu;
cv::resize(src, dst_cpu, cv::Size(), coeff, coeff, interpolation);
cv::Mat dst_gold;
cv::resize(src, dst_gold, cv::Size(), coeff, coeff, interpolation);

EXPECT_MAT_NEAR(dst_cpu, dst, src.depth() == CV_32F ? 1e-2 : 1.0);
EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-2 : 1.0);
}

INSTANTIATE_TEST_CASE_P(GPU_ImgProc, ResizeArea, testing::Combine(
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, ResizeSameAsHost, testing::Combine(
ALL_DEVICES,
DIFFERENT_SIZES,
testing::Values(MatType(CV_8UC3), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
testing::Values(0.3, 0.5),
testing::Values(Interpolation(cv::INTER_AREA)),
testing::Values(Interpolation(cv::INTER_AREA), Interpolation(cv::INTER_NEAREST)), //, Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)
WHOLE_SUBMAT));

///////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit cdbda45

Please sign in to comment.