From 2241bfb0dfa788e0b516a7da9a1f70733f5431d3 Mon Sep 17 00:00:00 2001 From: Namgoo Lee Date: Thu, 30 Jul 2020 01:03:34 +0900 Subject: [PATCH 1/2] Use "src" not "*this" for source GpuMat --- modules/core/src/cuda/gpu_mat.cu | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/src/cuda/gpu_mat.cu b/modules/core/src/cuda/gpu_mat.cu index e1b0c1b22d..f31f78a87a 100644 --- a/modules/core/src/cuda/gpu_mat.cu +++ b/modules/core/src/cuda/gpu_mat.cu @@ -561,7 +561,7 @@ void cv::cuda::GpuMat::convertTo(OutputArray _dst, int rtype, Stream& stream) co {convertToNoScale, convertToNoScale, convertToNoScale, convertToNoScale, convertToNoScale, convertToNoScale, 0} }; - funcs[sdepth][ddepth](reshape(1), dst.reshape(1), stream); + funcs[sdepth][ddepth](src.reshape(1), dst.reshape(1), stream); } void cv::cuda::GpuMat::convertTo(OutputArray _dst, int rtype, double alpha, double beta, Stream& stream) const @@ -591,7 +591,7 @@ void cv::cuda::GpuMat::convertTo(OutputArray _dst, int rtype, double alpha, doub {convertToScale, convertToScale, convertToScale, convertToScale, convertToScale, convertToScale, convertToScale} }; - funcs[sdepth][ddepth](reshape(1), dst.reshape(1), alpha, beta, stream); + funcs[sdepth][ddepth](src.reshape(1), dst.reshape(1), alpha, beta, stream); } void cv::cuda::convertFp16(InputArray _src, OutputArray _dst, Stream& stream) From 11ac26bfb43ad6e10c2bd50bbba0489e2bc26a79 Mon Sep 17 00:00:00 2001 From: Namgoo Lee Date: Thu, 30 Jul 2020 01:24:25 +0900 Subject: [PATCH 2/2] test code --- modules/cudaarithm/test/test_gpumat.cpp | 59 +++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/modules/cudaarithm/test/test_gpumat.cpp b/modules/cudaarithm/test/test_gpumat.cpp index e2fed16ad5..b4d59b1644 100644 --- a/modules/cudaarithm/test/test_gpumat.cpp +++ b/modules/cudaarithm/test/test_gpumat.cpp @@ -320,6 +320,65 @@ CUDA_TEST_P(GpuMat_ConvertTo, WithScaling) } } +CUDA_TEST_P(GpuMat_ConvertTo, InplaceWithOutScaling) +{ + cv::Mat src = randomMat(size, depth1); + + if ((depth1 == CV_64F || depth2 == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat d_srcDst = loadMat(src); + d_srcDst.convertTo(d_srcDst, depth2); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat d_srcDst = loadMat(src, useRoi); + d_srcDst.convertTo(d_srcDst, depth2); + + cv::Mat dst_gold; + src.convertTo(dst_gold, depth2); + + EXPECT_MAT_NEAR(dst_gold, d_srcDst, depth2 < CV_32F ? 1.0 : 1e-4); + } +} + + +CUDA_TEST_P(GpuMat_ConvertTo, InplaceWithScaling) +{ + cv::Mat src = randomMat(size, depth1); + double a = randomDouble(0.0, 1.0); + double b = randomDouble(-10.0, 10.0); + + if ((depth1 == CV_64F || depth2 == CV_64F) && !supportFeature(devInfo, cv::cuda::NATIVE_DOUBLE)) + { + try + { + cv::cuda::GpuMat d_srcDst = loadMat(src); + d_srcDst.convertTo(d_srcDst, depth2, a, b); + } + catch (const cv::Exception& e) + { + ASSERT_EQ(cv::Error::StsUnsupportedFormat, e.code); + } + } + else + { + cv::cuda::GpuMat d_srcDst = loadMat(src, useRoi); + d_srcDst.convertTo(d_srcDst, depth2, a, b); + + cv::Mat dst_gold; + src.convertTo(dst_gold, depth2, a, b); + + EXPECT_MAT_NEAR(dst_gold, d_srcDst, depth2 < CV_32F ? 1.0 : 1e-4); + } +} + INSTANTIATE_TEST_CASE_P(CUDA, GpuMat_ConvertTo, testing::Combine( ALL_DEVICES, DIFFERENT_SIZES,