From 2311b0b43b5b0b25e5f0d4e2cb448c4b43ad9e72 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 19 Jul 2013 16:37:10 +0400 Subject: [PATCH] added cudev::GpuMat_ support to Input/Output arrays --- modules/core/include/opencv2/core/base.hpp | 5 ++ modules/core/include/opencv2/core/mat.hpp | 3 ++ .../opencv2/cudev/ptr2d/detail/gpumat.hpp | 23 ++++++++++ modules/gpufilters/src/filtering.cpp | 12 ++--- modules/gpuimgproc/src/color.cpp | 46 +++++++++---------- modules/gpuwarping/src/pyramids.cpp | 4 +- 6 files changed, 62 insertions(+), 31 deletions(-) diff --git a/modules/core/include/opencv2/core/base.hpp b/modules/core/include/opencv2/core/base.hpp index 637ecdf513..9644f98016 100644 --- a/modules/core/include/opencv2/core/base.hpp +++ b/modules/core/include/opencv2/core/base.hpp @@ -498,6 +498,11 @@ namespace gpu class CV_EXPORTS Event; } +namespace cudev +{ + template class GpuMat_; +} + } // cv #endif //__OPENCV_CORE_BASE_HPP__ diff --git a/modules/core/include/opencv2/core/mat.hpp b/modules/core/include/opencv2/core/mat.hpp index d5826a9b61..b69946939c 100644 --- a/modules/core/include/opencv2/core/mat.hpp +++ b/modules/core/include/opencv2/core/mat.hpp @@ -96,6 +96,7 @@ public: _InputArray(const gpu::GpuMat& d_mat); _InputArray(const ogl::Buffer& buf); _InputArray(const gpu::CudaMem& cuda_mem); + template _InputArray(const cudev::GpuMat_<_Tp>& m); virtual Mat getMat(int i=-1) const; virtual void getMatVector(std::vector& mv) const; @@ -144,6 +145,7 @@ public: _OutputArray(gpu::GpuMat& d_mat); _OutputArray(ogl::Buffer& buf); _OutputArray(gpu::CudaMem& cuda_mem); + template _OutputArray(cudev::GpuMat_<_Tp>& m); template _OutputArray(std::vector<_Tp>& vec); template _OutputArray(std::vector >& vec); template _OutputArray(std::vector >& vec); @@ -156,6 +158,7 @@ public: _OutputArray(const gpu::GpuMat& d_mat); _OutputArray(const ogl::Buffer& buf); _OutputArray(const gpu::CudaMem& cuda_mem); + template _OutputArray(const cudev::GpuMat_<_Tp>& m); template _OutputArray(const std::vector<_Tp>& vec); template _OutputArray(const std::vector >& vec); template _OutputArray(const std::vector >& vec); diff --git a/modules/cudev/include/opencv2/cudev/ptr2d/detail/gpumat.hpp b/modules/cudev/include/opencv2/cudev/ptr2d/detail/gpumat.hpp index 2c7cf7e146..e378c52372 100644 --- a/modules/cudev/include/opencv2/cudev/ptr2d/detail/gpumat.hpp +++ b/modules/cudev/include/opencv2/cudev/ptr2d/detail/gpumat.hpp @@ -335,4 +335,27 @@ __host__ GpuMat_& GpuMat_::assign(const Expr& expr, Stream& stream) }} +// Input / Output Arrays + +namespace cv { + +template +__host__ _InputArray::_InputArray(const cudev::GpuMat_<_Tp>& m) + : flags(FIXED_TYPE + GPU_MAT + DataType<_Tp>::type), obj((void*)&m) +{} + +template +__host__ _OutputArray::_OutputArray(cudev::GpuMat_<_Tp>& m) + : _InputArray(m) +{} + +template +__host__ _OutputArray::_OutputArray(const cudev::GpuMat_<_Tp>& m) + : _InputArray(m) +{ + flags |= FIXED_SIZE; +} + +} + #endif diff --git a/modules/gpufilters/src/filtering.cpp b/modules/gpufilters/src/filtering.cpp index 5a852c9234..14917acc33 100644 --- a/modules/gpufilters/src/filtering.cpp +++ b/modules/gpufilters/src/filtering.cpp @@ -230,22 +230,22 @@ namespace switch (srcType) { case CV_8UC1: - func_ = cudev::filter2D; + func_ = cv::gpu::cudev::filter2D; break; case CV_8UC4: - func_ = cudev::filter2D; + func_ = cv::gpu::cudev::filter2D; break; case CV_16UC1: - func_ = cudev::filter2D; + func_ = cv::gpu::cudev::filter2D; break; case CV_16UC4: - func_ = cudev::filter2D; + func_ = cv::gpu::cudev::filter2D; break; case CV_32FC1: - func_ = cudev::filter2D; + func_ = cv::gpu::cudev::filter2D; break; case CV_32FC4: - func_ = cudev::filter2D; + func_ = cv::gpu::cudev::filter2D; break; } } diff --git a/modules/gpuimgproc/src/color.cpp b/modules/gpuimgproc/src/color.cpp index 006274742e..3d714b6287 100644 --- a/modules/gpuimgproc/src/color.cpp +++ b/modules/gpuimgproc/src/color.cpp @@ -187,7 +187,7 @@ namespace _dst.create(src.size(), CV_8UC2); GpuMat dst = _dst.getGpuMat(); - cudev::bgr_to_bgr555(src, dst, StreamAccessor::getStream(stream)); + cv::gpu::cudev::bgr_to_bgr555(src, dst, StreamAccessor::getStream(stream)); } void bgr_to_bgr565(InputArray _src, OutputArray _dst, int, Stream& stream) @@ -200,7 +200,7 @@ namespace _dst.create(src.size(), CV_8UC2); GpuMat dst = _dst.getGpuMat(); - cudev::bgr_to_bgr565(src, dst, StreamAccessor::getStream(stream)); + cv::gpu::cudev::bgr_to_bgr565(src, dst, StreamAccessor::getStream(stream)); } void rgb_to_bgr555(InputArray _src, OutputArray _dst, int, Stream& stream) @@ -213,7 +213,7 @@ namespace _dst.create(src.size(), CV_8UC2); GpuMat dst = _dst.getGpuMat(); - cudev::rgb_to_bgr555(src, dst, StreamAccessor::getStream(stream)); + cv::gpu::cudev::rgb_to_bgr555(src, dst, StreamAccessor::getStream(stream)); } void rgb_to_bgr565(InputArray _src, OutputArray _dst, int, Stream& stream) @@ -226,7 +226,7 @@ namespace _dst.create(src.size(), CV_8UC2); GpuMat dst = _dst.getGpuMat(); - cudev::rgb_to_bgr565(src, dst, StreamAccessor::getStream(stream)); + cv::gpu::cudev::rgb_to_bgr565(src, dst, StreamAccessor::getStream(stream)); } void bgra_to_bgr555(InputArray _src, OutputArray _dst, int, Stream& stream) @@ -239,7 +239,7 @@ namespace _dst.create(src.size(), CV_8UC2); GpuMat dst = _dst.getGpuMat(); - cudev::bgra_to_bgr555(src, dst, StreamAccessor::getStream(stream)); + cv::gpu::cudev::bgra_to_bgr555(src, dst, StreamAccessor::getStream(stream)); } void bgra_to_bgr565(InputArray _src, OutputArray _dst, int, Stream& stream) @@ -252,7 +252,7 @@ namespace _dst.create(src.size(), CV_8UC2); GpuMat dst = _dst.getGpuMat(); - cudev::bgra_to_bgr565(src, dst, StreamAccessor::getStream(stream)); + cv::gpu::cudev::bgra_to_bgr565(src, dst, StreamAccessor::getStream(stream)); } void rgba_to_bgr555(InputArray _src, OutputArray _dst, int, Stream& stream) @@ -265,7 +265,7 @@ namespace _dst.create(src.size(), CV_8UC2); GpuMat dst = _dst.getGpuMat(); - cudev::rgba_to_bgr555(src, dst, StreamAccessor::getStream(stream)); + cv::gpu::cudev::rgba_to_bgr555(src, dst, StreamAccessor::getStream(stream)); } void rgba_to_bgr565(InputArray _src, OutputArray _dst, int, Stream& stream) @@ -278,7 +278,7 @@ namespace _dst.create(src.size(), CV_8UC2); GpuMat dst = _dst.getGpuMat(); - cudev::rgba_to_bgr565(src, dst, StreamAccessor::getStream(stream)); + cv::gpu::cudev::rgba_to_bgr565(src, dst, StreamAccessor::getStream(stream)); } void bgr555_to_rgb(InputArray _src, OutputArray _dst, int, Stream& stream) @@ -291,7 +291,7 @@ namespace _dst.create(src.size(), CV_8UC3); GpuMat dst = _dst.getGpuMat(); - cudev::bgr555_to_rgb(src, dst, StreamAccessor::getStream(stream)); + cv::gpu::cudev::bgr555_to_rgb(src, dst, StreamAccessor::getStream(stream)); } void bgr565_to_rgb(InputArray _src, OutputArray _dst, int, Stream& stream) @@ -304,7 +304,7 @@ namespace _dst.create(src.size(), CV_8UC3); GpuMat dst = _dst.getGpuMat(); - cudev::bgr565_to_rgb(src, dst, StreamAccessor::getStream(stream)); + cv::gpu::cudev::bgr565_to_rgb(src, dst, StreamAccessor::getStream(stream)); } void bgr555_to_bgr(InputArray _src, OutputArray _dst, int, Stream& stream) @@ -317,7 +317,7 @@ namespace _dst.create(src.size(), CV_8UC3); GpuMat dst = _dst.getGpuMat(); - cudev::bgr555_to_bgr(src, dst, StreamAccessor::getStream(stream)); + cv::gpu::cudev::bgr555_to_bgr(src, dst, StreamAccessor::getStream(stream)); } void bgr565_to_bgr(InputArray _src, OutputArray _dst, int, Stream& stream) @@ -330,7 +330,7 @@ namespace _dst.create(src.size(), CV_8UC3); GpuMat dst = _dst.getGpuMat(); - cudev::bgr565_to_bgr(src, dst, StreamAccessor::getStream(stream)); + cv::gpu::cudev::bgr565_to_bgr(src, dst, StreamAccessor::getStream(stream)); } void bgr555_to_rgba(InputArray _src, OutputArray _dst, int, Stream& stream) @@ -343,7 +343,7 @@ namespace _dst.create(src.size(), CV_8UC4); GpuMat dst = _dst.getGpuMat(); - cudev::bgr555_to_rgba(src, dst, StreamAccessor::getStream(stream)); + cv::gpu::cudev::bgr555_to_rgba(src, dst, StreamAccessor::getStream(stream)); } void bgr565_to_rgba(InputArray _src, OutputArray _dst, int, Stream& stream) @@ -356,7 +356,7 @@ namespace _dst.create(src.size(), CV_8UC4); GpuMat dst = _dst.getGpuMat(); - cudev::bgr565_to_rgba(src, dst, StreamAccessor::getStream(stream)); + cv::gpu::cudev::bgr565_to_rgba(src, dst, StreamAccessor::getStream(stream)); } void bgr555_to_bgra(InputArray _src, OutputArray _dst, int, Stream& stream) @@ -369,7 +369,7 @@ namespace _dst.create(src.size(), CV_8UC4); GpuMat dst = _dst.getGpuMat(); - cudev::bgr555_to_bgra(src, dst, StreamAccessor::getStream(stream)); + cv::gpu::cudev::bgr555_to_bgra(src, dst, StreamAccessor::getStream(stream)); } void bgr565_to_bgra(InputArray _src, OutputArray _dst, int, Stream& stream) @@ -382,7 +382,7 @@ namespace _dst.create(src.size(), CV_8UC4); GpuMat dst = _dst.getGpuMat(); - cudev::bgr565_to_bgra(src, dst, StreamAccessor::getStream(stream)); + cv::gpu::cudev::bgr565_to_bgra(src, dst, StreamAccessor::getStream(stream)); } void gray_to_bgr(InputArray _src, OutputArray _dst, int, Stream& stream) @@ -427,7 +427,7 @@ namespace _dst.create(src.size(), CV_8UC2); GpuMat dst = _dst.getGpuMat(); - cudev::gray_to_bgr555(src, dst, StreamAccessor::getStream(stream)); + cv::gpu::cudev::gray_to_bgr555(src, dst, StreamAccessor::getStream(stream)); } void gray_to_bgr565(InputArray _src, OutputArray _dst, int, Stream& stream) @@ -440,7 +440,7 @@ namespace _dst.create(src.size(), CV_8UC2); GpuMat dst = _dst.getGpuMat(); - cudev::gray_to_bgr565(src, dst, StreamAccessor::getStream(stream)); + cv::gpu::cudev::gray_to_bgr565(src, dst, StreamAccessor::getStream(stream)); } void bgr555_to_gray(InputArray _src, OutputArray _dst, int, Stream& stream) @@ -453,7 +453,7 @@ namespace _dst.create(src.size(), CV_8UC1); GpuMat dst = _dst.getGpuMat(); - cudev::bgr555_to_gray(src, dst, StreamAccessor::getStream(stream)); + cv::gpu::cudev::bgr555_to_gray(src, dst, StreamAccessor::getStream(stream)); } void bgr565_to_gray(InputArray _src, OutputArray _dst, int, Stream& stream) @@ -466,7 +466,7 @@ namespace _dst.create(src.size(), CV_8UC1); GpuMat dst = _dst.getGpuMat(); - cudev::bgr565_to_gray(src, dst, StreamAccessor::getStream(stream)); + cv::gpu::cudev::bgr565_to_gray(src, dst, StreamAccessor::getStream(stream)); } void rgb_to_gray(InputArray _src, OutputArray _dst, int, Stream& stream) @@ -2145,9 +2145,9 @@ void cv::gpu::demosaicing(InputArray _src, OutputArray _dst, int code, int dcn, code == COLOR_BayerRG2BGR_MHT || code == COLOR_BayerGR2BGR_MHT ? 0 : 1); if (dcn == 3) - cudev::MHCdemosaic<3>(srcWhole, make_int2(ofs.x, ofs.y), dst, firstRed, StreamAccessor::getStream(stream)); + cv::gpu::cudev::MHCdemosaic<3>(srcWhole, make_int2(ofs.x, ofs.y), dst, firstRed, StreamAccessor::getStream(stream)); else - cudev::MHCdemosaic<4>(srcWhole, make_int2(ofs.x, ofs.y), dst, firstRed, StreamAccessor::getStream(stream)); + cv::gpu::cudev::MHCdemosaic<4>(srcWhole, make_int2(ofs.x, ofs.y), dst, firstRed, StreamAccessor::getStream(stream)); break; } @@ -2172,7 +2172,7 @@ void cv::gpu::demosaicing(InputArray _src, OutputArray _dst, int code, int dcn, const int2 firstRed = make_int2(code == COLOR_BayerRG2BGR_MHT || code == COLOR_BayerGB2BGR_MHT ? 0 : 1, code == COLOR_BayerRG2BGR_MHT || code == COLOR_BayerGR2BGR_MHT ? 0 : 1); - cudev::MHCdemosaic<1>(srcWhole, make_int2(ofs.x, ofs.y), dst, firstRed, StreamAccessor::getStream(stream)); + cv::gpu::cudev::MHCdemosaic<1>(srcWhole, make_int2(ofs.x, ofs.y), dst, firstRed, StreamAccessor::getStream(stream)); break; } diff --git a/modules/gpuwarping/src/pyramids.cpp b/modules/gpuwarping/src/pyramids.cpp index 577ed85677..0e8445df2c 100644 --- a/modules/gpuwarping/src/pyramids.cpp +++ b/modules/gpuwarping/src/pyramids.cpp @@ -181,7 +181,7 @@ namespace const GpuMat& prevLayer = i == 0 ? layer0_ : pyramid_[i - 1]; - cudev::pyramid::downsampleX2(prevLayer, pyramid_[i], img.depth(), img.channels(), StreamAccessor::getStream(stream)); + cv::gpu::cudev::pyramid::downsampleX2(prevLayer, pyramid_[i], img.depth(), img.channels(), StreamAccessor::getStream(stream)); szLastLayer = szCurLayer; } @@ -222,7 +222,7 @@ namespace lastLayer = curLayer; } - cudev::pyramid::interpolateFrom1(lastLayer, outImg, outImg.depth(), outImg.channels(), StreamAccessor::getStream(stream)); + cv::gpu::cudev::pyramid::interpolateFrom1(lastLayer, outImg, outImg.depth(), outImg.channels(), StreamAccessor::getStream(stream)); } }