Skip to main content

Arithmetic Operations

add

Calculates the per-element sum of two arrays or an array and a scalar.
src1
InputArray
First input array or scalar
src2
InputArray
Second input array or scalar
dst
OutputArray
Output array with the same size and number of channels as input arrays
mask
InputArray
Optional 8-bit single channel mask that specifies elements to be changed
dtype
int
Optional depth of the output array. Default is -1 (same as input)
Formula:
Example:
Saturation is not applied when the output array has depth CV_32S. You may get incorrect sign in case of overflow.

subtract

Calculates the per-element difference between two arrays or array and a scalar.
src1
InputArray
First input array or scalar
src2
InputArray
Second input array or scalar
dst
OutputArray
Output array
mask
InputArray
Optional operation mask
dtype
int
Optional depth of the output array
Formula:
Example:

multiply

Calculates the per-element scaled product of two arrays.
src1
InputArray
First input array
src2
InputArray
Second input array of the same size and type as src1
dst
OutputArray
Output array
scale
double
Optional scale factor
dtype
int
Optional depth of the output array
Formula:
Example:
For matrix multiplication (not element-wise), use gemm() function.

divide

Performs per-element division of two arrays or a scalar by an array.
src1
InputArray
First input array (numerator)
src2
InputArray
Second input array (denominator)
scale
double
Scalar factor
dst
OutputArray
Output array
Formula:
Example:
For integer types, when src2(I) is zero, dst(I) will also be zero. For floating-point data, expect IEEE-754 behavior (NaN, Inf values).

scaleAdd

Calculates the sum of a scaled array and another array (SAXPY/DAXPY operation).
src1
InputArray
First input array
alpha
double
Scale factor for the first array
src2
InputArray
Second input array (same size and type as src1)
dst
OutputArray
Output array
Formula:
Example:

addWeighted

Calculates the weighted sum of two arrays.
src1
InputArray
First input array
alpha
double
Weight of the first array elements
src2
InputArray
Second input array
beta
double
Weight of the second array elements
gamma
double
Scalar added to each sum
dst
OutputArray
Output array
Formula:
Example:

Bitwise Operations

bitwise_and

Calculates per-element bit-wise conjunction of two arrays or array and a scalar.
src1
InputArray
First input array or scalar
src2
InputArray
Second input array or scalar
dst
OutputArray
Output array
mask
InputArray
Optional operation mask
Formula:

bitwise_or

Calculates per-element bit-wise disjunction of two arrays or array and a scalar. Formula:

bitwise_xor

Calculates per-element bit-wise exclusive OR of two arrays or array and a scalar. Formula:

bitwise_not

Inverts every bit of an array.
src
InputArray
Input array
dst
OutputArray
Output array
Formula:
Example:

Comparison Operations

compare

Performs per-element comparison of two arrays or array and scalar.
src1
InputArray
First input array or scalar
src2
InputArray
Second input array or scalar
dst
OutputArray
Output array of type CV_8U (0 or 255 values)
cmpop
int
Comparison operation: CMP_EQ, CMP_GT, CMP_GE, CMP_LT, CMP_LE, CMP_NE
Example:

min

Calculates per-element minimum of two arrays or array and scalar. Example:

max

Calculates per-element maximum of two arrays or array and scalar. Example:

inRange

Checks if array elements lie between two bounds.
src
InputArray
Input array
lowerb
InputArray
Inclusive lower boundary array or scalar
upperb
InputArray
Inclusive upper boundary array or scalar
dst
OutputArray
Output array of type CV_8U (0 or 255)
Formula:
Example:

Mathematical Operations

sqrt

Calculates square root of array elements. Formula:

pow

Raises every array element to a power.
src
InputArray
Input array
power
double
Exponent of power
dst
OutputArray
Output array
Formula:
Example:

exp

Calculates the exponent of every array element. Formula:

log

Calculates the natural logarithm of every array element. Formula:
Example:

absdiff

Calculates per-element absolute difference between two arrays or array and scalar. Formula:
Example:

magnitude

Calculates magnitude of 2D vectors.
x
InputArray
Floating-point array of x-coordinates
y
InputArray
Floating-point array of y-coordinates (same size as x)
magnitude
OutputArray
Output array of magnitudes
Formula:

phase

Calculates the rotation angle of 2D vectors.
x
InputArray
Array of x-coordinates (floating-point)
y
InputArray
Array of y-coordinates (same size and type as x)
angle
OutputArray
Output array of angles
angleInDegrees
bool
When true, angles are in degrees (0-360), otherwise radians (0-2π)
Formula:

cartToPolar

Calculates the magnitude and angle of 2D vectors. Example:

polarToCart

Converts polar coordinates to Cartesian.
magnitude
InputArray
Array of vector magnitudes
angle
InputArray
Array of vector angles
x
OutputArray
Output array of x-coordinates
y
OutputArray
Output array of y-coordinates

Matrix Operations

gemm

Performs generalized matrix multiplication (GEMM).
src1
InputArray
First input matrix
src2
InputArray
Second input matrix
alpha
double
Weight for src1 * src2
src3
InputArray
Third input matrix (added to product)
beta
double
Weight for src3
dst
OutputArray
Output matrix
flags
int
Operation flags: GEMM_1_T (transpose src1), GEMM_2_T (transpose src2), GEMM_3_T (transpose src3)
Formula:
Example:

transpose

Transposes a matrix. Formula:
Example:

transform

Performs matrix transformation of every array element.
src
InputArray
Input array (must be continuous)
dst
OutputArray
Output array
m
InputArray
Transformation matrix (2x2, 2x3, 3x3, or 3x4 for 2D, 3x3 or 3x4 for 3D)
Example:

mulTransposed

Calculates the product of a matrix and its transposition.
src
InputArray
Input matrix
dst
OutputArray
Output square matrix
aTa
bool
If true, computes src^T * src; if false, computes src * src^T
delta
InputArray
Optional delta matrix subtracted from src before multiplication
scale
double
Optional scale factor for the matrix product
Formula:

Array Manipulation

flip

Flips a 2D array around vertical, horizontal, or both axes.
src
InputArray
Input array
dst
OutputArray
Output array
flipCode
int
Flip type: 0 (vertical flip), positive (horizontal flip), negative (both axes)
Example:

rotate

Rotates a 2D array in multiples of 90 degrees.
rotateCode
int
Rotation type: ROTATE_90_CLOCKWISE, ROTATE_180, ROTATE_90_COUNTERCLOCKWISE
Example:

repeat

Fills the output array with repeated copies of the input array.
ny
int
Number of times to repeat along the vertical axis
nx
int
Number of times to repeat along the horizontal axis
Example:

hconcat

Concatenates arrays horizontally (along columns). Example:

vconcat

Concatenates arrays vertically (along rows). Example:

Channel Operations

split

Divides a multi-channel array into several single-channel arrays.
src
InputArray
Input multi-channel array
mv
OutputArrayOfArrays
Output vector of arrays
Example:

merge

Merges several arrays to make a multi-channel array. Example:

mixChannels

Copies specified channels from input arrays to specified channels of output arrays.
fromTo
const int*
Array of index pairs: fromTo[k2] is source channel, fromTo[k2+1] is destination channel
Example:
Channel indexing starts from 0. Use -1 to set a channel to zero.