From: Vladislav Vinogradov Date: Wed, 24 Dec 2014 10:33:17 +0000 (+0300) Subject: add auxiliary functions to work with Input/Output arrays: X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~2738^2~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=00e7816c1bf177887e4645ee2afa811bc72a395a;p=platform%2Fupstream%2Fopencv.git add auxiliary functions to work with Input/Output arrays: they allow to perform asynchronous upload/download into temporary buffer to get valid GpuMat object --- diff --git a/modules/core/include/opencv2/core/private.cuda.hpp b/modules/core/include/opencv2/core/private.cuda.hpp index a97388b..aaa777c 100644 --- a/modules/core/include/opencv2/core/private.cuda.hpp +++ b/modules/core/include/opencv2/core/private.cuda.hpp @@ -106,6 +106,16 @@ namespace cv { namespace cuda GpuMat::Allocator* allocator_; }; + CV_EXPORTS GpuMat getInputMat(InputArray _src, Stream& stream); + + CV_EXPORTS GpuMat getOutputMat(OutputArray _dst, int rows, int cols, int type, Stream& stream); + static inline GpuMat getOutputMat(OutputArray _dst, Size size, int type, Stream& stream) + { + return getOutputMat(_dst, size.height, size.width, type, stream); + } + + CV_EXPORTS void syncOutput(const GpuMat& dst, OutputArray _dst, Stream& stream); + static inline void checkNppError(int code, const char* file, const int line, const char* func) { if (code < 0) diff --git a/modules/core/src/cuda_gpu_mat.cpp b/modules/core/src/cuda_gpu_mat.cpp index 4440d58..8a7b236 100644 --- a/modules/core/src/cuda_gpu_mat.cpp +++ b/modules/core/src/cuda_gpu_mat.cpp @@ -342,6 +342,53 @@ void cv::cuda::ensureSizeIsEnough(int rows, int cols, int type, OutputArray arr) } } +GpuMat cv::cuda::getInputMat(InputArray _src, Stream& stream) +{ + GpuMat src; + + if (_src.kind() == _InputArray::CUDA_GPU_MAT) + { + src = _src.getGpuMat(); + } + else if (!_src.empty()) + { + BufferPool pool(stream); + src = pool.getBuffer(_src.size(), _src.type()); + src.upload(_src, stream); + } + + return src; +} + +GpuMat cv::cuda::getOutputMat(OutputArray _dst, int rows, int cols, int type, Stream& stream) +{ + GpuMat dst; + + if (_dst.kind() == _InputArray::CUDA_GPU_MAT) + { + _dst.create(rows, cols, type); + dst = _dst.getGpuMat(); + } + else + { + BufferPool pool(stream); + dst = pool.getBuffer(rows, cols, type); + } + + return dst; +} + +void cv::cuda::syncOutput(const GpuMat& dst, OutputArray _dst, Stream& stream) +{ + if (_dst.kind() != _InputArray::CUDA_GPU_MAT) + { + if (stream) + dst.download(_dst, stream); + else + dst.download(_dst); + } +} + #ifndef HAVE_CUDA GpuMat::Allocator* cv::cuda::GpuMat::defaultAllocator()