add
import { add } from '@banou/opencv-wasm'Use after await initOpenCV(). See the initialization and named imports guide.
Calculates the per-element sum of two arrays or an array and a scalar.
The function add calculates:
- Sum of two arrays when both input arrays have the same size and the same number of channels:
\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) + \texttt{src2}(I)) \quad \texttt{if mask}(I) \ne0
- Sum of an array and a scalar when src2 is constructed from Scalar or has the same number of
elements as
src1.channels():
\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) + \texttt{src2} ) \quad \texttt{if mask}(I) \ne0
- Sum of a scalar and an array when src1 is constructed from Scalar or has the same number of
elements as
src2.channels():
\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1} + \texttt{src2}(I) ) \quad \texttt{if mask}(I) \ne0
where I is a multi-dimensional index of array elements. In case of multi-channel arrays, each
channel is processed independently.
The first function in the list above can be replaced with matrix expressions:
dst = src1 + src2;
dst += src1; // equivalent to add(dst, src1, dst);
The input arrays and the output array can all have the same or different depths. For example, you can add a 16-bit unsigned array to a 8-bit signed array and store the sum as a 32-bit floating-point array. Depth of the output array is determined by the dtype parameter. In the second and third cases above, as well as in the first case, when src1.depth() == src2.depth(), dtype can be set to the default -1. In this case, the output array will have the same depth as the input array, be it src1, src2 or both.
Note: Saturation is not applied when the output array has the depth CV_32S. You may even get result of an incorrect sign in the case of overflow.
Note: (Python) Be careful to difference behaviour between src1/src2 are single number and they are tuple/array.
add(src,X) means add(src,(X,X,X,X)).
add(src,(X,)) means add(src,(X,0,0,0)).
See: subtract, addWeighted, scaleAdd, Mat::convertTo
add(src1: Mat, src2: Mat, dst: Mat, mask: Mat, dtype: number): void;3 available overloads
add(src1: Mat, src2: Mat, dst: Mat): void;add(src1: Mat, src2: Mat, dst: Mat, mask: Mat): void;add(src1: Mat, src2: Mat, dst: Mat, mask: Mat, dtype: number): void;src1first input array or a scalar.
src2second input array or a scalar.
dstOutput destination, filled by the native operation. output array that has the same size and number of channels as the input array(s); the depth is defined by dtype or src1/src2.
maskoptional operation mask - CV_8U, CV_8S or CV_Bool single channel array, that specifies elements of the output array to be changed.
dtypeoptional depth of the output array (see the discussion below).
These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.