From f2aa6ebe158ed59407e166586cec239286abe881 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Thu, 25 Apr 2013 15:10:13 +0400 Subject: [PATCH] switched to Input/Output Array in shift operations --- .../gpuarithm/include/opencv2/gpuarithm.hpp | 16 +++++----- modules/gpuarithm/src/element_operations.cpp | 30 +++++++++++-------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/modules/gpuarithm/include/opencv2/gpuarithm.hpp b/modules/gpuarithm/include/opencv2/gpuarithm.hpp index 807285e983..943b3a1d8a 100644 --- a/modules/gpuarithm/include/opencv2/gpuarithm.hpp +++ b/modules/gpuarithm/include/opencv2/gpuarithm.hpp @@ -107,6 +107,14 @@ CV_EXPORTS void bitwise_and(InputArray src1, InputArray src2, OutputArray dst, I //! calculates per-element bit-wise "exclusive or" operation CV_EXPORTS void bitwise_xor(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null()); +//! pixel by pixel right shift of an image by a constant value +//! supports 1, 3 and 4 channels images with integers elements +CV_EXPORTS void rshift(InputArray src, Scalar_ val, OutputArray dst, Stream& stream = Stream::Null()); + +//! pixel by pixel left shift of an image by a constant value +//! supports 1, 3 and 4 channels images with CV_8U, CV_16U or CV_32S depth +CV_EXPORTS void lshift(InputArray src, Scalar_ val, OutputArray dst, Stream& stream = Stream::Null()); + //! computes the weighted sum of two arrays (dst = alpha*src1 + beta*src2 + gamma) CV_EXPORTS void addWeighted(const GpuMat& src1, double alpha, const GpuMat& src2, double beta, double gamma, GpuMat& dst, int dtype = -1, Stream& stream = Stream::Null()); @@ -117,14 +125,6 @@ static inline void scaleAdd(const GpuMat& src1, double alpha, const GpuMat& src2 addWeighted(src1, alpha, src2, 1.0, 0.0, dst, -1, stream); } -//! pixel by pixel right shift of an image by a constant value -//! supports 1, 3 and 4 channels images with integers elements -CV_EXPORTS void rshift(const GpuMat& src, Scalar_ sc, GpuMat& dst, Stream& stream = Stream::Null()); - -//! pixel by pixel left shift of an image by a constant value -//! supports 1, 3 and 4 channels images with CV_8U, CV_16U or CV_32S depth -CV_EXPORTS void lshift(const GpuMat& src, Scalar_ sc, GpuMat& dst, Stream& stream = Stream::Null()); - //! computes per-element minimum of two arrays (dst = min(src1, src2)) CV_EXPORTS void min(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream = Stream::Null()); diff --git a/modules/gpuarithm/src/element_operations.cpp b/modules/gpuarithm/src/element_operations.cpp index 61c4338528..5a0f206aed 100644 --- a/modules/gpuarithm/src/element_operations.cpp +++ b/modules/gpuarithm/src/element_operations.cpp @@ -79,9 +79,9 @@ void cv::gpu::bitwise_and(InputArray, InputArray, OutputArray, InputArray, Strea void cv::gpu::bitwise_xor(InputArray, InputArray, OutputArray, InputArray, Stream&) { throw_no_cuda(); } -void cv::gpu::rshift(const GpuMat&, Scalar_, GpuMat&, Stream&) { throw_no_cuda(); } +void cv::gpu::rshift(InputArray, Scalar_, OutputArray, Stream&) { throw_no_cuda(); } -void cv::gpu::lshift(const GpuMat&, Scalar_, GpuMat&, Stream&) { throw_no_cuda(); } +void cv::gpu::lshift(InputArray, Scalar_, OutputArray, Stream&) { throw_no_cuda(); } void cv::gpu::min(const GpuMat&, const GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); } void cv::gpu::min(const GpuMat&, double, GpuMat&, Stream&) { throw_no_cuda(); } @@ -2213,7 +2213,7 @@ namespace }; } -void cv::gpu::rshift(const GpuMat& src, Scalar_ sc, GpuMat& dst, Stream& stream) +void cv::gpu::rshift(InputArray _src, Scalar_ val, OutputArray _dst, Stream& stream) { typedef void (*func_t)(const GpuMat& src, Scalar_ sc, GpuMat& dst, cudaStream_t stream); static const func_t funcs[5][4] = @@ -2225,15 +2225,18 @@ void cv::gpu::rshift(const GpuMat& src, Scalar_ sc, GpuMat& dst, Stream& st {NppShift::call, 0, NppShift::call, NppShift::call}, }; - CV_Assert(src.depth() < CV_32F); - CV_Assert(src.channels() == 1 || src.channels() == 3 || src.channels() == 4); + GpuMat src = _src.getGpuMat(); - dst.create(src.size(), src.type()); + CV_Assert( src.depth() < CV_32F ); + CV_Assert( src.channels() == 1 || src.channels() == 3 || src.channels() == 4 ); + + _dst.create(src.size(), src.type()); + GpuMat dst = _dst.getGpuMat(); - funcs[src.depth()][src.channels() - 1](src, sc, dst, StreamAccessor::getStream(stream)); + funcs[src.depth()][src.channels() - 1](src, val, dst, StreamAccessor::getStream(stream)); } -void cv::gpu::lshift(const GpuMat& src, Scalar_ sc, GpuMat& dst, Stream& stream) +void cv::gpu::lshift(InputArray _src, Scalar_ val, OutputArray _dst, Stream& stream) { typedef void (*func_t)(const GpuMat& src, Scalar_ sc, GpuMat& dst, cudaStream_t stream); static const func_t funcs[5][4] = @@ -2245,12 +2248,15 @@ void cv::gpu::lshift(const GpuMat& src, Scalar_ sc, GpuMat& dst, Stream& st {NppShift::call, 0, NppShift::call, NppShift::call}, }; - CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32S); - CV_Assert(src.channels() == 1 || src.channels() == 3 || src.channels() == 4); + GpuMat src = _src.getGpuMat(); - dst.create(src.size(), src.type()); + CV_Assert( src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32S ); + CV_Assert( src.channels() == 1 || src.channels() == 3 || src.channels() == 4 ); + + _dst.create(src.size(), src.type()); + GpuMat dst = _dst.getGpuMat(); - funcs[src.depth()][src.channels() - 1](src, sc, dst, StreamAccessor::getStream(stream)); + funcs[src.depth()][src.channels() - 1](src, val, dst, StreamAccessor::getStream(stream)); } //////////////////////////////////////////////////////////////////////////////