Skip to main content

Arithmetic Operations

add

Calculates the per-element sum of two arrays or an array and a scalar.
InputArray
First input array or scalar
InputArray
Second input array or scalar
OutputArray
Output array with the same size and number of channels as input arrays
InputArray
Optional 8-bit single channel mask that specifies elements to be changed
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.
InputArray
First input array or scalar
InputArray
Second input array or scalar
OutputArray
Output array
InputArray
Optional operation mask
int
Optional depth of the output array
Formula:
Example:

multiply

Calculates the per-element scaled product of two arrays.
InputArray
First input array
InputArray
Second input array of the same size and type as src1
OutputArray
Output array
double
Optional scale factor
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.
InputArray
First input array (numerator)
InputArray
Second input array (denominator)
double
Scalar factor
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).
InputArray
First input array
double
Scale factor for the first array
InputArray
Second input array (same size and type as src1)
OutputArray
Output array
Formula:
Example:

addWeighted

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

Bitwise Operations

bitwise_and

Calculates per-element bit-wise conjunction of two arrays or array and a scalar.
InputArray
First input array or scalar
InputArray
Second input array or scalar
OutputArray
Output array
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.
InputArray
Input array
OutputArray
Output array
Formula:
Example:

Comparison Operations

compare

Performs per-element comparison of two arrays or array and scalar.
InputArray
First input array or scalar
InputArray
Second input array or scalar
OutputArray
Output array of type CV_8U (0 or 255 values)
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.
InputArray
Input array
InputArray
Inclusive lower boundary array or scalar
InputArray
Inclusive upper boundary array or scalar
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.
InputArray
Input array
double
Exponent of power
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.
InputArray
Floating-point array of x-coordinates
InputArray
Floating-point array of y-coordinates (same size as x)
OutputArray
Output array of magnitudes
Formula:

phase

Calculates the rotation angle of 2D vectors.
InputArray
Array of x-coordinates (floating-point)
InputArray
Array of y-coordinates (same size and type as x)
OutputArray
Output array of angles
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.
InputArray
Array of vector magnitudes
InputArray
Array of vector angles
OutputArray
Output array of x-coordinates
OutputArray
Output array of y-coordinates

Matrix Operations

gemm

Performs generalized matrix multiplication (GEMM).
InputArray
First input matrix
InputArray
Second input matrix
double
Weight for src1 * src2
InputArray
Third input matrix (added to product)
double
Weight for src3
OutputArray
Output matrix
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.
InputArray
Input array (must be continuous)
OutputArray
Output array
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.
InputArray
Input matrix
OutputArray
Output square matrix
bool
If true, computes src^T * src; if false, computes src * src^T
InputArray
Optional delta matrix subtracted from src before multiplication
double
Optional scale factor for the matrix product
Formula:

Array Manipulation

flip

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

rotate

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

repeat

Fills the output array with repeated copies of the input array.
int
Number of times to repeat along the vertical axis
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.
InputArray
Input multi-channel array
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.
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.