fix cv::gpu::resize for INTER_LINEAR, now it produces the same result as CPU version

This commit is contained in:
Vladislav Vinogradov
2014-08-01 11:33:29 +04:00
parent bab826a381
commit da9be8231f
2 changed files with 62 additions and 16 deletions

View File

@@ -73,6 +73,28 @@ namespace
}
}
template <typename T, template <typename> class Interpolator>
void resizeLinearImpl(const cv::Mat& src, cv::Mat& dst, double fx, double fy)
{
const int cn = src.channels();
cv::Size dsize(cv::saturate_cast<int>(src.cols * fx), cv::saturate_cast<int>(src.rows * fy));
dst.create(dsize, src.type());
float ifx = static_cast<float>(1.0 / fx);
float ify = static_cast<float>(1.0 / fy);
for (int y = 0; y < dsize.height; ++y)
{
for (int x = 0; x < dsize.width; ++x)
{
for (int c = 0; c < cn; ++c)
dst.at<T>(y, x * cn + c) = Interpolator<T>::getValue(src, (y + 0.5f) * ify - 0.5f, (x + 0.5f) * ifx - 0.5f, c, cv::BORDER_REPLICATE);
}
}
}
void resizeGold(const cv::Mat& src, cv::Mat& dst, double fx, double fy, int interpolation)
{
typedef void (*func_t)(const cv::Mat& src, cv::Mat& dst, double fx, double fy);
@@ -90,12 +112,12 @@ namespace
static const func_t linear_funcs[] =
{
resizeImpl<unsigned char, LinearInterpolator>,
resizeImpl<signed char, LinearInterpolator>,
resizeImpl<unsigned short, LinearInterpolator>,
resizeImpl<short, LinearInterpolator>,
resizeImpl<int, LinearInterpolator>,
resizeImpl<float, LinearInterpolator>
resizeLinearImpl<unsigned char, LinearInterpolator>,
resizeLinearImpl<signed char, LinearInterpolator>,
resizeLinearImpl<unsigned short, LinearInterpolator>,
resizeLinearImpl<short, LinearInterpolator>,
resizeLinearImpl<int, LinearInterpolator>,
resizeLinearImpl<float, LinearInterpolator>
};
static const func_t cubic_funcs[] =
@@ -203,7 +225,15 @@ INSTANTIATE_TEST_CASE_P(GPU_ImgProc, ResizeSameAsHost, testing::Combine(
DIFFERENT_SIZES,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), 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_NEAREST), Interpolation(cv::INTER_AREA)),
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_AREA)),
WHOLE_SUBMAT));
INSTANTIATE_TEST_CASE_P(GPU_ImgProc2, ResizeSameAsHost, testing::Combine(
ALL_DEVICES,
DIFFERENT_SIZES,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
testing::Values(0.3, 0.5, 1.5, 2.0),
testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR)),
WHOLE_SUBMAT));
#endif // HAVE_CUDA