From d352db7ec4664f14520b8781686d886ca119c640 Mon Sep 17 00:00:00 2001 From: Anatoly Baksheev Date: Fri, 23 Jul 2010 15:04:16 +0000 Subject: [PATCH] imgproc_gpu - minor refactoring --- modules/gpu/include/opencv2/gpu/gpu.hpp | 1 + modules/gpu/src/cuda/imgproc.cu | 21 +++++++++-------- modules/gpu/src/imgproc_gpu.cpp | 30 ++++++++++++------------- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/modules/gpu/include/opencv2/gpu/gpu.hpp b/modules/gpu/include/opencv2/gpu/gpu.hpp index 6fd835a4a2..c50351e841 100644 --- a/modules/gpu/include/opencv2/gpu/gpu.hpp +++ b/modules/gpu/include/opencv2/gpu/gpu.hpp @@ -64,6 +64,7 @@ namespace cv CV_EXPORTS int getNumberOfSMs(int device); //////////////////////////////// GpuMat //////////////////////////////// + class CudaStrem; //! Smart pointer for GPU memory with reference counting. Its interface is mostly similar with cv::Mat. class CV_EXPORTS GpuMat diff --git a/modules/gpu/src/cuda/imgproc.cu b/modules/gpu/src/cuda/imgproc.cu index 5093cf654f..b0960eab7a 100644 --- a/modules/gpu/src/cuda/imgproc.cu +++ b/modules/gpu/src/cuda/imgproc.cu @@ -64,22 +64,25 @@ namespace imgproc } } -namespace cv { namespace gpu { namespace impl { - extern "C" void remap_gpu(const DevMem2D& src, const DevMem2D_& xmap, const DevMem2D_& ymap, DevMem2D dst, size_t width, size_t height) +namespace cv { namespace gpu { namespace impl +{ + using namespace imgproc; + + extern "C" void remap_gpu(const DevMem2D& src, const DevMem2D_& xmap, const DevMem2D_& ymap, DevMem2D dst) { dim3 block(16, 16, 1); dim3 grid(1, 1, 1); - grid.x = divUp( width, block.x); - grid.y = divUp(height, block.y); + grid.x = divUp(dst.cols, block.x); + grid.y = divUp(dst.rows, block.y); - ::imgproc::tex.filterMode = cudaFilterModeLinear; - ::imgproc::tex.addressMode[0] = ::imgproc::tex.addressMode[1] = cudaAddressModeWrap; + tex.filterMode = cudaFilterModeLinear; + tex.addressMode[0] = tex.addressMode[1] = cudaAddressModeWrap; cudaChannelFormatDesc desc = cudaCreateChannelDesc(); - cudaSafeCall( cudaBindTexture2D(0, ::imgproc::tex, src.ptr, desc, width, height, src.step) ); + cudaSafeCall( cudaBindTexture2D(0, tex, src.ptr, desc, dst.cols, dst.rows, src.step) ); - ::imgproc::kernel_remap<<>>(xmap.ptr, ymap.ptr, xmap.step, dst.ptr, dst.step, width, height); + kernel_remap<<>>(xmap.ptr, ymap.ptr, xmap.step, dst.ptr, dst.step, dst.cols, dst.rows); cudaSafeCall( cudaThreadSynchronize() ); - cudaSafeCall( cudaUnbindTexture(::imgproc::tex) ); + cudaSafeCall( cudaUnbindTexture(tex) ); } }}} \ No newline at end of file diff --git a/modules/gpu/src/imgproc_gpu.cpp b/modules/gpu/src/imgproc_gpu.cpp index 7874e0bb47..57dcfc4fa4 100644 --- a/modules/gpu/src/imgproc_gpu.cpp +++ b/modules/gpu/src/imgproc_gpu.cpp @@ -47,29 +47,27 @@ using namespace cv::gpu; #if !defined (HAVE_CUDA) -namespace cv -{ - namespace gpu - { - remap(const GpuMat& /*src*/, const GpuMat& /*xmap*/, const GpuMat& /*ymap*/, GpuMat& /*dst*/) { throw_nogpu(); } - } - -} +cv::gpu::remap(const GpuMat& /*src*/, const GpuMat& /*xmap*/, const GpuMat& /*ymap*/, GpuMat& /*dst*/) { throw_nogpu(); } #else /* !defined (HAVE_CUDA) */ -namespace cv { namespace gpu { namespace impl { - extern "C" void remap_gpu(const DevMem2D& src, const DevMem2D_& xmap, const DevMem2D_& ymap, DevMem2D dst, size_t width, size_t height); -}}} - +namespace cv { namespace gpu +{ + namespace impl + { + extern "C" void remap_gpu(const DevMem2D& src, const DevMem2D_& xmap, const DevMem2D_& ymap, DevMem2D dst); + } +}} void cv::gpu::remap(const GpuMat& src, const GpuMat& xmap, const GpuMat& ymap, GpuMat& dst) { - CV_Assert((!xmap.data || xmap.size() == ymap.size())); - dst.create(xmap.size(), src.type()); - CV_Assert(dst.data != src.data ); + CV_DbgAssert(xmap.data && xmap.cols == ymap.cols && xmap.rows == ymap.rows); + CV_Assert(xmap.type() == CV_32F && ymap.type() == CV_32F); - impl::remap_gpu(src, xmap, ymap, dst, dst.cols, dst.rows); + dst.create(xmap.size(), src.type()); + CV_Assert(dst.data != src.data); + + impl::remap_gpu(src, xmap, ymap, dst); } #endif /* !defined (HAVE_CUDA) */ \ No newline at end of file