Calculates absolute difference between two arrays.
Parameters: 


The function calculates absolute difference between two arrays.
All the arrays must have the same data type and the same size (or ROI size).
#define cvAbs(src, dst) cvAbsDiffS(src, dst, cvScalarAll(0))
param src: The source array param dst: The destination array param value: The scalar
The function calculates absolute difference between an array and a scalar.
All the arrays must have the same data type and the same size (or ROI size).
Computes the perelement sum of two arrays.
Parameters: 


The function adds one array to another:
dst(I)=src1(I)+src2(I) if mask(I)!=0
All the arrays must have the same type, except the mask, and the same size (or ROI size). For types that have limited range this operation is saturating.
Computes the sum of an array and a scalar.
Parameters: 


The function adds a scalar value to every element in the source array src1 and stores the result in dst . For types that have limited range this operation is saturating.
dst(I)=src(I)+value if mask(I)!=0
All the arrays must have the same type, except the mask, and the same size (or ROI size).
Computes the weighted sum of two arrays.
Parameters: 


The function calculates the weighted sum of two arrays as follows:
dst(I)=src1(I)*alpha+src2(I)*beta+gamma
All the arrays must have the same type and the same size (or ROI size). For types that have limited range this operation is saturating.
Calculates perelement bitwise conjunction of two arrays.
Parameters: 


The function calculates perelement bitwise logical conjunction of two arrays:
dst(I)=src1(I)&src2(I) if mask(I)!=0
In the case of floatingpoint arrays their bit representations are used for the operation. All the arrays must have the same type, except the mask, and the same size.
Calculates perelement bitwise conjunction of an array and a scalar.
Parameters: 


The function calculates perelement bitwise conjunction of an array and a scalar:
dst(I)=src(I)&value if mask(I)!=0
Prior to the actual operation, the scalar is converted to the same type as that of the array(s). In the case of floatingpoint arrays their bit representations are used for the operation. All the arrays must have the same type, except the mask, and the same size.
The following sample demonstrates how to calculate the absolute value of floatingpoint array elements by clearing the mostsignificant bit:
float a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
CvMat A = cvMat(3, 3, CV_32F, &a);
int i, absMask = 0x7fffffff;
cvAndS(&A, cvRealScalar(*(float*)&absMask), &A, 0);
for(i = 0; i < 9; i++ )
printf("
The code should print:
1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0
Calculates average (mean) of array elements.
Parameters: 


The function calculates the average value M of array elements, independently for each channel:
If the array is IplImage and COI is set, the function processes the selected channel only and stores the average to the first scalar component .
Calculates average (mean) of array elements.
Parameters: 


The function calculates the average value and standard deviation of array elements, independently for each channel:
If the array is IplImage and COI is set, the function processes the selected channel only and stores the average and standard deviation to the first components of the output scalars ( and ).
Calculates covariance matrix of a set of vectors.
Parameters: 


The function calculates the covariance matrix and, optionally, the mean vector of the set of input vectors. The function can be used for PCA, for comparing vectors using Mahalanobis distance and so forth.
Calculates the magnitude and/or angle of 2d vectors.
Parameters: 


The function calculates either the magnitude, angle, or both of every 2d vector (x(I),y(I)):
magnitude(I)=sqrt(x(I)^2^+y(I)^2^ ),
angle(I)=atan(y(I)/x(I) )
The angles are calculated with 0.1 degree accuracy. For the (0,0) point, the angle is set to 0.
Calculates the cubic root
Parameter:  value – The input floatingpoint value 

The function calculates the cubic root of the argument, and normally it is faster than pow(value,1./3) . In addition, negative arguments are handled properly. Special values ( , NaN) are not handled.
Clears a specific array element.
Parameters: 


The function ClearND clears (sets to zero) a specific element of a dense array or deletes the element of a sparse array. If the sparse array element does not exists, the function does nothing.
Makes a full copy of an image, including the header, data, and ROI.
Parameter:  image – The original image 

The returned IplImage* points to the image copy.
Creates a full matrix copy.
Parameter:  mat – Matrix to be copied 

Creates a full copy of a matrix and returns a pointer to the copy.
Creates full copy of sparse array.
Parameter:  mat – Input array 

The function creates a copy of the input array and returns pointer to the copy.
Performs perelement comparison of two arrays.
Parameters: 


The function compares the corresponding elements of two arrays and fills the destination mask array:
dst(I)=src1(I) op src2(I),
dst(I) is set to 0xff (all 1 bits) if the specific relation between the elements is true and 0 otherwise. All the arrays must have the same type, except the destination, and the same size (or ROI size)
Performs perelement comparison of an array and a scalar.
Parameters: 


The function compares the corresponding elements of an array and a scalar and fills the destination mask array:
dst(I)=src(I) op scalar
where op is .
dst(I) is set to 0xff (all 1 bits) if the specific relation between the elements is true and 0 otherwise. All the arrays must have the same size (or ROI size).
#define cvCvtScale cvConvertScale
#define cvScale cvConvertScale
#define cvConvert(src, dst ) cvConvertScale((src), (dst), 1, 0 )
param src: Source array param dst: Destination array param scale: Scale factor param shift: Value added to the scaled source array elements
The function has several different purposes, and thus has several different names. It copies one array to another with optional scaling, which is performed first, and/or optional type conversion, performed after:
All the channels of multichannel arrays are processed independently.
The type of conversion is done with rounding and saturation, that is if the result of scaling + conversion can not be represented exactly by a value of the destination array element type, it is set to the nearest representable value on the real axis.
In the case of scale=1, shift=0 no prescaling is done. This is a specially optimized case and it has the appropriate Convert name. If source and destination array types have equal types, this is also a special case that can be used to scale and shift a matrix or an image and that is caled Scale .
Converts input array elements to another 8bit unsigned integer with optional linear transformation.
Parameters: 


The function is similar to ConvertScale , but it stores absolute values of the conversion results:
The function supports only destination arrays of 8u (8bit unsigned integers) type; for other types the function can be emulated by a combination of ConvertScale and Abs functions.
Converts input array elements to another 8bit unsigned integer with optional linear transformation.
Parameters: 


The function is similar to ConvertScale , but it stores absolute values of the conversion results:
The function supports only destination arrays of 8u (8bit unsigned integers) type; for other types the function can be emulated by a combination of ConvertScale and Abs functions.
Copies one array to another.
Parameters: 


The function copies selected elements from an input array to an output array:
If any of the passed arrays is of IplImage type, then its ROI and COI fields are used. Both arrays must have the same type, the same number of dimensions, and the same size. The function can also copy sparse arrays (mask is not supported in this case).
Counts nonzero array elements.
Parameter:  arr – The array must be a singlechannel array or a multichannel image with COI set 

The function returns the number of nonzero elements in arr:
In the case of IplImage both ROI and COI are supported.
The function allocates image, matrix or multidimensional array data. Note that in the case of matrix types OpenCV allocation functions are used and in the case of IplImage they are used unless CV_TURN_ON_IPL_COMPATIBILITY was called. In the latter case IPL functions are used to allocate the data.
Creates an image header and allocates the image data.
Parameters: 

This call is a shortened form of
header = cvCreateImageHeader(size, depth, channels);
cvCreateData(header);
Creates an image header but does not allocate the image data.
Parameters: 


This call is an analogue of
hdr=iplCreateImageHeader(channels, 0, depth,
channels == 1 ? "GRAY" : "RGB",
channels == 1 ? "GRAY" : channels == 3 ? "BGR" :
channels == 4 ? "BGRA" : "",
IPL_DATA_ORDER_PIXEL, IPL_ORIGIN_TL, 4,
size.width, size.height,
0,0,0,0);
but it does not use IPL functions by default (see the CV_TURN_ON_IPL_COMPATIBILITY macro).
Creates a matrix header and allocates the matrix data.
Parameters: 


This is the concise form for:
CvMat* mat = cvCreateMatHeader(rows, cols, type);
cvCreateData(mat);
Creates a matrix header but does not allocate the matrix data.
Parameters: 


The function allocates a new matrix header and returns a pointer to it. The matrix data can then be allocated using CreateData or set explicitly to userallocated data via SetData .
Creates the header and allocates the data for a multidimensional dense array.
Parameters: 


This is a short form for:
CvMatND* mat = cvCreateMatNDHeader(dims, sizes, type);
cvCreateData(mat);
Creates a new matrix header but does not allocate the matrix data.
Parameters: 


The function allocates a header for a multidimensional dense array. The array data can further be allocated using CreateData or set explicitly to userallocated data via SetData .
Creates sparse array.
Parameters: 


The function allocates a multidimensional sparse array. Initially the array contain no elements, that is Get or GetReal returns zero for every index.
Calculates the cross product of two 3D vectors.
Parameters: 


The function calculates the cross product of two 3D vectors:
or:
Performs a forward or inverse Discrete Cosine transform of a 1D or 2D floatingpoint array.
Parameters: 


The function performs a forward or inverse transform of a 1D or 2D floatingpoint array:
Forward Cosine transform of 1D vector of elements:
where
and , for .
Inverse Cosine transform of 1D vector of N elements:
(since is orthogonal matrix, )
Forward Cosine transform of 2D matrix:
Inverse Cosine transform of 2D vector of elements:
Performs a forward or inverse Discrete Fourier transform of a 1D or 2D floatingpoint array.
Parameters: 


The function performs a forward or inverse transform of a 1D or 2D floatingpoint array:
Forward Fourier transform of 1D vector of N elements:
,
Inverse Fourier transform of 1D vector of N elements:
Forward Fourier transform of 2D vector of M N elements:
Inverse Fourier transform of 2D vector of M N elements:
In the case of real (singlechannel) data, the packed format, borrowed from IPL, is used to represent the result of a forward Fourier transform or input for an inverse Fourier transform:
Note: the last column is present if N is even, the last row is present if M is even. In the case of 1D real transform the result looks like the first row of the above matrix.
Here is the example of how to compute 2D convolution using DFT.
CvMat* A = cvCreateMat(M1, N1, CVg32F);
CvMat* B = cvCreateMat(M2, N2, A>type);
// it is also possible to have only abs(M2M1)+1 times abs(N2N1)+1
// part of the full convolution result
CvMat* conv = cvCreateMat(A>rows + B>rows  1, A>cols + B>cols  1,
A>type);
// initialize A and B
...
int dftgM = cvGetOptimalDFTSize(A>rows + B>rows  1);
int dftgN = cvGetOptimalDFTSize(A>cols + B>cols  1);
CvMat* dftgA = cvCreateMat(dft_M, dft_N, A>type);
CvMat* dftgB = cvCreateMat(dft_M, dft_N, B>type);
CvMat tmp;
// copy A to dftgA and pad dft_A with zeros
cvGetSubRect(dftgA, &tmp, cvRect(0,0,A>cols,A>rows));
cvCopy(A, &tmp);
cvGetSubRect(dftgA, &tmp, cvRect(A>cols,0,dft_A>cols  A>cols,A>rows));
cvZero(&tmp);
// no need to pad bottom part of dftgA with zeros because of
// use nonzerogrows parameter in cvDFT() call below
cvDFT(dftgA, dft_A, CV_DXT_FORWARD, A>rows);
// repeat the same with the second array
cvGetSubRect(dftgB, &tmp, cvRect(0,0,B>cols,B>rows));
cvCopy(B, &tmp);
cvGetSubRect(dftgB, &tmp, cvRect(B>cols,0,dft_B>cols  B>cols,B>rows));
cvZero(&tmp);
// no need to pad bottom part of dftgB with zeros because of
// use nonzerogrows parameter in cvDFT() call below
cvDFT(dftgB, dft_B, CV_DXT_FORWARD, B>rows);
cvMulSpectrums(dftgA, dft_B, dft_A, 0 /* or CV_DXT_MUL_CONJ to get
correlation rather than convolution */);
cvDFT(dftgA, dft_A, CV_DXT_INV_SCALE, conv>rows); // calculate only
// the top part
cvGetSubRect(dftgA, &tmp, cvRect(0,0,conv>cols,conv>rows));
cvCopy(&tmp, conv);
Decrements an array data reference counter.
Parameter:  arr – Pointer to an array header 

The function decrements the data reference counter in a CvMat or CvMatND if the reference counter pointer is not NULL. If the counter reaches zero, the data is deallocated. In the current implementation the reference counter is not NULL only if the data was allocated using the CreateData function. The counter will be NULL in other cases such as: external data was assigned to the header using SetData , the matrix header is part of a larger matrix or image, or the header was converted from an image or ndimensional matrix header.
Returns the determinant of a matrix.
Parameter:  mat – The source matrix 

The function returns the determinant of the square matrix mat . The direct method is used for small matrices and Gaussian elimination is used for larger matrices. For symmetric positivedetermined matrices, it is also possible to run SVD with and then calculate the determinant as a product of the diagonal elements of .
Performs perelement division of two arrays.
Parameters: 


The function divides one array by another:
All the arrays must have the same type and the same size (or ROI size).
Calculates the dot product of two arrays in Euclidian metrics.
Parameters: 


The function calculates and returns the Euclidean dot product of two arrays.
In the case of multiple channel arrays, the results for all channels are accumulated. In particular, cvDotProduct(a,a) where a is a complex vector, will return . The function can process multidimensional arrays, row by row, layer by layer, and so on.
Computes eigenvalues and eigenvectors of a symmetric matrix.
Parameters: 


The function computes the eigenvalues and eigenvectors of matrix A :
mat*evects(i,:)' = evals(i)*evects(i,:)' (in MATLAB notation)
If either low or highindex is supplied the other is required, too. Indexing is 0based. Example: To calculate the largest eigenvector/value set lowindex=highindex=0 . To calculate all the eigenvalues, leave lowindex=highindex=1 . For legacy reasons this function always returns a square matrix the same size as the source matrix with eigenvectors and a vector the length of the source matrix with eigenvalues. The selected eigenvectors/values are always in the first highindex  lowindex + 1 rows.
The contents of matrix A is destroyed by the function.
Currently the function is slower than SVD yet less accurate, so if A is known to be positivelydefined (for example, it is a covariance matrix)it is recommended to use SVD to find eigenvalues and eigenvectors of A , especially if eigenvectors are not required.
Calculates the exponent of every array element.
Parameters: 


The function calculates the exponent of every element of the input array:
The maximum relative error is about . Currently, the function converts denormalized values to zeros on output.
Calculates the angle of a 2D vector.
Parameters: 


The function calculates the fullrange angle of an input 2D vector. The angle is measured in degrees and varies from 0 degrees to 360 degrees. The accuracy is about 0.1 degrees.
Flip a 2D array around vertical, horizontal or both axes.
Parameters: 


The function flips the array in one of three different ways (row and column indices are 0based):
The example scenarios of function use are:
Performs generalized matrix multiplication.
Parameters: 


The function performs generalized matrix multiplication:
All the matrices should have the same data type and coordinated sizes. Real or complex floatingpoint matrices are supported.
Return a specific array element.
Parameters: 


The functions return a specific array element. In the case of a sparse array the functions return 0 if the requested node does not exist (no new node is created by the functions).
Parameters: 


The functions GetCol and GetCols return the header, corresponding to a specified column span of the input array. GetCol is a shortcut for GetCols :
cvGetCol(arr, submat, col); // ~ cvGetCols(arr, submat, col, col + 1);
Returns one of array diagonals.
Parameters: 


The function returns the header, corresponding to a specified diagonal of the input array.
Return number of array dimensions and their sizes or the size of a particular dimension.
Parameters: 


The function cvGetDims returns the array dimensionality and the array of dimension sizes. In the case of IplImage or CvMat it always returns 2 regardless of number of image/matrix rows. The function cvGetDimSize returns the particular dimension size (number of elements per that dimension). For example, the following code calculates total number of array elements in two ways:
// via cvGetDims()
int sizes[CV_MAX_DIM];
int i, total = 1;
int dims = cvGetDims(arr, size);
for(i = 0; i < dims; i++ )
total *= sizes[i];
// via cvGetDims() and cvGetDimSize()
int i, total = 1;
int dims = cvGetDims(arr);
for(i = 0; i < dims; i++ )
total *= cvGetDimsSize(arr, i);
The function returns type of the array elements as described in CreateMat discussion: CV_8UC1 ... CV_64FC4 .
Returns image header for arbitrary array.
Parameters: 


The function returns the image header for the input array that can be a matrix  CvMat , or an image  IplImage* . In the case of an image the function simply returns the input pointer. In the case of CvMat it initializes an imageHeader structure with the parameters of the input matrix. Note that if we transform IplImage to CvMat and then transform CvMat back to IplImage, we can get different headers if the ROI is set, and thus some IPL functions that calculate image stride from its width and align may fail on the resultant image.
Returns the index of the channel of interest.
Parameter:  image – A pointer to the image header 

Returns the channel of interest of in an IplImage. Returned values correspond to the coi in SetImageCOI .
Returns the image ROI.
Parameter:  image – A pointer to the image header 

If there is no ROI set, cvRect(0,0,image>width,image>height) is returned.
Returns matrix header for arbitrary array.
Parameters: 


The function returns a matrix header for the input array that can be a matrix 
CvMat , an image  IplImage or a multidimensional dense array  CvMatND (latter case is allowed only if allowND != 0 ) . In the case of matrix the function simply returns the input pointer. In the case of IplImage* or CvMatND it initializes the header structure with parameters of the current image ROI and returns the pointer to this temporary structure. Because COI is not supported by CvMat , it is returned separately.
The function provides an easy way to handle both types of arrays  IplImage and CvMat  using the same code. Reverse transform from CvMat to IplImage can be done using the GetImage function.
Input array must have underlying data allocated or attached, otherwise the function fails.
If the input array is IplImage with planar data layout and COI set, the function returns the pointer to the selected plane and COI = 0. It enables perplane processing of multichannel images with planar data layout using OpenCV functions.
Returns the next sparse matrix element
Parameter:  matIterator – Sparse array iterator 

The function moves iterator to the next sparse matrix element and returns pointer to it. In the current version there is no any particular order of the elements, because they are stored in the hash table. The sample below demonstrates how to iterate through the sparse matrix:
Using InitSparseMatIterator and GetNextSparseNode to calculate sum of floatingpoint sparse array.
double sum;
int i, dims = cvGetDims(array);
CvSparseMatIterator mat_iterator;
CvSparseNode* node = cvInitSparseMatIterator(array, &mat_iterator);
for(; node != 0; node = cvGetNextSparseNode(&mat_iterator ))
{
/* get pointer to the element indices */
int* idx = CV_NODE_IDX(array, node);
/* get value of the element (assume that the type is CV_32FC1) */
float val = *(float*)CV_NODE_VAL(array, node);
printf("(");
for(i = 0; i < dims; i++ )
printf("
printf("
sum += val;
}
printf("nTotal sum =
Returns optimal DFT size for a given vector size.
Parameter:  size0 – Vector size 

The function returns the minimum number N that is greater than or equal to size0 , such that the DFT of a vector of size N can be computed fast. In the current implementation , for some , , .
The function returns a negative number if size0 is too large (very close to INT_MAX )
Retrieves lowlevel information about the array.
Parameters: 


The function fills output variables with lowlevel information about the array data. All output parameters are optional, so some of the pointers may be set to NULL . If the array is IplImage with ROI set, the parameters of ROI are returned.
The following example shows how to get access to array elements. GetRawData calculates the absolute value of the elements in a singlechannel, floatingpoint array.
float* data;
int step;
CvSize size;
int x, y;
cvGetRawData(array, (uchar**)&data, &step, &size);
step /= sizeof(data[0]);
for(y = 0; y < size.height; y++, data += step )
for(x = 0; x < size.width; x++ )
data[x] = (float)fabs(data[x]);
Return a specific element of singlechannel array.
Parameters: 


The functions cvGetReal*D return a specific element of a singlechannel array. If the array has multiple channels, a runtime error is raised. Note that Get function can be used safely for both singlechannel and multiplechannel arrays though they are a bit slower.
In the case of a sparse array the functions return 0 if the requested node does not exist (no new node is created by the functions).
Parameters: 


The functions return the header, corresponding to a specified row/row span of the input array. Note that GetRow is a shortcut for GetRows :
cvGetRow(arr, submat, row ) ~ cvGetRows(arr, submat, row, row + 1, 1);
Returns size of matrix or image ROI.
Parameter:  arr – array header 

The function returns number of rows (CvSize::height) and number of columns (CvSize::width) of the input matrix or image. In the case of image the size of ROI is returned.
Returns matrix header corresponding to the rectangular subarray of input image or matrix.
Parameters: 


The function returns header, corresponding to a specified rectangle of the input array. In other words, it allows the user to treat a rectangular part of input array as a standalone array. ROI is taken into account by the function so the subarray of ROI is actually extracted.
Checks that array elements lie between the elements of two other arrays.
Parameters: 


The function does the range check for every element of the input array:
For singlechannel arrays,
For twochannel arrays and so forth,
dst(I) is set to 0xff (all 1 bits) if src(I) is within the range and 0 otherwise. All the arrays must have the same type, except the destination, and the same size (or ROI size).
Checks that array elements lie between two scalars.
Parameters: 


The function does the range check for every element of the input array:
For singlechannel arrays,
For twochannel arrays nd so forth,
‘dst(I)’ is set to 0xff (all 1 bits) if ‘src(I)’ is within the range and 0 otherwise. All the arrays must have the same size (or ROI size).
The function increments CvMat or CvMatND data reference counter and returns the new counter value if the reference counter pointer is not NULL, otherwise it returns zero.
Initializes an image header that was previously allocated.
Parameters: 


The returned IplImage* points to the initialized header.
Initializes a preallocated matrix header.
Parameters: 


This function is often used to process raw data with OpenCV matrix functions. For example, the following code computes the matrix product of two matrices, stored as ordinary arrays:
double a[] = { 1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12 };
double b[] = { 1, 5, 9,
2, 6, 10,
3, 7, 11,
4, 8, 12 };
double c[9];
CvMat Ma, Mb, Mc ;
cvInitMatHeader(&Ma, 3, 4, CV_64FC1, a);
cvInitMatHeader(&Mb, 4, 3, CV_64FC1, b);
cvInitMatHeader(&Mc, 3, 3, CV_64FC1, c);
cvMatMulAdd(&Ma, &Mb, 0, &Mc);
// the c array now contains the product of a (3x4) and b (4x3)
Initializes a preallocated multidimensional array header.
Parameters: 


Initializes sparse array elements iterator.
Parameters: 


The function initializes iterator of sparse array elements and returns pointer to the first element, or NULL if the array is empty.
Calculates the inverse square root.
Parameter:  value – The input floatingpoint value 

The function calculates the inverse square root of the argument, and normally it is faster than 1./sqrt(value) . If the argument is zero or negative, the result is not determined. Special values ( , NaN) are not handled.
Invert
Finds the inverse or pseudoinverse of a matrix.
Parameters: 


The function inverts matrix src1 and stores the result in src2 .
In the case of LU method, the function returns the src1 determinant (src1 must be square). If it is 0, the matrix is not inverted and src2 is filled with zeros.
In the case of SVD methods, the function returns the inversed condition of src1 (ratio of the smallest singular value to the largest singular value) and 0 if src1 is all zeros. The SVD methods calculate a pseudoinverse matrix if src1 is singular.
Determines if the argument is Infinity.
Parameter:  value – The input floatingpoint value 

The function returns 1 if the argument is (as defined by IEEE754 standard), 0 otherwise.
Determines if the argument is Not A Number.
Parameter:  value – The input floatingpoint value 

The function returns 1 if the argument is Not A Number (as defined by IEEE754 standard), 0 otherwise.
Performs a lookup table transform of an array.
Parameters: 


The function fills the destination array with values from the lookup table. Indices of the entries are taken from the source array. That is, the function processes each element of src as follows:
where
Calculates the natural logarithm of every array element’s absolute value.
Parameters: 


The function calculates the natural logarithm of the absolute value of every element of the input array:
Where C is a large negative number (about 700 in the current implementation).
Calculates the Mahalonobis distance between two vectors.
Parameters: 


The function calculates and returns the weighted distance between two vectors:
The covariance matrix may be calculated using the CalcCovarMatrix function and further inverted using the Invert function (CV _ SVD method is the prefered one because the matrix might be singular).
Initializes matrix header (lightweight variant).
Parameters: 


Initializes a matrix header and assigns data to it. The matrix is filled row wise (the first cols elements of data form the first row of the matrix, etc.)
This function is a fast inline substitution for InitMatHeader . Namely, it is equivalent to:
CvMat mat;
cvInitMatHeader(&mat, rows, cols, type, data, CV_AUTOSTEP);
Finds perelement maximum of two arrays.
Parameters: 


The function calculates perelement maximum of two arrays:
All the arrays must have a single channel, the same data type and the same size (or ROI size).
Finds perelement maximum of array and scalar.
Parameters: 


The function calculates perelement maximum of array and scalar:
All the arrays must have a single channel, the same data type and the same size (or ROI size).
#define cvCvtPlaneToPix cvMerge
param src0: Input channel 0 param src1: Input channel 1 param src2: Input channel 2 param src3: Input channel 3 param dst: Destination array
The function is the opposite to Split . If the destination array has N channels then if the first N input channels are not NULL, they all are copied to the destination array; if only a single source channel of the first N is not NULL, this particular channel is copied into the destination array; otherwise an error is raised. The rest of the source channels (beyond the first N) must always be NULL. For IplImage Copy with COI set can be also used to insert a single channel into the image.
Finds perelement minimum of two arrays.
Parameters: 


The function calculates perelement minimum of two arrays:
All the arrays must have a single channel, the same data type and the same size (or ROI size).
Finds global minimum and maximum in array or subarray.
Parameters: 


The function finds minimum and maximum element values and their positions. The extremums are searched across the whole array, selected ROI (in the case of IplImage ) or, if mask is not NULL , in the specified array region. If the array has more than one channel, it must be IplImage with COI set. In the case of multidimensional arrays, minLoc>x and maxLoc>x will contain raw (linear) positions of the extremums.
Finds perelement minimum of an array and a scalar.
Parameters: 


The function calculates minimum of an array and a scalar:
All the arrays must have a single channel, the same data type and the same size (or ROI size).
Copies several channels from input arrays to certain channels of output arrays
Parameters: 


The function is a generalized form of cvSplit and Merge and some forms of CvtColor . It can be used to change the order of the planes, add/remove alpha channel, extract or insert a single plane or multiple planes etc.
As an example, this code splits a 4channel RGBA image into a 3channel BGR (i.e. with R and B swapped) and separate alpha channel image:
CvMat* rgba = cvCreateMat(100, 100, CV_8UC4);
CvMat* bgr = cvCreateMat(rgba>rows, rgba>cols, CV_8UC3);
CvMat* alpha = cvCreateMat(rgba>rows, rgba>cols, CV_8UC1);
cvSet(rgba, cvScalar(1,2,3,4));
CvArr* out[] = { bgr, alpha };
int from_to[] = { 0,2, 1,1, 2,0, 3,3 };
cvMixChannels(&bgra, 1, out, 2, from_to, 4);
Calculates the perelement product of two arrays.
Parameters: 


The function calculates the perelement product of two arrays:
All the arrays must have the same type and the same size (or ROI size). For types that have limited range this operation is saturating.
Performs perelement multiplication of two Fourier spectrums.
Parameters: 


The function performs perelement multiplication of the two CCSpacked or complex matrices that are results of a real or complex Fourier transform.
The function, together with DFT , may be used to calculate convolution of two arrays rapidly.
Calculates the product of an array and a transposed array.
Parameters: 


The function calculates the product of src and its transposition:
if , and
otherwise.
Calculates absolute array norm, absolute difference norm, or relative difference norm.
Parameters: 


The function calculates the absolute norm of arr1 if arr2 is NULL:
or the absolute difference norm if arr2 is not NULL:
or the relative difference norm if arr2 is not NULL and (normType & CV_RELATIVE) != 0 :
The function returns the calculated norm. A multiplechannel array is treated as a singlechannel, that is, the results for all channels are combined.
Performs perelement bitwise inversion of array elements.
Parameters: 


The function Not inverses every bit of every array element:
dst(I)=~src(I)
Calculates perelement bitwise disjunction of two arrays.
Parameters: 


The function calculates perelement bitwise disjunction of two arrays:
dst(I)=src1(I)src2(I)
In the case of floatingpoint arrays their bit representations are used for the operation. All the arrays must have the same type, except the mask, and the same size.
Calculates a perelement bitwise disjunction of an array and a scalar.
Parameters: 


The function OrS calculates perelement bitwise disjunction of an array and a scalar:
dst(I)=src(I)value if mask(I)!=0
Prior to the actual operation, the scalar is converted to the same type as that of the array(s). In the case of floatingpoint arrays their bit representations are used for the operation. All the arrays must have the same type, except the mask, and the same size.
Performs perspective matrix transformation of a vector array.
Parameters: 


The function transforms every element of src (by treating it as 2D or 3D vector) in the following way:
where
and
Calculates Cartesian coordinates of 2d vectors represented in polar form.
Parameters: 


The function calculates either the xcoodinate, ycoordinate or both of every vector magnitude(I)*exp(angle(I)*j), j=sqrt(1) :
x(I)=magnitude(I)*cos(angle(I)),
y(I)=magnitude(I)*sin(angle(I))
Raises every array element to a power.
Parameters: 


The function raises every element of the input array to p :
That is, for a noninteger power exponent the absolute values of input array elements are used. However, it is possible to get true values for negative values using some extra operations, as the following example, computing the cube root of array elements, shows:
CvSize size = cvGetSize(src);
CvMat* mask = cvCreateMat(size.height, size.width, CV_8UC1);
cvCmpS(src, 0, mask, CV_CMP_LT); /* find negative elements */
cvPow(src, dst, 1./3);
cvSubRS(dst, cvScalarAll(0), dst, mask); /* negate the results of negative inputs */
cvReleaseMat(&mask);
For some values of power , such as integer values, 0.5, and 0.5, specialized faster algorithms are used.
Return pointer to a particular array element.
Parameters: 


The functions return a pointer to a specific array element. Number of array dimension should match to the number of indices passed to the function except for cvPtr1D function that can be used for sequential access to 1D, 2D or nD dense arrays.
The functions can be used for sparse arrays as well  if the requested node does not exist they create it and set it to zero.
All these as well as other functions accessing array elements ( Get , GetReal , Set , SetReal ) raise an error in case if the element index is out of range.
Initializes a random number generator state.
Parameter:  seed – 64bit value used to initiate a random sequence 

The function initializes a random number generator and returns the state. The pointer to the state can be then passed to the RandInt , RandReal and RandArr functions. In the current implementation a multiplywithcarry generator is used.
Fills an array with random numbers and updates the RNG state.
Parameters: 


The function fills the destination array with uniformly or normally distributed random numbers.
In the example below, the function is used to add a few normally distributed floatingpoint numbers to random locations within a 2d array.
/* let noisy_screen be the floatingpoint 2d array that is to be "crapped" */
CvRNG rng_state = cvRNG(0xffffffff);
int i, pointCount = 1000;
/* allocate the array of coordinates of points */
CvMat* locations = cvCreateMat(pointCount, 1, CV_32SC2);
/* arr of random point values */
CvMat* values = cvCreateMat(pointCount, 1, CV_32FC1);
CvSize size = cvGetSize(noisy_screen);
/* initialize the locations */
cvRandArr(&rng_state, locations, CV_RAND_UNI, cvScalar(0,0,0,0),
cvScalar(size.width,size.height,0,0));
/* generate values */
cvRandArr(&rng_state, values, CV_RAND_NORMAL,
cvRealScalar(100), // average intensity
cvRealScalar(30) // deviation of the intensity
);
/* set the points */
for(i = 0; i < pointCount; i++ )
{
CvPoint pt = *(CvPoint*)cvPtr1D(locations, i, 0);
float value = *(float*)cvPtr1D(values, i, 0);
*((float*)cvPtr2D(noisy_screen, pt.y, pt.x, 0 )) += value;
}
/* not to forget to release the temporary arrays */
cvReleaseMat(&locations);
cvReleaseMat(&values);
/* RNG state does not need to be deallocated */
Returns a 32bit unsigned integer and updates RNG.
Parameter:  rng – RNG state initialized by RandInit and, optionally, customized by RandSetRange (though, the latter function does not affect the discussed function outcome) 

The function returns a uniformlydistributed random 32bit unsigned integer and updates the RNG state. It is similar to the rand() function from the C runtime library, but it always generates a 32bit number whereas rand() returns a number in between 0 and RAND_MAX which is or , depending on the platform.
The function is useful for generating scalar random numbers, such as points, patch sizes, table indices, etc., where integer numbers of a certain range can be generated using a modulo operation and floatingpoint numbers can be generated by scaling from 0 to 1 or any other specific range.
Here is the example from the previous function discussion rewritten using RandInt :
/* the input and the task is the same as in the previous sample. */
CvRNG rnggstate = cvRNG(0xffffffff);
int i, pointCount = 1000;
/* ...  no arrays are allocated here */
CvSize size = cvGetSize(noisygscreen);
/* make a buffer for normally distributed numbers to reduce call overhead */
#define bufferSize 16
float normalValueBuffer[bufferSize];
CvMat normalValueMat = cvMat(bufferSize, 1, CVg32F, normalValueBuffer);
int valuesLeft = 0;
for(i = 0; i < pointCount; i++ )
{
CvPoint pt;
/* generate random point */
pt.x = cvRandInt(&rnggstate )
pt.y = cvRandInt(&rnggstate )
if(valuesLeft <= 0 )
{
/* fulfill the buffer with normally distributed numbers
if the buffer is empty */
cvRandArr(&rnggstate, &normalValueMat, CV_RAND_NORMAL,
cvRealScalar(100), cvRealScalar(30));
valuesLeft = bufferSize;
}
*((float*)cvPtr2D(noisygscreen, pt.y, pt.x, 0 ) =
normalValueBuffer[valuesLeft];
}
/* there is no need to deallocate normalValueMat because we have
both the matrix header and the data on stack. It is a common and efficient
practice of working with small, fixedsize matrices */
Returns a floatingpoint random number and updates RNG.
Parameter:  rng – RNG state initialized by RNG 

The function returns a uniformlydistributed random floatingpoint number between 0 and 1 (1 is not included).
Reduces a matrix to a vector.
Parameters: 


The function reduces matrix to a vector by treating the matrix rows/columns as a set of 1D vectors and performing the specified operation on the vectors until a single row/column is obtained. For example, the function can be used to compute horizontal and vertical projections of an raster image. In the case of CV_REDUCE_SUM and CV_REDUCE_AVG the output may have a larger element bitdepth to preserve accuracy. And multichannel arrays are also supported in these two reduction modes.
The function releases the array data. In the case of CvMat or CvMatND it simply calls cvDecRefData(), that is the function can not deallocate external data. See also the note to CreateData .
Deallocates the image header and the image data.
Parameter:  image – Double pointer to the image header 

This call is a shortened form of
if(*image )
{
cvReleaseData(*image);
cvReleaseImageHeader(image);
}
Deallocates an image header.
Parameter:  image – Double pointer to the image header 

This call is an analogue of
if(image )
{
iplDeallocate(*image, IPL_IMAGE_HEADER  IPL_IMAGE_ROI);
*image = 0;
}
but it does not use IPL functions by default (see the CV_TURN_ON_IPL_COMPATIBILITY macro).
The function decrements the matrix data reference counter and deallocates matrix header. If the data reference counter is 0, it also deallocates the data.
if(*mat )
cvDecRefData(*mat);
cvFree((void**)mat);
Deallocates a multidimensional array.
Parameter:  mat – Double pointer to the array 

The function decrements the array data reference counter and releases the array header. If the reference counter reaches 0, it also deallocates the data.
if(*mat )
cvDecRefData(*mat);
cvFree((void**)mat);
Deallocates sparse array.
Parameter:  mat – Double pointer to the array 

The function releases the sparse array and clears the array pointer upon exit.
Fill the destination array with repeated copies of the source array.
Parameters: 


The function fills the destination array with repeated copies of the source array:
dst(i,j)=src(i mod rows(src), j mod cols(src))
So the destination array may be as larger as well as smaller than the source array.
Resets the image ROI to include the entire image and releases the ROI structure.
Parameter:  image – A pointer to the image header 

This produces a similar result to the following , but in addition it releases the ROI structure.
cvSetImageROI(image, cvRect(0, 0, image>width, image>height ));
cvSetImageCOI(image, 0);
Changes shape of matrix/image without copying data.
Parameters: 


The function initializes the CvMat header so that it points to the same data as the original array but has a different shape  different number of channels, different number of rows, or both.
The following example code creates one image buffer and two image headers, the first is for a 320x240x3 image and the second is for a 960x240x1 image:
IplImage* color_img = cvCreateImage(cvSize(320,240), IPL_DEPTH_8U, 3);
CvMat gray_mat_hdr;
IplImage gray_img_hdr, *gray_img;
cvReshape(color_img, &gray_mat_hdr, 1);
gray_img = cvGetImage(&gray_mat_hdr, &gray_img_hdr);
And the next example converts a 3x3 matrix to a single 1x9 vector:
CvMat* mat = cvCreateMat(3, 3, CV_32F);
CvMat row_header, *row;
row = cvReshape(mat, &row_header, 0, 1);
#define cvReshapeND(arr, header, newCn, newDims, newSizes ) \
cvReshapeMatND((arr), sizeof(*(header)), (header), \
(newCn), (newDims), (newSizes))
param arr: Input array param sizeofHeader: Size of output header to distinguish between IplImage, CvMat and CvMatND output headers param header: Output header to be filled param newCn: New number of channels. means that the number of channels remains unchanged. param newDims: New number of dimensions. means that the number of dimensions remains the same. param newSizes: Array of new dimension sizes. Only values are used, because the total number of elements must remain the same. Thus, if , newSizes array is not used.
The function is an advanced version of Reshape that can work with multidimensional arrays as well (though it can work with ordinary images and matrices) and change the number of dimensions.
Below are the two samples from the Reshape description rewritten using ReshapeMatND :
IplImage* color_img = cvCreateImage(cvSize(320,240), IPL_DEPTH_8U, 3);
IplImage gray_img_hdr, *gray_img;
gray_img = (IplImage*)cvReshapeND(color_img, &gray_img_hdr, 1, 0, 0);
...
/* second example is modified to convert 2x2x2 array to 8x1 vector */
int size[] = { 2, 2, 2 };
CvMatND* mat = cvCreateMatND(3, size, CV_32F);
CvMat row_header, *row;
row = (CvMat*)cvReshapeND(mat, &row_header, 0, 1, 0);
Converts a floatingpoint number to an integer.
Parameter:  value – The input floatingpoint value 

The functions convert the input floatingpoint number to an integer using one of the rounding modes. Round returns the nearest integer value to the argument. Floor returns the maximum integer value that is not larger than the argument. Ceil returns the minimum integer value that is not smaller than the argument. On some architectures the functions work much faster than the standard cast operations in C. If the absolute value of the argument is greater than , the result is not determined. Special values ( , NaN) are not handled.
Calculates the sum of a scaled array and another array.
Parameters: 


The function calculates the sum of a scaled array and another array:
All array parameters should have the same type and the same size.
Sets every element of an array to a given value.
Parameters: 


The function copies the scalar value to every selected element of the destination array:
If array arr is of IplImage type, then is ROI used, but COI must not be set.
Change the particular array element.
Parameters: 


The functions assign the new value to a particular array element. In the case of a sparse array the functions create the node if it does not exist yet.
Assigns user data to the array header.
Parameters: 


The function assigns user data to the array header. Header should be initialized before using cvCreate*Header , cvInit*Header or Mat (in the case of matrix) function.
Initializes a scaled identity matrix.
Parameters: 


The function initializes a scaled identity matrix:
Sets the channel of interest in an IplImage.
Parameters: 


If the ROI is set to NULL and the coi is not 0, the ROI is allocated. Most OpenCV functions do not support the COI setting, so to process an individual image/matrix channel one may copy (via Copy or Split ) the channel to a separate image/matrix, process it and then copy the result back (via Copy or Merge ) if needed.
Sets an image Region Of Interest (ROI) for a given rectangle.
Parameters: 


If the original image ROI was NULL and the rect is not the whole image, the ROI structure is allocated.
Most OpenCV functions support the use of ROI and treat the image rectangle as a separate image. For example, all of the pixel coordinates are counted from the topleft (or bottomleft) corner of the ROI, not the original image.
Change a specific array element.
Parameters: 


The functions assign a new value to a specific element of a singlechannel array. If the array has multiple channels, a runtime error is raised. Note that the Set*D function can be used safely for both singlechannel and multiplechannel arrays, though they are a bit slower.
In the case of a sparse array the functions create the node if it does not yet exist.
#define cvZero cvSetZero
param arr: Array to be cleared
The function clears the array. In the case of dense arrays (CvMat, CvMatND or IplImage), cvZero(array) is equivalent to cvSet(array,cvScalarAll(0),0). In the case of sparse arrays all the elements are removed.
Solves a linear system or leastsquares problem.
Parameters: 


The function solves a linear system or leastsquares problem (the latter is possible with SVD methods):
If CV_LU method is used, the function returns 1 if src1 is nonsingular and 0 otherwise; in the latter case dst is not valid.
Finds the real roots of a cubic equation.
Parameters: 


The function finds the real roots of a cubic equation:
If coeffs is a 4element vector:
or if coeffs is 3element vector:
The function returns the number of real roots found. The roots are stored to root array, which is padded with zeros if there is only one root.
Divides multichannel array into several singlechannel arrays or extracts a single channel from the array.
Parameters: 


The function divides a multichannel array into separate singlechannel arrays. Two modes are available for the operation. If the source array has N channels then if the first N destination channels are not NULL, they all are extracted from the source array; if only a single destination channel of the first N is not NULL, this particular channel is extracted; otherwise an error is raised. The rest of the destination channels (beyond the first N) must always be NULL. For IplImage Copy with COI set can be also used to extract a single channel from the image.
Calculates the square root.
Parameter:  value – The input floatingpoint value 

The function calculates the square root of the argument. If the argument is negative, the result is not determined.
Computes the perelement difference between two arrays.
Parameters: 


The function subtracts one array from another one:
dst(I)=src1(I)src2(I) if mask(I)!=0
All the arrays must have the same type, except the mask, and the same size (or ROI size). For types that have limited range this operation is saturating.
Computes the difference between a scalar and an array.
Parameters: 


The function subtracts every element of source array from a scalar:
dst(I)=valuesrc(I) if mask(I)!=0
All the arrays must have the same type, except the mask, and the same size (or ROI size). For types that have limited range this operation is saturating.
Computes the difference between an array and a scalar.
Parameters: 


The function subtracts a scalar from every element of the source array:
dst(I)=src(I)value if mask(I)!=0
All the arrays must have the same type, except the mask, and the same size (or ROI size). For types that have limited range this operation is saturating.
The function calculates the sum S of array elements, independently for each channel:
If the array is IplImage and COI is set, the function processes the selected channel only and stores the sum to the first scalar component.
Performs singular value back substitution.
Parameters: 


The function calculates back substitution for decomposed matrix A (see SVD description) and matrix B :
where
and is a small number that depends on the matrix data type.
This function together with SVD is used inside Invert and Solve , and the possible reason to use these (svd and bksb) “lowlevel” function, is to avoid allocation of temporary matrices inside the highlevel counterparts (inv and solve).
Performs singular value decomposition of a real floatingpoint matrix.
Parameters: 


The function decomposes matrix A into the product of a diagonal matrix and two
orthogonal matrices:
where is a diagonal matrix of singular values that can be coded as a 1D vector of singular values and and . All the singular values are nonnegative and sorted (together with and columns) in descending order.
An SVD algorithm is numerically robust and its typical applications include:
accurate eigenvalue problem solution when matrix A is a square, symmetric, and positively defined matrix, for example, when
it is a covariance matrix.
in this case will be a vector/matrix
of the eigenvalues, and
will be a matrix of the eigenvectors.
accurate solution of a poorconditioned linear system.
leastsquares solution of an overdetermined linear system. This and the preceeding is done by using the Solve function with the CV_SVD method.
accurate calculation of different matrix characteristics such as the matrix rank (the number of nonzero singular values), condition number (ratio of the largest singular value to the smallest one), and determinant (absolute value of the determinant is equal to the product of singular values).
Returns the trace of a matrix.
Parameter:  mat – The source matrix 

The function returns the sum of the diagonal elements of the matrix src1 .
Performs matrix transformation of every array element.
Parameters: 


The function performs matrix transformation of every element of array src and stores the results in dst :
That is, every element of an N channel array src is considered as an N element vector which is transformed using a matrix transmat and shift vector shiftvec into an element of M channel array dst . There is an option to embedd shiftvec into transmat . In this case transmat should be a matrix and the rightmost column is treated as the shift vector.
Both source and destination arrays should have the same depth and the same size or selected ROI size. transmat and shiftvec should be real floatingpoint matrices.
The function may be used for geometrical transformation of n dimensional point set, arbitrary linear color space transformation, shuffling the channels and so forth.
Transposes a matrix.
Parameters: 


The function transposes matrix src1 :
Note that no complex conjugation is done in the case of a complex matrix. Conjugation should be done separately: look at the sample code in XorS for an example.
Performs perelement bitwise “exclusive or” operation on two arrays.
Parameters: 


The function calculates perelement bitwise logical conjunction of two arrays:
dst(I)=src1(I)^src2(I) if mask(I)!=0
In the case of floatingpoint arrays their bit representations are used for the operation. All the arrays must have the same type, except the mask, and the same size.
Performs perelement bitwise “exclusive or” operation on an array and a scalar.
Parameters: 


The function XorS calculates perelement bitwise conjunction of an array and a scalar:
dst(I)=src(I)^value if mask(I)!=0
Prior to the actual operation, the scalar is converted to the same type as that of the array(s). In the case of floatingpoint arrays their bit representations are used for the operation. All the arrays must have the same type, except the mask, and the same size
The following sample demonstrates how to conjugate complex vector by switching the mostsignificant bit of imaging part:
float a[] = { 1, 0, 0, 1, 1, 0, 0, 1 }; /* 1, j, 1, j */
CvMat A = cvMat(4, 1, CV_32FC2, &a);
int i, negMask = 0x80000000;
cvXorS(&A, cvScalar(0, *(float*)&negMask, 0, 0 ), &A, 0);
for(i = 0; i < 4; i++ )
printf("(%.1f, %.1f) ", a[i*2], a[i*2+1]);
The code should print:
(1.0,0.0) (0.0,1.0) (1.0,0.0) (0.0,1.0)
Returns the particular element of singlechannel floatingpoint matrix.
Parameters: 


The function is a fast replacement for GetReal2D in the case of singlechannel floatingpoint matrices. It is faster because it is inline, it does fewer checks for array type and array element type, and it checks for the row and column ranges only in debug mode.
Returns a specific element of a singlechannel floatingpoint matrix.
Parameters: 


The function is a fast replacement for SetReal2D in the case of singlechannel floatingpoint matrices. It is faster because it is inline, it does fewer checks for array type and array element type, and it checks for the row and column ranges only in debug mode.