Skip to content

Commit cdbda45

Browse files
author
Marina Kolpakova
committed
merged GPU resize became same as CPU implementation
1 parent 13735de commit cdbda45

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

modules/gpu/src/opencv2/gpu/device/filters.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ namespace cv { namespace gpu { namespace device
6464

6565
__device__ __forceinline__ elem_type operator ()(float y, float x) const
6666
{
67-
return src(__float2int_rn(y), __float2int_rn(x));
67+
return src(__float2int_rz(y), __float2int_rz(x));
6868
}
6969

7070
const Ptr2D src;

modules/gpu/test/interpolation.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ template <typename T> struct NearestInterpolator
5454
{
5555
static T getValue(const cv::Mat& src, float y, float x, int c, int border_type, cv::Scalar borderVal = cv::Scalar())
5656
{
57-
return readVal<T>(src, cvRound(y), cvRound(x), c, border_type, borderVal);
57+
return readVal<T>(src, int(y), int(x), c, border_type, borderVal);
5858
}
5959
};
6060

modules/gpu/test/test_resize.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Resize, testing::Combine(
159159

160160

161161
/////////////////
162-
PARAM_TEST_CASE(ResizeArea, cv::gpu::DeviceInfo, cv::Size, MatType, double, Interpolation, UseRoi)
162+
PARAM_TEST_CASE(ResizeSameAsHost, cv::gpu::DeviceInfo, cv::Size, MatType, double, Interpolation, UseRoi)
163163
{
164164
cv::gpu::DeviceInfo devInfo;
165165
cv::Size size;
@@ -181,25 +181,26 @@ PARAM_TEST_CASE(ResizeArea, cv::gpu::DeviceInfo, cv::Size, MatType, double, Inte
181181
}
182182
};
183183

184-
TEST_P(ResizeArea, Accuracy)
184+
// downscaling only: used for classifiers
185+
TEST_P(ResizeSameAsHost, Accuracy)
185186
{
186187
cv::Mat src = randomMat(size, type);
187188

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

191-
cv::Mat dst_cpu;
192-
cv::resize(src, dst_cpu, cv::Size(), coeff, coeff, interpolation);
192+
cv::Mat dst_gold;
193+
cv::resize(src, dst_gold, cv::Size(), coeff, coeff, interpolation);
193194

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

197-
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, ResizeArea, testing::Combine(
198+
INSTANTIATE_TEST_CASE_P(GPU_ImgProc, ResizeSameAsHost, testing::Combine(
198199
ALL_DEVICES,
199200
DIFFERENT_SIZES,
200201
testing::Values(MatType(CV_8UC3), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
201202
testing::Values(0.3, 0.5),
202-
testing::Values(Interpolation(cv::INTER_AREA)),
203+
testing::Values(Interpolation(cv::INTER_AREA), Interpolation(cv::INTER_NEAREST)), //, Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)
203204
WHOLE_SUBMAT));
204205

205206
///////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)