Skip to content

Commit 5741f22

Browse files
authored
Merge pull request #3815 from cudawarped:cuda_fix_python_binaryop_with_scalar
`cudaarithm`: fix python bindings for binary ops involving scalars
2 parents 843b6ed + 06ddcce commit 5741f22

File tree

2 files changed

+250
-15
lines changed

2 files changed

+250
-15
lines changed

Diff for: modules/cudaarithm/include/opencv2/cudaarithm.hpp

+215-15
Original file line numberDiff line numberDiff line change
@@ -75,72 +75,163 @@ 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());
8789

90+
/** @brief Computes a matrix-scalar sum.
91+
92+
@param src1 First source matrix.
93+
@param src2 Second source scalar.
94+
@param dst Destination matrix that has the same size and number of channels as the input array.
95+
The depth is defined by dtype or @p src1 depth.
96+
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
97+
destination array to be changed. The mask can be used only with single channel images.
98+
@param dtype Optional depth of the output array.
99+
@param stream Stream for the asynchronous version.
100+
101+
@sa add
102+
*/
103+
CV_EXPORTS_W void inline addWithScalar(InputArray src1, Scalar src2, OutputArray dst, InputArray mask = noArray(), int dtype = -1, Stream& stream = Stream::Null()) {
104+
add(src1, src2, dst, mask, dtype, stream);
105+
}
106+
88107
/** @brief Computes a matrix-matrix or matrix-scalar difference.
89108
90109
@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 .
110+
@param src2 Second source matrix or scalar. Matrix should have the same size and type as @p src1.
92111
@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.
112+
The depth is defined by dtype or @p src1 depth.
94113
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
95114
destination array to be changed. The mask can be used only with single channel images.
96115
@param dtype Optional depth of the output array.
97116
@param stream Stream for the asynchronous version.
98117
99-
@sa subtract
118+
@warning In python both @p src1 and @p src2 have to be matrices, see @ref subtractWithScalar for scalar overload.
119+
120+
@sa cv::subtract, subtractWithScalar
100121
*/
101122
CV_EXPORTS_W void subtract(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), int dtype = -1, Stream& stream = Stream::Null());
102123

124+
/** @brief Computes matrix-scalar difference.
125+
126+
@param src1 First source matrix.
127+
@param src2 Second source scalar.
128+
@param dst Destination matrix that has the same size and number of channels as the input array.
129+
The depth is defined by dtype or @p src1 depth.
130+
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
131+
destination array to be changed. The mask can be used only with single channel images.
132+
@param dtype Optional depth of the output array.
133+
@param stream Stream for the asynchronous version.
134+
135+
@sa cv::subtract
136+
*/
137+
CV_EXPORTS_W void inline subtractWithScalar(InputArray src1, Scalar src2, OutputArray dst, InputArray mask = noArray(), int dtype = -1, Stream& stream = Stream::Null()) {
138+
subtract(src1, src2, dst, mask, dtype, stream);
139+
}
140+
103141
/** @brief Computes a matrix-matrix or matrix-scalar per-element product.
104142
105143
@param src1 First source matrix or scalar.
106144
@param src2 Second source matrix or scalar.
107145
@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.
146+
The depth is defined by dtype or @p src1 depth.
109147
@param scale Optional scale factor.
110148
@param dtype Optional depth of the output array.
111149
@param stream Stream for the asynchronous version.
112150
113-
@sa multiply
151+
@warning In python both @p src1 and @p src2 have to be matrices, see @ref multiplyWithScalar for scalar overload.
152+
153+
@sa cv::multiply, multiplyWithScalar
114154
*/
115155
CV_EXPORTS_W void multiply(InputArray src1, InputArray src2, OutputArray dst, double scale = 1, int dtype = -1, Stream& stream = Stream::Null());
116156

157+
/** @brief Computes a matrix-scalar per-element product.
158+
159+
@param src1 First source matrix.
160+
@param src2 Second source scalar.
161+
@param dst Destination matrix that has the same size and number of channels as the input array.
162+
The depth is defined by dtype or @p src1 depth.
163+
@param scale Optional scale factor.
164+
@param dtype Optional depth of the output array.
165+
@param stream Stream for the asynchronous version.
166+
167+
@sa multiply
168+
*/
169+
CV_EXPORTS_W void inline multiplyWithScalar(InputArray src1, Scalar src2, OutputArray dst, double scale = 1, int dtype = -1, Stream& stream = Stream::Null()) {
170+
multiply(src1, src2, dst, scale, dtype, stream);
171+
}
172+
117173
/** @brief Computes a matrix-matrix or matrix-scalar division.
118174
119-
@param src1 First source matrix or a scalar.
175+
@param src1 First source matrix or scalar.
120176
@param src2 Second source matrix or scalar.
121177
@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.
178+
The depth is defined by dtype or @p src1 depth.
123179
@param scale Optional scale factor.
124180
@param dtype Optional depth of the output array.
125181
@param stream Stream for the asynchronous version.
126182
127183
This function, in contrast to divide, uses a round-down rounding mode.
128184
129-
@sa divide
185+
@warning In python both @p src1 and @p src2 have to be matrices, see @ref divideWithScalar for scalar overload.
186+
187+
@sa cv::divide, divideWithScalar
130188
*/
131189
CV_EXPORTS_W void divide(InputArray src1, InputArray src2, OutputArray dst, double scale = 1, int dtype = -1, Stream& stream = Stream::Null());
132190

191+
/** @brief Computes a matrix-scalar division.
192+
193+
@param src1 First source matrix.
194+
@param src2 Second source scalar.
195+
@param dst Destination matrix that has the same size and number of channels as the input array.
196+
The depth is defined by dtype or @p src1 depth.
197+
@param scale Optional scale factor.
198+
@param dtype Optional depth of the output array.
199+
@param stream Stream for the asynchronous version.
200+
201+
This function, in contrast to divide, uses a round-down rounding mode.
202+
203+
@sa divide
204+
*/
205+
CV_EXPORTS_W void inline divideWithScalar(InputArray src1, Scalar src2, OutputArray dst, double scale = 1, int dtype = -1, Stream& stream = Stream::Null()) {
206+
divide(src1, src2, dst, scale, dtype, stream);
207+
}
208+
133209
/** @brief Computes per-element absolute difference of two matrices (or of a matrix and scalar).
134210
135211
@param src1 First source matrix or scalar.
136212
@param src2 Second source matrix or scalar.
137213
@param dst Destination matrix that has the same size and type as the input array(s).
138214
@param stream Stream for the asynchronous version.
139215
140-
@sa absdiff
216+
@warning In python both @p src1 and @p src2 have to be matrices, see @ref absdiffWithScalar for scalar overload.
217+
218+
@sa cv::absdiff, absdiffWithScalar
141219
*/
142220
CV_EXPORTS_W void absdiff(InputArray src1, InputArray src2, OutputArray dst, Stream& stream = Stream::Null());
143221

222+
/** @brief Computes per-element absolute difference of a matrix and scalar.
223+
224+
@param src1 First source matrix.
225+
@param src2 Second source scalar.
226+
@param dst Destination matrix that has the same size and type as the input array.
227+
@param stream Stream for the asynchronous version.
228+
229+
@sa absdiff
230+
*/
231+
CV_EXPORTS_W void inline absdiffWithScalar(InputArray src1, Scalar src2, OutputArray dst, Stream& stream = Stream::Null()) {
232+
absdiff(src1, src2, dst, stream);
233+
}
234+
144235
/** @brief Computes an absolute value of each matrix element.
145236
146237
@param src Source matrix.
@@ -218,10 +309,32 @@ CV_EXPORTS_W void pow(InputArray src, double power, OutputArray dst, Stream& str
218309
- **CMP_NE:** a(.) != b(.)
219310
@param stream Stream for the asynchronous version.
220311
221-
@sa compare
312+
@warning In python both @p src1 and @p src2 have to be matrices, see @ref compareWithScalar for scalar overload.
313+
314+
@sa cv::compare, compareWithScalar
222315
*/
223316
CV_EXPORTS_W void compare(InputArray src1, InputArray src2, OutputArray dst, int cmpop, Stream& stream = Stream::Null());
224317

318+
/** @brief Compares elements of a matrix and scalar.
319+
320+
@param src1 First source matrix.
321+
@param src2 Second source scalar.
322+
@param dst Destination matrix that has the same size as the input array and type \ref CV_8U.
323+
@param cmpop Flag specifying the relation between the elements to be checked:
324+
- **CMP_EQ:** a(.) == b(.)
325+
- **CMP_GT:** a(.) \> b(.)
326+
- **CMP_GE:** a(.) \>= b(.)
327+
- **CMP_LT:** a(.) \< b(.)
328+
- **CMP_LE:** a(.) \<= b(.)
329+
- **CMP_NE:** a(.) != b(.)
330+
@param stream Stream for the asynchronous version.
331+
332+
@sa compare
333+
*/
334+
CV_EXPORTS_W void inline compareWithScalar(InputArray src1, Scalar src2, OutputArray dst, int cmpop, Stream& stream = Stream::Null()) {
335+
compare(src1, src2, dst, cmpop, stream);
336+
}
337+
225338
/** @brief Performs a per-element bitwise inversion.
226339
227340
@param src Source matrix.
@@ -240,9 +353,28 @@ CV_EXPORTS_W void bitwise_not(InputArray src, OutputArray dst, InputArray mask =
240353
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
241354
destination array to be changed. The mask can be used only with single channel images.
242355
@param stream Stream for the asynchronous version.
356+
357+
@warning In python both @p src1 and @p src2 have to be matrices, see @ref bitwise_or_with_scalar for scalar overload.
358+
359+
@sa cv::bitwise_or, bitwise_or_with_scalar
243360
*/
244361
CV_EXPORTS_W void bitwise_or(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());
245362

363+
/** @brief Performs a per-element bitwise disjunction of a matrix and scalar.
364+
365+
@param src1 First source matrix.
366+
@param src2 Second source scalar.
367+
@param dst Destination matrix that has the same size and type as the input array.
368+
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
369+
destination array to be changed. The mask can be used only with single channel images.
370+
@param stream Stream for the asynchronous version.
371+
372+
@sa bitwise_or
373+
*/
374+
CV_EXPORTS_W void inline bitwise_or_with_scalar(InputArray src1, Scalar src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null()) {
375+
bitwise_or(src1, src2, dst, mask, stream);
376+
}
377+
246378
/** @brief Performs a per-element bitwise conjunction of two matrices (or of matrix and scalar).
247379
248380
@param src1 First source matrix or scalar.
@@ -251,20 +383,58 @@ CV_EXPORTS_W void bitwise_or(InputArray src1, InputArray src2, OutputArray dst,
251383
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
252384
destination array to be changed. The mask can be used only with single channel images.
253385
@param stream Stream for the asynchronous version.
386+
387+
@warning In python both @p src1 and @p src2 have to be matrices, see @ref bitwise_and_with_scalar for scalar overload.
388+
389+
@sa bitwise_and_with_scalar
254390
*/
255391
CV_EXPORTS_W void bitwise_and(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());
256392

393+
/** @brief Performs a per-element bitwise conjunction of a matrix and a scalar.
394+
395+
@param src1 First source matrix.
396+
@param src2 Second source scalar.
397+
@param dst Destination matrix that has the same size and type as the input array.
398+
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
399+
destination array to be changed. The mask can be used only with single channel images.
400+
@param stream Stream for the asynchronous version.
401+
402+
@sa bitwise_and
403+
*/
404+
CV_EXPORTS_W void inline bitwise_and_with_scalar(InputArray src1, Scalar src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null()) {
405+
bitwise_and(src1, src2, dst, mask, stream);
406+
}
407+
257408
/** @brief Performs a per-element bitwise exclusive or operation of two matrices (or of matrix and scalar).
258409
259410
@param src1 First source matrix or scalar.
260411
@param src2 Second source matrix or scalar.
261-
@param dst Destination matrix that has the same size and type as the input array(s).
412+
@param dst Destination matrix that has the same size and type as the input array.
262413
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
263414
destination array to be changed. The mask can be used only with single channel images.
264415
@param stream Stream for the asynchronous version.
416+
417+
@warning In python both @p src1 and @p src2 have to be matrices, see @ref bitwise_xor_with_scalar for scalar overload.
418+
419+
@sa cv::bitwise_xor, bitwise_xor_with_scalar
265420
*/
266421
CV_EXPORTS_W void bitwise_xor(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());
267422

423+
/** @brief Performs a per-element bitwise exclusive or operation of a matrix and a scalar.
424+
425+
@param src1 First source matrix.
426+
@param src2 Second source scalar.
427+
@param dst Destination matrix that has the same size and type as the input array(s).
428+
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
429+
destination array to be changed. The mask can be used only with single channel images.
430+
@param stream Stream for the asynchronous version.
431+
432+
@sa bitwise_xor
433+
*/
434+
CV_EXPORTS_W void inline bitwise_xor_with_scalar(InputArray src1, Scalar src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null()) {
435+
bitwise_xor(src1, src2, dst, mask, stream);
436+
}
437+
268438
/** @brief Performs pixel by pixel right shift of an image by a constant value.
269439
270440
@param src Source matrix. Supports 1, 3 and 4 channels images with integers elements.
@@ -299,21 +469,51 @@ CV_WRAP inline void lshift(InputArray src, Scalar val, OutputArray dst, Stream&
299469
@param dst Destination matrix that has the same size and type as the input array(s).
300470
@param stream Stream for the asynchronous version.
301471
302-
@sa min
472+
@warning In python both @p src1 and @p src2 have to be matrices, see @ref minWithScalar for scalar overload.
473+
474+
@sa cv::min, minWithScalar
303475
*/
304476
CV_EXPORTS_W void min(InputArray src1, InputArray src2, OutputArray dst, Stream& stream = Stream::Null());
305477

478+
/** @brief Computes the per-element minimum or a matrix and a scalar.
479+
480+
@param src1 First source matrix.
481+
@param src2 Second source scalar.
482+
@param dst Destination matrix that has the same size and type as the input array.
483+
@param stream Stream for the asynchronous version.
484+
485+
@sa min
486+
*/
487+
CV_EXPORTS_W void inline minWithScalar(InputArray src1, Scalar src2, OutputArray dst, Stream& stream = Stream::Null()) {
488+
min(src1, src2, dst, stream);
489+
}
490+
306491
/** @brief Computes the per-element maximum of two matrices (or a matrix and a scalar).
307492
308493
@param src1 First source matrix or scalar.
309494
@param src2 Second source matrix or scalar.
310495
@param dst Destination matrix that has the same size and type as the input array(s).
311496
@param stream Stream for the asynchronous version.
312497
313-
@sa max
498+
@warning In python both @p src1 and @p src2 have to be matrices, see @ref maxWithScalar for scalar overload.
499+
500+
@sa cv::max, maxWithScalar
314501
*/
315502
CV_EXPORTS_W void max(InputArray src1, InputArray src2, OutputArray dst, Stream& stream = Stream::Null());
316503

504+
/** @brief Computes the per-element maximum of a matrix and a scalar.
505+
506+
@param src1 First source matrix.
507+
@param src2 Second source scalar.
508+
@param dst Destination matrix that has the same size and type as the input array.
509+
@param stream Stream for the asynchronous version.
510+
511+
@sa max
512+
*/
513+
CV_EXPORTS_W void inline maxWithScalar(InputArray src1, Scalar src2, OutputArray dst, Stream& stream = Stream::Null()) {
514+
max(src1, src2, dst, stream);
515+
}
516+
317517
/** @brief Computes the weighted sum of two arrays.
318518
319519
@param src1 First source array.

0 commit comments

Comments
 (0)