Skip to content

Commit 58c4d0e

Browse files
author
Vladislav Vinogradov
committed
switched to Input/Output Array in cart<->polar operations
1 parent 0a83817 commit 58c4d0e

File tree

2 files changed

+93
-61
lines changed

2 files changed

+93
-61
lines changed

modules/gpuarithm/include/opencv2/gpuarithm.hpp

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,34 @@ static inline void scaleAdd(InputArray src1, double alpha, InputArray src2, Outp
134134
//! applies fixed threshold to the image
135135
CV_EXPORTS double threshold(InputArray src, OutputArray dst, double thresh, double maxval, int type, Stream& stream = Stream::Null());
136136

137+
//! computes magnitude of complex (x(i).re, x(i).im) vector
138+
//! supports only CV_32FC2 type
139+
CV_EXPORTS void magnitude(InputArray xy, OutputArray magnitude, Stream& stream = Stream::Null());
140+
141+
//! computes squared magnitude of complex (x(i).re, x(i).im) vector
142+
//! supports only CV_32FC2 type
143+
CV_EXPORTS void magnitudeSqr(InputArray xy, OutputArray magnitude, Stream& stream = Stream::Null());
144+
145+
//! computes magnitude of each (x(i), y(i)) vector
146+
//! supports only floating-point source
147+
CV_EXPORTS void magnitude(InputArray x, InputArray y, OutputArray magnitude, Stream& stream = Stream::Null());
148+
149+
//! computes squared magnitude of each (x(i), y(i)) vector
150+
//! supports only floating-point source
151+
CV_EXPORTS void magnitudeSqr(InputArray x, InputArray y, OutputArray magnitude, Stream& stream = Stream::Null());
152+
153+
//! computes angle of each (x(i), y(i)) vector
154+
//! supports only floating-point source
155+
CV_EXPORTS void phase(InputArray x, InputArray y, OutputArray angle, bool angleInDegrees = false, Stream& stream = Stream::Null());
156+
157+
//! converts Cartesian coordinates to polar
158+
//! supports only floating-point source
159+
CV_EXPORTS void cartToPolar(InputArray x, InputArray y, OutputArray magnitude, OutputArray angle, bool angleInDegrees = false, Stream& stream = Stream::Null());
160+
161+
//! converts polar coordinates to Cartesian
162+
//! supports only floating-point source
163+
CV_EXPORTS void polarToCart(InputArray magnitude, InputArray angle, OutputArray x, OutputArray y, bool angleInDegrees = false, Stream& stream = Stream::Null());
164+
137165
//! implements generalized matrix product algorithm GEMM from BLAS
138166
CV_EXPORTS void gemm(const GpuMat& src1, const GpuMat& src2, double alpha,
139167
const GpuMat& src3, double beta, GpuMat& dst, int flags = 0, Stream& stream = Stream::Null());
@@ -163,34 +191,6 @@ CV_EXPORTS void split(const GpuMat& src, GpuMat* dst, Stream& stream = Stream::N
163191
//! copies each plane of a multi-channel array to a dedicated array
164192
CV_EXPORTS void split(const GpuMat& src, std::vector<GpuMat>& dst, Stream& stream = Stream::Null());
165193

166-
//! computes magnitude of complex (x(i).re, x(i).im) vector
167-
//! supports only CV_32FC2 type
168-
CV_EXPORTS void magnitude(const GpuMat& xy, GpuMat& magnitude, Stream& stream = Stream::Null());
169-
170-
//! computes squared magnitude of complex (x(i).re, x(i).im) vector
171-
//! supports only CV_32FC2 type
172-
CV_EXPORTS void magnitudeSqr(const GpuMat& xy, GpuMat& magnitude, Stream& stream = Stream::Null());
173-
174-
//! computes magnitude of each (x(i), y(i)) vector
175-
//! supports only floating-point source
176-
CV_EXPORTS void magnitude(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, Stream& stream = Stream::Null());
177-
178-
//! computes squared magnitude of each (x(i), y(i)) vector
179-
//! supports only floating-point source
180-
CV_EXPORTS void magnitudeSqr(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, Stream& stream = Stream::Null());
181-
182-
//! computes angle (angle(i)) of each (x(i), y(i)) vector
183-
//! supports only floating-point source
184-
CV_EXPORTS void phase(const GpuMat& x, const GpuMat& y, GpuMat& angle, bool angleInDegrees = false, Stream& stream = Stream::Null());
185-
186-
//! converts Cartesian coordinates to polar
187-
//! supports only floating-point source
188-
CV_EXPORTS void cartToPolar(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, GpuMat& angle, bool angleInDegrees = false, Stream& stream = Stream::Null());
189-
190-
//! converts polar coordinates to Cartesian
191-
//! supports only floating-point source
192-
CV_EXPORTS void polarToCart(const GpuMat& magnitude, const GpuMat& angle, GpuMat& x, GpuMat& y, bool angleInDegrees = false, Stream& stream = Stream::Null());
193-
194194
//! scales and shifts array elements so that either the specified norm (alpha) or the minimum (alpha) and maximum (beta) array values get the specified values
195195
CV_EXPORTS void normalize(const GpuMat& src, GpuMat& dst, double alpha = 1, double beta = 0,
196196
int norm_type = NORM_L2, int dtype = -1, const GpuMat& mask = GpuMat());

modules/gpuarithm/src/element_operations.cpp

Lines changed: 65 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,13 @@ void cv::gpu::addWeighted(InputArray, double, InputArray, double, double, Output
7777

7878
double cv::gpu::threshold(InputArray, OutputArray, double, double, int, Stream&) {throw_no_cuda(); return 0.0;}
7979

80-
void cv::gpu::magnitude(const GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); }
81-
void cv::gpu::magnitude(const GpuMat&, const GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); }
82-
83-
void cv::gpu::magnitudeSqr(const GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); }
84-
void cv::gpu::magnitudeSqr(const GpuMat&, const GpuMat&, GpuMat&, Stream&) { throw_no_cuda(); }
85-
86-
void cv::gpu::phase(const GpuMat&, const GpuMat&, GpuMat&, bool, Stream&) { throw_no_cuda(); }
87-
88-
void cv::gpu::cartToPolar(const GpuMat&, const GpuMat&, GpuMat&, GpuMat&, bool, Stream&) { throw_no_cuda(); }
89-
90-
void cv::gpu::polarToCart(const GpuMat&, const GpuMat&, GpuMat&, GpuMat&, bool, Stream&) { throw_no_cuda(); }
80+
void cv::gpu::magnitude(InputArray, OutputArray, Stream&) { throw_no_cuda(); }
81+
void cv::gpu::magnitude(InputArray, InputArray, OutputArray, Stream&) { throw_no_cuda(); }
82+
void cv::gpu::magnitudeSqr(InputArray, OutputArray, Stream&) { throw_no_cuda(); }
83+
void cv::gpu::magnitudeSqr(InputArray, InputArray, OutputArray, Stream&) { throw_no_cuda(); }
84+
void cv::gpu::phase(InputArray, InputArray, OutputArray, bool, Stream&) { throw_no_cuda(); }
85+
void cv::gpu::cartToPolar(InputArray, InputArray, OutputArray, OutputArray, bool, Stream&) { throw_no_cuda(); }
86+
void cv::gpu::polarToCart(InputArray, InputArray, OutputArray, OutputArray, bool, Stream&) { throw_no_cuda(); }
9187

9288
#else
9389

@@ -3005,12 +3001,10 @@ namespace
30053001
{
30063002
typedef NppStatus (*nppMagnitude_t)(const Npp32fc* pSrc, int nSrcStep, Npp32f* pDst, int nDstStep, NppiSize oSizeROI);
30073003

3008-
inline void npp_magnitude(const GpuMat& src, GpuMat& dst, nppMagnitude_t func, cudaStream_t stream)
3004+
void npp_magnitude(const GpuMat& src, GpuMat& dst, nppMagnitude_t func, cudaStream_t stream)
30093005
{
30103006
CV_Assert(src.type() == CV_32FC2);
30113007

3012-
dst.create(src.size(), CV_32FC1);
3013-
30143008
NppiSize sz;
30153009
sz.width = src.cols;
30163010
sz.height = src.rows;
@@ -3024,13 +3018,23 @@ namespace
30243018
}
30253019
}
30263020

3027-
void cv::gpu::magnitude(const GpuMat& src, GpuMat& dst, Stream& stream)
3021+
void cv::gpu::magnitude(InputArray _src, OutputArray _dst, Stream& stream)
30283022
{
3023+
GpuMat src = _src.getGpuMat();
3024+
3025+
_dst.create(src.size(), CV_32FC1);
3026+
GpuMat dst = _dst.getGpuMat();
3027+
30293028
npp_magnitude(src, dst, nppiMagnitude_32fc32f_C1R, StreamAccessor::getStream(stream));
30303029
}
30313030

3032-
void cv::gpu::magnitudeSqr(const GpuMat& src, GpuMat& dst, Stream& stream)
3031+
void cv::gpu::magnitudeSqr(InputArray _src, OutputArray _dst, Stream& stream)
30333032
{
3033+
GpuMat src = _src.getGpuMat();
3034+
3035+
_dst.create(src.size(), CV_32FC1);
3036+
GpuMat dst = _dst.getGpuMat();
3037+
30343038
npp_magnitude(src, dst, nppiMagnitudeSqr_32fc32f_C1R, StreamAccessor::getStream(stream));
30353039
}
30363040

@@ -3048,18 +3052,13 @@ namespace cv { namespace gpu { namespace cudev
30483052

30493053
namespace
30503054
{
3051-
inline void cartToPolar_caller(const GpuMat& x, const GpuMat& y, GpuMat* mag, bool magSqr, GpuMat* angle, bool angleInDegrees, cudaStream_t stream)
3055+
void cartToPolar_caller(const GpuMat& x, const GpuMat& y, GpuMat* mag, bool magSqr, GpuMat* angle, bool angleInDegrees, cudaStream_t stream)
30523056
{
30533057
using namespace ::cv::gpu::cudev::mathfunc;
30543058

30553059
CV_Assert(x.size() == y.size() && x.type() == y.type());
30563060
CV_Assert(x.depth() == CV_32F);
30573061

3058-
if (mag)
3059-
mag->create(x.size(), x.type());
3060-
if (angle)
3061-
angle->create(x.size(), x.type());
3062-
30633062
GpuMat x1cn = x.reshape(1);
30643063
GpuMat y1cn = y.reshape(1);
30653064
GpuMat mag1cn = mag ? mag->reshape(1) : GpuMat();
@@ -3068,16 +3067,13 @@ namespace
30683067
cartToPolar_gpu(x1cn, y1cn, mag1cn, magSqr, angle1cn, angleInDegrees, stream);
30693068
}
30703069

3071-
inline void polarToCart_caller(const GpuMat& mag, const GpuMat& angle, GpuMat& x, GpuMat& y, bool angleInDegrees, cudaStream_t stream)
3070+
void polarToCart_caller(const GpuMat& mag, const GpuMat& angle, GpuMat& x, GpuMat& y, bool angleInDegrees, cudaStream_t stream)
30723071
{
30733072
using namespace ::cv::gpu::cudev::mathfunc;
30743073

30753074
CV_Assert((mag.empty() || mag.size() == angle.size()) && mag.type() == angle.type());
30763075
CV_Assert(mag.depth() == CV_32F);
30773076

3078-
x.create(mag.size(), mag.type());
3079-
y.create(mag.size(), mag.type());
3080-
30813077
GpuMat mag1cn = mag.reshape(1);
30823078
GpuMat angle1cn = angle.reshape(1);
30833079
GpuMat x1cn = x.reshape(1);
@@ -3087,29 +3083,65 @@ namespace
30873083
}
30883084
}
30893085

3090-
void cv::gpu::magnitude(const GpuMat& x, const GpuMat& y, GpuMat& dst, Stream& stream)
3086+
void cv::gpu::magnitude(InputArray _x, InputArray _y, OutputArray _dst, Stream& stream)
30913087
{
3088+
GpuMat x = _x.getGpuMat();
3089+
GpuMat y = _y.getGpuMat();
3090+
3091+
_dst.create(x.size(), CV_32FC1);
3092+
GpuMat dst = _dst.getGpuMat();
3093+
30923094
cartToPolar_caller(x, y, &dst, false, 0, false, StreamAccessor::getStream(stream));
30933095
}
30943096

3095-
void cv::gpu::magnitudeSqr(const GpuMat& x, const GpuMat& y, GpuMat& dst, Stream& stream)
3097+
void cv::gpu::magnitudeSqr(InputArray _x, InputArray _y, OutputArray _dst, Stream& stream)
30963098
{
3099+
GpuMat x = _x.getGpuMat();
3100+
GpuMat y = _y.getGpuMat();
3101+
3102+
_dst.create(x.size(), CV_32FC1);
3103+
GpuMat dst = _dst.getGpuMat();
3104+
30973105
cartToPolar_caller(x, y, &dst, true, 0, false, StreamAccessor::getStream(stream));
30983106
}
30993107

3100-
void cv::gpu::phase(const GpuMat& x, const GpuMat& y, GpuMat& angle, bool angleInDegrees, Stream& stream)
3108+
void cv::gpu::phase(InputArray _x, InputArray _y, OutputArray _dst, bool angleInDegrees, Stream& stream)
31013109
{
3102-
cartToPolar_caller(x, y, 0, false, &angle, angleInDegrees, StreamAccessor::getStream(stream));
3110+
GpuMat x = _x.getGpuMat();
3111+
GpuMat y = _y.getGpuMat();
3112+
3113+
_dst.create(x.size(), CV_32FC1);
3114+
GpuMat dst = _dst.getGpuMat();
3115+
3116+
cartToPolar_caller(x, y, 0, false, &dst, angleInDegrees, StreamAccessor::getStream(stream));
31033117
}
31043118

3105-
void cv::gpu::cartToPolar(const GpuMat& x, const GpuMat& y, GpuMat& mag, GpuMat& angle, bool angleInDegrees, Stream& stream)
3119+
void cv::gpu::cartToPolar(InputArray _x, InputArray _y, OutputArray _mag, OutputArray _angle, bool angleInDegrees, Stream& stream)
31063120
{
3121+
GpuMat x = _x.getGpuMat();
3122+
GpuMat y = _y.getGpuMat();
3123+
3124+
_mag.create(x.size(), CV_32FC1);
3125+
GpuMat mag = _mag.getGpuMat();
3126+
3127+
_angle.create(x.size(), CV_32FC1);
3128+
GpuMat angle = _angle.getGpuMat();
3129+
31073130
cartToPolar_caller(x, y, &mag, false, &angle, angleInDegrees, StreamAccessor::getStream(stream));
31083131
}
31093132

3110-
void cv::gpu::polarToCart(const GpuMat& magnitude, const GpuMat& angle, GpuMat& x, GpuMat& y, bool angleInDegrees, Stream& stream)
3133+
void cv::gpu::polarToCart(InputArray _mag, InputArray _angle, OutputArray _x, OutputArray _y, bool angleInDegrees, Stream& stream)
31113134
{
3112-
polarToCart_caller(magnitude, angle, x, y, angleInDegrees, StreamAccessor::getStream(stream));
3135+
GpuMat mag = _mag.getGpuMat();
3136+
GpuMat angle = _angle.getGpuMat();
3137+
3138+
_x.create(mag.size(), CV_32FC1);
3139+
GpuMat x = _x.getGpuMat();
3140+
3141+
_y.create(mag.size(), CV_32FC1);
3142+
GpuMat y = _y.getGpuMat();
3143+
3144+
polarToCart_caller(mag, angle, x, y, angleInDegrees, StreamAccessor::getStream(stream));
31133145
}
31143146

31153147
#endif

0 commit comments

Comments
 (0)