From b2079d6de15982f6205546e3597653f42e2f5414 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Mon, 12 Sep 2011 10:13:14 +0000 Subject: [PATCH] implemented gpu::resize for all types --- modules/gpu/include/opencv2/gpu/gpu.hpp | 3 +- modules/gpu/perf/perf_imgproc.cpp | 6 +- modules/gpu/src/cuda/imgproc.cu | 216 ++++++++++++++++++++++++ modules/gpu/src/imgproc.cpp | 73 +++++--- modules/gpu/test/test_imgproc.cpp | 12 +- samples/gpu/performance/tests.cpp | 128 +++++++++++++- 6 files changed, 401 insertions(+), 37 deletions(-) diff --git a/modules/gpu/include/opencv2/gpu/gpu.hpp b/modules/gpu/include/opencv2/gpu/gpu.hpp index 250c630c40..3c7dcc7d71 100644 --- a/modules/gpu/include/opencv2/gpu/gpu.hpp +++ b/modules/gpu/include/opencv2/gpu/gpu.hpp @@ -633,8 +633,7 @@ namespace cv CV_EXPORTS double threshold(const GpuMat& src, GpuMat& dst, double thresh, double maxval, int type, Stream& stream = Stream::Null()); //! resizes the image - //! Supports INTER_NEAREST, INTER_LINEAR - //! supports CV_8UC1, CV_8UC4 types + //! Supports INTER_NEAREST, INTER_LINEAR, INTER_CUBIC CV_EXPORTS void resize(const GpuMat& src, GpuMat& dst, Size dsize, double fx=0, double fy=0, int interpolation = INTER_LINEAR, Stream& stream = Stream::Null()); //! warps the image using affine transformation diff --git a/modules/gpu/perf/perf_imgproc.cpp b/modules/gpu/perf/perf_imgproc.cpp index 67e7466845..f4d63d6dd6 100644 --- a/modules/gpu/perf/perf_imgproc.cpp +++ b/modules/gpu/perf/perf_imgproc.cpp @@ -245,8 +245,8 @@ PERF_TEST_P(DevInfo_Size_MatType, threshold, testing::Combine(testing::ValuesIn( PERF_TEST_P(DevInfo_Size_MatType_Interpolation_SizeCoeff, resize, testing::Combine(testing::ValuesIn(devices()), testing::Values(GPU_TYPICAL_MAT_SIZES), - testing::Values(CV_8UC1, CV_8UC4), - testing::Values((int)INTER_NEAREST, (int)INTER_LINEAR), + testing::Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_16UC1, CV_16UC3, CV_16UC4, CV_32FC1, CV_32FC3, CV_32FC4), + testing::Values((int)INTER_NEAREST, (int)INTER_LINEAR, (int)INTER_CUBIC), testing::Values(0.5, 2.0))) { DeviceInfo devInfo = std::tr1::get<0>(GetParam()); @@ -264,7 +264,7 @@ PERF_TEST_P(DevInfo_Size_MatType_Interpolation_SizeCoeff, resize, testing::Combi GpuMat src(src_host); GpuMat dst; - declare.time(0.5).iterations(100); + declare.time(1.0).iterations(100); SIMPLE_TEST_CYCLE() { diff --git a/modules/gpu/src/cuda/imgproc.cu b/modules/gpu/src/cuda/imgproc.cu index 44a54ca47e..d76f93b9a5 100644 --- a/modules/gpu/src/cuda/imgproc.cu +++ b/modules/gpu/src/cuda/imgproc.cu @@ -252,6 +252,222 @@ namespace cv { namespace gpu { namespace imgproc template void remap_gpu(const DevMem2D& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2D& dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream); template void remap_gpu(const DevMem2D& src, const DevMem2Df& xmap, const DevMem2Df& ymap, const DevMem2D& dst, int interpolation, int borderMode, const float* borderValue, cudaStream_t stream); +/////////////////////////////////// Resize /////////////////////////////////////////////// + + template __global__ void resize(const Ptr2D src, float fx, float fy, DevMem2D_ dst) + { + const int x = blockDim.x * blockIdx.x + threadIdx.x; + const int y = blockDim.y * blockIdx.y + threadIdx.y; + + if (x < dst.cols && y < dst.rows) + { + const float xcoo = x / fx; + const float ycoo = y / fy; + + dst.ptr(y)[x] = saturate_cast(src(ycoo, xcoo)); + } + } + template __global__ void resizeNN(const Ptr2D src, float fx, float fy, DevMem2D_ dst) + { + const int x = blockDim.x * blockIdx.x + threadIdx.x; + const int y = blockDim.y * blockIdx.y + threadIdx.y; + + if (x < dst.cols && y < dst.rows) + { + const float xcoo = x / fx; + const float ycoo = y / fy; + + dst.ptr(y)[x] = src(__float2int_rd(ycoo), __float2int_rd(xcoo)); + } + } + + template