Skip to content

Commit

Permalink
Merge pull request #3815 from cudawarped:cuda_fix_python_binaryop_wit…
Browse files Browse the repository at this point in the history
…h_scalar

`cudaarithm`: fix python bindings for binary ops involving scalars
  • Loading branch information
asmorkalov authored Oct 31, 2024
2 parents 843b6ed + 06ddcce commit 5741f22
Show file tree
Hide file tree
Showing 2 changed files with 250 additions and 15 deletions.
230 changes: 215 additions & 15 deletions modules/cudaarithm/include/opencv2/cudaarithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,72 +75,163 @@ namespace cv { namespace cuda {
@param src1 First source matrix or scalar.
@param src2 Second source matrix or scalar. Matrix should have the same size and type as src1 .
@param dst Destination matrix that has the same size and number of channels as the input array(s).
The depth is defined by dtype or src1 depth.
The depth is defined by dtype or @p src1 depth.
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
destination array to be changed. The mask can be used only with single channel images.
@param dtype Optional depth of the output array.
@param stream Stream for the asynchronous version.
@sa add
@warning In python both @p src1 and @p src2 have to be matrices, see @ref addWithScalar for scalar overload.
@sa cv::add, addWithScalar
*/
CV_EXPORTS_W void add(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), int dtype = -1, Stream& stream = Stream::Null());

/** @brief Computes a matrix-scalar sum.
@param src1 First source matrix.
@param src2 Second source scalar.
@param dst Destination matrix that has the same size and number of channels as the input array.
The depth is defined by dtype or @p src1 depth.
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
destination array to be changed. The mask can be used only with single channel images.
@param dtype Optional depth of the output array.
@param stream Stream for the asynchronous version.
@sa add
*/
CV_EXPORTS_W void inline addWithScalar(InputArray src1, Scalar src2, OutputArray dst, InputArray mask = noArray(), int dtype = -1, Stream& stream = Stream::Null()) {
add(src1, src2, dst, mask, dtype, stream);
}

/** @brief Computes a matrix-matrix or matrix-scalar difference.
@param src1 First source matrix or scalar.
@param src2 Second source matrix or scalar. Matrix should have the same size and type as src1 .
@param src2 Second source matrix or scalar. Matrix should have the same size and type as @p src1.
@param dst Destination matrix that has the same size and number of channels as the input array(s).
The depth is defined by dtype or src1 depth.
The depth is defined by dtype or @p src1 depth.
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
destination array to be changed. The mask can be used only with single channel images.
@param dtype Optional depth of the output array.
@param stream Stream for the asynchronous version.
@sa subtract
@warning In python both @p src1 and @p src2 have to be matrices, see @ref subtractWithScalar for scalar overload.
@sa cv::subtract, subtractWithScalar
*/
CV_EXPORTS_W void subtract(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), int dtype = -1, Stream& stream = Stream::Null());

/** @brief Computes matrix-scalar difference.
@param src1 First source matrix.
@param src2 Second source scalar.
@param dst Destination matrix that has the same size and number of channels as the input array.
The depth is defined by dtype or @p src1 depth.
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
destination array to be changed. The mask can be used only with single channel images.
@param dtype Optional depth of the output array.
@param stream Stream for the asynchronous version.
@sa cv::subtract
*/
CV_EXPORTS_W void inline subtractWithScalar(InputArray src1, Scalar src2, OutputArray dst, InputArray mask = noArray(), int dtype = -1, Stream& stream = Stream::Null()) {
subtract(src1, src2, dst, mask, dtype, stream);
}

/** @brief Computes a matrix-matrix or matrix-scalar per-element product.
@param src1 First source matrix or scalar.
@param src2 Second source matrix or scalar.
@param dst Destination matrix that has the same size and number of channels as the input array(s).
The depth is defined by dtype or src1 depth.
The depth is defined by dtype or @p src1 depth.
@param scale Optional scale factor.
@param dtype Optional depth of the output array.
@param stream Stream for the asynchronous version.
@sa multiply
@warning In python both @p src1 and @p src2 have to be matrices, see @ref multiplyWithScalar for scalar overload.
@sa cv::multiply, multiplyWithScalar
*/
CV_EXPORTS_W void multiply(InputArray src1, InputArray src2, OutputArray dst, double scale = 1, int dtype = -1, Stream& stream = Stream::Null());

/** @brief Computes a matrix-scalar per-element product.
@param src1 First source matrix.
@param src2 Second source scalar.
@param dst Destination matrix that has the same size and number of channels as the input array.
The depth is defined by dtype or @p src1 depth.
@param scale Optional scale factor.
@param dtype Optional depth of the output array.
@param stream Stream for the asynchronous version.
@sa multiply
*/
CV_EXPORTS_W void inline multiplyWithScalar(InputArray src1, Scalar src2, OutputArray dst, double scale = 1, int dtype = -1, Stream& stream = Stream::Null()) {
multiply(src1, src2, dst, scale, dtype, stream);
}

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

/** @brief Computes a matrix-scalar division.
@param src1 First source matrix.
@param src2 Second source scalar.
@param dst Destination matrix that has the same size and number of channels as the input array.
The depth is defined by dtype or @p src1 depth.
@param scale Optional scale factor.
@param dtype Optional depth of the output array.
@param stream Stream for the asynchronous version.
This function, in contrast to divide, uses a round-down rounding mode.
@sa divide
*/
CV_EXPORTS_W void inline divideWithScalar(InputArray src1, Scalar src2, OutputArray dst, double scale = 1, int dtype = -1, Stream& stream = Stream::Null()) {
divide(src1, src2, dst, scale, dtype, stream);
}

/** @brief Computes per-element absolute difference of two matrices (or of a matrix and scalar).
@param src1 First source matrix or scalar.
@param src2 Second source matrix or scalar.
@param dst Destination matrix that has the same size and type as the input array(s).
@param stream Stream for the asynchronous version.
@sa absdiff
@warning In python both @p src1 and @p src2 have to be matrices, see @ref absdiffWithScalar for scalar overload.
@sa cv::absdiff, absdiffWithScalar
*/
CV_EXPORTS_W void absdiff(InputArray src1, InputArray src2, OutputArray dst, Stream& stream = Stream::Null());

/** @brief Computes per-element absolute difference of a matrix and scalar.
@param src1 First source matrix.
@param src2 Second source scalar.
@param dst Destination matrix that has the same size and type as the input array.
@param stream Stream for the asynchronous version.
@sa absdiff
*/
CV_EXPORTS_W void inline absdiffWithScalar(InputArray src1, Scalar src2, OutputArray dst, Stream& stream = Stream::Null()) {
absdiff(src1, src2, dst, stream);
}

/** @brief Computes an absolute value of each matrix element.
@param src Source matrix.
Expand Down Expand Up @@ -218,10 +309,32 @@ CV_EXPORTS_W void pow(InputArray src, double power, OutputArray dst, Stream& str
- **CMP_NE:** a(.) != b(.)
@param stream Stream for the asynchronous version.
@sa compare
@warning In python both @p src1 and @p src2 have to be matrices, see @ref compareWithScalar for scalar overload.
@sa cv::compare, compareWithScalar
*/
CV_EXPORTS_W void compare(InputArray src1, InputArray src2, OutputArray dst, int cmpop, Stream& stream = Stream::Null());

/** @brief Compares elements of a matrix and scalar.
@param src1 First source matrix.
@param src2 Second source scalar.
@param dst Destination matrix that has the same size as the input array and type \ref CV_8U.
@param cmpop Flag specifying the relation between the elements to be checked:
- **CMP_EQ:** a(.) == b(.)
- **CMP_GT:** a(.) \> b(.)
- **CMP_GE:** a(.) \>= b(.)
- **CMP_LT:** a(.) \< b(.)
- **CMP_LE:** a(.) \<= b(.)
- **CMP_NE:** a(.) != b(.)
@param stream Stream for the asynchronous version.
@sa compare
*/
CV_EXPORTS_W void inline compareWithScalar(InputArray src1, Scalar src2, OutputArray dst, int cmpop, Stream& stream = Stream::Null()) {
compare(src1, src2, dst, cmpop, stream);
}

/** @brief Performs a per-element bitwise inversion.
@param src Source matrix.
Expand All @@ -240,9 +353,28 @@ CV_EXPORTS_W void bitwise_not(InputArray src, OutputArray dst, InputArray mask =
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
destination array to be changed. The mask can be used only with single channel images.
@param stream Stream for the asynchronous version.
@warning In python both @p src1 and @p src2 have to be matrices, see @ref bitwise_or_with_scalar for scalar overload.
@sa cv::bitwise_or, bitwise_or_with_scalar
*/
CV_EXPORTS_W void bitwise_or(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());

/** @brief Performs a per-element bitwise disjunction of a matrix and scalar.
@param src1 First source matrix.
@param src2 Second source scalar.
@param dst Destination matrix that has the same size and type as the input array.
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
destination array to be changed. The mask can be used only with single channel images.
@param stream Stream for the asynchronous version.
@sa bitwise_or
*/
CV_EXPORTS_W void inline bitwise_or_with_scalar(InputArray src1, Scalar src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null()) {
bitwise_or(src1, src2, dst, mask, stream);
}

/** @brief Performs a per-element bitwise conjunction of two matrices (or of matrix and scalar).
@param src1 First source matrix or scalar.
Expand All @@ -251,20 +383,58 @@ CV_EXPORTS_W void bitwise_or(InputArray src1, InputArray src2, OutputArray dst,
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
destination array to be changed. The mask can be used only with single channel images.
@param stream Stream for the asynchronous version.
@warning In python both @p src1 and @p src2 have to be matrices, see @ref bitwise_and_with_scalar for scalar overload.
@sa bitwise_and_with_scalar
*/
CV_EXPORTS_W void bitwise_and(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());

/** @brief Performs a per-element bitwise conjunction of a matrix and a scalar.
@param src1 First source matrix.
@param src2 Second source scalar.
@param dst Destination matrix that has the same size and type as the input array.
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
destination array to be changed. The mask can be used only with single channel images.
@param stream Stream for the asynchronous version.
@sa bitwise_and
*/
CV_EXPORTS_W void inline bitwise_and_with_scalar(InputArray src1, Scalar src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null()) {
bitwise_and(src1, src2, dst, mask, stream);
}

/** @brief Performs a per-element bitwise exclusive or operation of two matrices (or of matrix and scalar).
@param src1 First source matrix or scalar.
@param src2 Second source matrix or scalar.
@param dst Destination matrix that has the same size and type as the input array(s).
@param dst Destination matrix that has the same size and type as the input array.
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
destination array to be changed. The mask can be used only with single channel images.
@param stream Stream for the asynchronous version.
@warning In python both @p src1 and @p src2 have to be matrices, see @ref bitwise_xor_with_scalar for scalar overload.
@sa cv::bitwise_xor, bitwise_xor_with_scalar
*/
CV_EXPORTS_W void bitwise_xor(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());

/** @brief Performs a per-element bitwise exclusive or operation of a matrix and a scalar.
@param src1 First source matrix.
@param src2 Second source scalar.
@param dst Destination matrix that has the same size and type as the input array(s).
@param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
destination array to be changed. The mask can be used only with single channel images.
@param stream Stream for the asynchronous version.
@sa bitwise_xor
*/
CV_EXPORTS_W void inline bitwise_xor_with_scalar(InputArray src1, Scalar src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null()) {
bitwise_xor(src1, src2, dst, mask, stream);
}

/** @brief Performs pixel by pixel right shift of an image by a constant value.
@param src Source matrix. Supports 1, 3 and 4 channels images with integers elements.
Expand Down Expand Up @@ -299,21 +469,51 @@ CV_WRAP inline void lshift(InputArray src, Scalar val, OutputArray dst, Stream&
@param dst Destination matrix that has the same size and type as the input array(s).
@param stream Stream for the asynchronous version.
@sa min
@warning In python both @p src1 and @p src2 have to be matrices, see @ref minWithScalar for scalar overload.
@sa cv::min, minWithScalar
*/
CV_EXPORTS_W void min(InputArray src1, InputArray src2, OutputArray dst, Stream& stream = Stream::Null());

/** @brief Computes the per-element minimum or a matrix and a scalar.
@param src1 First source matrix.
@param src2 Second source scalar.
@param dst Destination matrix that has the same size and type as the input array.
@param stream Stream for the asynchronous version.
@sa min
*/
CV_EXPORTS_W void inline minWithScalar(InputArray src1, Scalar src2, OutputArray dst, Stream& stream = Stream::Null()) {
min(src1, src2, dst, stream);
}

/** @brief Computes the per-element maximum of two matrices (or a matrix and a scalar).
@param src1 First source matrix or scalar.
@param src2 Second source matrix or scalar.
@param dst Destination matrix that has the same size and type as the input array(s).
@param stream Stream for the asynchronous version.
@sa max
@warning In python both @p src1 and @p src2 have to be matrices, see @ref maxWithScalar for scalar overload.
@sa cv::max, maxWithScalar
*/
CV_EXPORTS_W void max(InputArray src1, InputArray src2, OutputArray dst, Stream& stream = Stream::Null());

/** @brief Computes the per-element maximum of a matrix and a scalar.
@param src1 First source matrix.
@param src2 Second source scalar.
@param dst Destination matrix that has the same size and type as the input array.
@param stream Stream for the asynchronous version.
@sa max
*/
CV_EXPORTS_W void inline maxWithScalar(InputArray src1, Scalar src2, OutputArray dst, Stream& stream = Stream::Null()) {
max(src1, src2, dst, stream);
}

/** @brief Computes the weighted sum of two arrays.
@param src1 First source array.
Expand Down
Loading

0 comments on commit 5741f22

Please sign in to comment.