Skip to content

Commit 826e85a

Browse files
committed
cudaarithm: fix python bindings for binary ops involving scalars
1 parent 80f1ca2 commit 826e85a

File tree

2 files changed

+240
-15
lines changed

2 files changed

+240
-15
lines changed

modules/cudaarithm/include/opencv2/cudaarithm.hpp

Lines changed: 205 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,71 +75,158 @@ namespace cv { namespace cuda {
7575
@param src1 First source matrix or scalar.
7676
@param src2 Second source matrix or scalar. Matrix should have the same size and type as src1 .
7777
@param dst Destination matrix that has the same size and number of channels as the input array(s).
78-
The depth is defined by dtype or src1 depth.
78+
The depth is defined by dtype or @p src1 depth.
7979
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
8080
destination array to be changed. The mask can be used only with single channel images.
8181
@param dtype Optional depth of the output array.
8282
@param stream Stream for the asynchronous version.
8383
84-
@sa add
84+
@warning In python both @p src1 and @p src2 have to be matrices, see @ref addWithScalar for scalar overload.
85+
86+
@sa cv::add, addWithScalar
8587
*/
8688
CV_EXPORTS_W void add(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), int dtype = -1, Stream& stream = Stream::Null());
89+
/** @brief Computes a matrix-scalar sum.
90+
91+
@param src1 First source matrix.
92+
@param src2 Second source scalar.
93+
@param dst Destination matrix that has the same size and number of channels as the input array.
94+
The depth is defined by dtype or @p src1 depth.
95+
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
96+
destination array to be changed. The mask can be used only with single channel images.
97+
@param dtype Optional depth of the output array.
98+
@param stream Stream for the asynchronous version.
99+
100+
@sa add
101+
*/
102+
CV_EXPORTS_W void inline addWithScalar(InputArray src1, Scalar src2, OutputArray dst, InputArray mask = noArray(), int dtype = -1, Stream& stream = Stream::Null()) {
103+
add(src1, src2, dst, mask, dtype, stream);
104+
}
87105

88106
/** @brief Computes a matrix-matrix or matrix-scalar difference.
89107
90108
@param src1 First source matrix or scalar.
91-
@param src2 Second source matrix or scalar. Matrix should have the same size and type as src1 .
109+
@param src2 Second source matrix or scalar. Matrix should have the same size and type as @p src1.
92110
@param dst Destination matrix that has the same size and number of channels as the input array(s).
93-
The depth is defined by dtype or src1 depth.
111+
The depth is defined by dtype or @p src1 depth.
94112
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
95113
destination array to be changed. The mask can be used only with single channel images.
96114
@param dtype Optional depth of the output array.
97115
@param stream Stream for the asynchronous version.
98116
99-
@sa subtract
117+
@warning In python both @p src1 and @p src2 have to be matrices, see @ref subtractWithScalar for scalar overload.
118+
119+
@sa cv::subtract, subtractWithScalar
100120
*/
101121
CV_EXPORTS_W void subtract(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), int dtype = -1, Stream& stream = Stream::Null());
122+
/** @brief Computes matrix-scalar difference.
123+
124+
@param src1 First source matrix.
125+
@param src2 Second source scalar.
126+
@param dst Destination matrix that has the same size and number of channels as the input array.
127+
The depth is defined by dtype or @p src1 depth.
128+
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
129+
destination array to be changed. The mask can be used only with single channel images.
130+
@param dtype Optional depth of the output array.
131+
@param stream Stream for the asynchronous version.
132+
133+
@sa cv::subtract
134+
*/
135+
CV_EXPORTS_W void inline subtractWithScalar(InputArray src1, Scalar src2, OutputArray dst, InputArray mask = noArray(), int dtype = -1, Stream& stream = Stream::Null()) {
136+
subtract(src1, src2, dst, mask, dtype, stream);
137+
}
102138

103139
/** @brief Computes a matrix-matrix or matrix-scalar per-element product.
104140
105141
@param src1 First source matrix or scalar.
106142
@param src2 Second source matrix or scalar.
107143
@param dst Destination matrix that has the same size and number of channels as the input array(s).
108-
The depth is defined by dtype or src1 depth.
144+
The depth is defined by dtype or @p src1 depth.
109145
@param scale Optional scale factor.
110146
@param dtype Optional depth of the output array.
111147
@param stream Stream for the asynchronous version.
112148
113-
@sa multiply
149+
@warning In python both @p src1 and @p src2 have to be matrices, see @ref multiplyWithScalar for scalar overload.
150+
151+
@sa cv::multiply, multiplyWithScalar
114152
*/
115153
CV_EXPORTS_W void multiply(InputArray src1, InputArray src2, OutputArray dst, double scale = 1, int dtype = -1, Stream& stream = Stream::Null());
154+
/** @brief Computes a matrix-scalar per-element product.
155+
156+
@param src1 First source matrix.
157+
@param src2 Second source scalar.
158+
@param dst Destination matrix that has the same size and number of channels as the input array.
159+
The depth is defined by dtype or @p src1 depth.
160+
@param scale Optional scale factor.
161+
@param dtype Optional depth of the output array.
162+
@param stream Stream for the asynchronous version.
163+
164+
@sa multiply
165+
*/
166+
CV_EXPORTS_W void inline multiplyWithScalar(InputArray src1, Scalar src2, OutputArray dst, double scale = 1, int dtype = -1, Stream& stream = Stream::Null()) {
167+
multiply(src1, src2, dst, scale, dtype, stream);
168+
}
116169

117170
/** @brief Computes a matrix-matrix or matrix-scalar division.
118171
119-
@param src1 First source matrix or a scalar.
172+
@param src1 First source matrix or scalar.
120173
@param src2 Second source matrix or scalar.
121174
@param dst Destination matrix that has the same size and number of channels as the input array(s).
122-
The depth is defined by dtype or src1 depth.
175+
The depth is defined by dtype or @p src1 depth.
123176
@param scale Optional scale factor.
124177
@param dtype Optional depth of the output array.
125178
@param stream Stream for the asynchronous version.
126179
127180
This function, in contrast to divide, uses a round-down rounding mode.
128181
129-
@sa divide
182+
@warning In python both @p src1 and @p src2 have to be matrices, see @ref divideWithScalar for scalar overload.
183+
184+
@sa cv::divide, divideWithScalar
130185
*/
131186
CV_EXPORTS_W void divide(InputArray src1, InputArray src2, OutputArray dst, double scale = 1, int dtype = -1, Stream& stream = Stream::Null());
132187

188+
/** @brief Computes a matrix-scalar division.
189+
190+
@param src1 First source matrix.
191+
@param src2 Second source scalar.
192+
@param dst Destination matrix that has the same size and number of channels as the input array.
193+
The depth is defined by dtype or @p src1 depth.
194+
@param scale Optional scale factor.
195+
@param dtype Optional depth of the output array.
196+
@param stream Stream for the asynchronous version.
197+
198+
This function, in contrast to divide, uses a round-down rounding mode.
199+
200+
@sa divide
201+
*/
202+
CV_EXPORTS_W void inline divideWithScalar(InputArray src1, Scalar src2, OutputArray dst, double scale = 1, int dtype = -1, Stream& stream = Stream::Null()) {
203+
divide(src1, src2, dst, scale, dtype, stream);
204+
}
205+
133206
/** @brief Computes per-element absolute difference of two matrices (or of a matrix and scalar).
134207
135208
@param src1 First source matrix or scalar.
136209
@param src2 Second source matrix or scalar.
137210
@param dst Destination matrix that has the same size and type as the input array(s).
138211
@param stream Stream for the asynchronous version.
139212
140-
@sa absdiff
213+
@warning In python both @p src1 and @p src2 have to be matrices, see @ref absdiffWithScalar for scalar overload.
214+
215+
@sa cv::absdiff, absdiffWithScalar
141216
*/
142217
CV_EXPORTS_W void absdiff(InputArray src1, InputArray src2, OutputArray dst, Stream& stream = Stream::Null());
218+
/** @brief Computes per-element absolute difference of a matrix and scalar.
219+
220+
@param src1 First source matrix.
221+
@param src2 Second source scalar.
222+
@param dst Destination matrix that has the same size and type as the input array.
223+
@param stream Stream for the asynchronous version.
224+
225+
@sa absdiff
226+
*/
227+
CV_EXPORTS_W void inline absdiffWithScalar(InputArray src1, Scalar src2, OutputArray dst, Stream& stream = Stream::Null()) {
228+
absdiff(src1, src2, dst, stream);
229+
}
143230

144231
/** @brief Computes an absolute value of each matrix element.
145232
@@ -218,9 +305,30 @@ CV_EXPORTS_W void pow(InputArray src, double power, OutputArray dst, Stream& str
218305
- **CMP_NE:** a(.) != b(.)
219306
@param stream Stream for the asynchronous version.
220307
221-
@sa compare
308+
@warning In python both @p src1 and @p src2 have to be matrices, see @ref compareWithScalar for scalar overload.
309+
310+
@sa cv::compare, compareWithScalar
222311
*/
223312
CV_EXPORTS_W void compare(InputArray src1, InputArray src2, OutputArray dst, int cmpop, Stream& stream = Stream::Null());
313+
/** @brief Compares elements of a matrix and scalar.
314+
315+
@param src1 First source matrix.
316+
@param src2 Second source scalar.
317+
@param dst Destination matrix that has the same size as the input array and type \ref CV_8U.
318+
@param cmpop Flag specifying the relation between the elements to be checked:
319+
- **CMP_EQ:** a(.) == b(.)
320+
- **CMP_GT:** a(.) \> b(.)
321+
- **CMP_GE:** a(.) \>= b(.)
322+
- **CMP_LT:** a(.) \< b(.)
323+
- **CMP_LE:** a(.) \<= b(.)
324+
- **CMP_NE:** a(.) != b(.)
325+
@param stream Stream for the asynchronous version.
326+
327+
@sa compare
328+
*/
329+
CV_EXPORTS_W void inline compareWithScalar(InputArray src1, Scalar src2, OutputArray dst, int cmpop, Stream& stream = Stream::Null()) {
330+
compare(src1, src2, dst, cmpop, stream);
331+
}
224332

225333
/** @brief Performs a per-element bitwise inversion.
226334
@@ -240,8 +348,26 @@ CV_EXPORTS_W void bitwise_not(InputArray src, OutputArray dst, InputArray mask =
240348
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
241349
destination array to be changed. The mask can be used only with single channel images.
242350
@param stream Stream for the asynchronous version.
351+
352+
@warning In python both @p src1 and @p src2 have to be matrices, see @ref bitwise_or_with_scalar for scalar overload.
353+
354+
@sa cv::bitwise_or, bitwise_or_with_scalar
243355
*/
244356
CV_EXPORTS_W void bitwise_or(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());
357+
/** @brief Performs a per-element bitwise disjunction of a matrix and scalar.
358+
359+
@param src1 First source matrix.
360+
@param src2 Second source scalar.
361+
@param dst Destination matrix that has the same size and type as the input array.
362+
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
363+
destination array to be changed. The mask can be used only with single channel images.
364+
@param stream Stream for the asynchronous version.
365+
366+
@sa bitwise_or
367+
*/
368+
CV_EXPORTS_W void inline bitwise_or_with_scalar(InputArray src1, Scalar src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null()) {
369+
bitwise_or(src1, src2, dst, mask, stream);
370+
}
245371

246372
/** @brief Performs a per-element bitwise conjunction of two matrices (or of matrix and scalar).
247373
@@ -251,19 +377,55 @@ CV_EXPORTS_W void bitwise_or(InputArray src1, InputArray src2, OutputArray dst,
251377
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
252378
destination array to be changed. The mask can be used only with single channel images.
253379
@param stream Stream for the asynchronous version.
380+
381+
@warning In python both @p src1 and @p src2 have to be matrices, see @ref bitwise_and_with_scalar for scalar overload.
382+
383+
@sa bitwise_and_with_scalar
254384
*/
255385
CV_EXPORTS_W void bitwise_and(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());
386+
/** @brief Performs a per-element bitwise conjunction of a matrix and a scalar.
387+
388+
@param src1 First source matrix.
389+
@param src2 Second source scalar.
390+
@param dst Destination matrix that has the same size and type as the input array.
391+
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
392+
destination array to be changed. The mask can be used only with single channel images.
393+
@param stream Stream for the asynchronous version.
394+
395+
@sa bitwise_and
396+
*/
397+
CV_EXPORTS_W void inline bitwise_and_with_scalar(InputArray src1, Scalar src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null()) {
398+
bitwise_and(src1, src2, dst, mask, stream);
399+
}
256400

257401
/** @brief Performs a per-element bitwise exclusive or operation of two matrices (or of matrix and scalar).
258402
259403
@param src1 First source matrix or scalar.
260404
@param src2 Second source matrix or scalar.
261-
@param dst Destination matrix that has the same size and type as the input array(s).
405+
@param dst Destination matrix that has the same size and type as the input array.
262406
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
263407
destination array to be changed. The mask can be used only with single channel images.
264408
@param stream Stream for the asynchronous version.
409+
410+
@warning In python both @p src1 and @p src2 have to be matrices, see @ref bitwise_xor_with_scalar for scalar overload.
411+
412+
@sa cv::bitwise_xor, bitwise_xor_with_scalar
265413
*/
266414
CV_EXPORTS_W void bitwise_xor(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());
415+
/** @brief Performs a per-element bitwise exclusive or operation of a matrix and a scalar.
416+
417+
@param src1 First source matrix.
418+
@param src2 Second source scalar.
419+
@param dst Destination matrix that has the same size and type as the input array(s).
420+
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
421+
destination array to be changed. The mask can be used only with single channel images.
422+
@param stream Stream for the asynchronous version.
423+
424+
@sa bitwise_xor
425+
*/
426+
CV_EXPORTS_W void inline bitwise_xor_with_scalar(InputArray src1, Scalar src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null()) {
427+
bitwise_xor(src1, src2, dst, mask, stream);
428+
}
267429

268430
/** @brief Performs pixel by pixel right shift of an image by a constant value.
269431
@@ -299,9 +461,23 @@ CV_WRAP inline void lshift(InputArray src, Scalar val, OutputArray dst, Stream&
299461
@param dst Destination matrix that has the same size and type as the input array(s).
300462
@param stream Stream for the asynchronous version.
301463
302-
@sa min
464+
@warning In python both @p src1 and @p src2 have to be matrices, see @ref minWithScalar for scalar overload.
465+
466+
@sa cv::min, minWithScalar
303467
*/
304468
CV_EXPORTS_W void min(InputArray src1, InputArray src2, OutputArray dst, Stream& stream = Stream::Null());
469+
/** @brief Computes the per-element minimum or a matrix and a scalar.
470+
471+
@param src1 First source matrix.
472+
@param src2 Second source scalar.
473+
@param dst Destination matrix that has the same size and type as the input array.
474+
@param stream Stream for the asynchronous version.
475+
476+
@sa min
477+
*/
478+
CV_EXPORTS_W void inline minWithScalar(InputArray src1, Scalar src2, OutputArray dst, Stream& stream = Stream::Null()) {
479+
min(src1, src2, dst, stream);
480+
}
305481

306482
/** @brief Computes the per-element maximum of two matrices (or a matrix and a scalar).
307483
@@ -310,9 +486,23 @@ CV_EXPORTS_W void min(InputArray src1, InputArray src2, OutputArray dst, Stream&
310486
@param dst Destination matrix that has the same size and type as the input array(s).
311487
@param stream Stream for the asynchronous version.
312488
313-
@sa max
489+
@warning In python both @p src1 and @p src2 have to be matrices, see @ref maxWithScalar for scalar overload.
490+
491+
@sa cv::max, maxWithScalar
314492
*/
315493
CV_EXPORTS_W void max(InputArray src1, InputArray src2, OutputArray dst, Stream& stream = Stream::Null());
494+
/** @brief Computes the per-element maximum of a matrix and a scalar.
495+
496+
@param src1 First source matrix.
497+
@param src2 Second source scalar.
498+
@param dst Destination matrix that has the same size and type as the input array.
499+
@param stream Stream for the asynchronous version.
500+
501+
@sa max
502+
*/
503+
CV_EXPORTS_W void inline maxWithScalar(InputArray src1, Scalar src2, OutputArray dst, Stream& stream = Stream::Null()) {
504+
max(src1, src2, dst, stream);
505+
}
316506

317507
/** @brief Computes the weighted sum of two arrays.
318508

0 commit comments

Comments
 (0)