Opencv Cheatsheet PDF
Opencv Cheatsheet PDF
SparseMat
Ptr
src.copyTo(dst)
Copy matrix to another one
src.convertTo(dst,type,scale,shift) Scale and convert to
another datatype
m.clone()
Make deep copy of a matrix
Create a matrix
m.reshape(nch,nrows)
Change matrix dimensions and/or numMat image(240, 320, CV_8UC3);
ber of channels without copying data
[Re]allocate a pre-declared matrix
m.row(i),
m.col(i)
Take a matrix row/column
image.create(480, 640, CV_8UC3);
m.rowRange(Range(i1,i2)) Take a matrix row/column span
Create a matrix initialized with a constant
m.colRange(Range(j1,j2))
Mat A33(3, 3, CV_32F, Scalar(5));
m.diag(i)
Take a matrix diagonal
Mat B33(3, 3, CV_32F); B33 = Scalar(5);
m(Range(i1,i2),Range(j1,j2)),Take a submatrix
Mat C33 = Mat::ones(3, 3, CV_32F)*5.;
m(roi)
Mat D33 = Mat::zeros(3, 3, CV_32F) + 5.;
m.repeat(ny,nx)
Make a bigger matrix from a smaller one
Create a matrix initialized with specied values
flip(src,dst,dir)
Reverse the order of matrix rows and/or
double a = CV_PI/3;
columns
Mat A22 = (Mat_<float>(2, 2)
split(...)
Split multi-channel matrix into separate
cos(a), -sin(a), sin(a), cos(a));
channels
float B22data[] = {cos(a), -sin(a), sin(a), cos(a)};
merge(...)
Make a multi-channel matrix out of the
Mat B22 = Mat(2, 2, CV_32F, B22data).clone();
separate channels
Initialize a random matrix
mixChannels(...)
Generalized form of split() and merge()
randu(image, Scalar(0), Scalar(256)); // uniform dist
randShuffle(...)
Randomly shue matrix elements
randn(image, Scalar(128), Scalar(10)); // Gaussian dist
Matrix Basics
A33.at<float>(i,j) = A33.at<float>(j,i)+1;
minMaxLoc(),
various statistics of matrix elements.
exp(), log(), pow(), sqrt(), cartToPolar(),
polarToCart()
the classical math functions.
scaleAdd(), transpose(), gemm(), invert(), solve(),
determinant(), trace(), eigen(), SVD,
the algebraic functions + SVD class.
dft(), idft(), dct(), idct(),
discrete Fourier and cosine transformations
For some operations a more convenient algebraic notation can
be used, for example:
Mat delta = (J.t()*J + lambda*
Mat::eye(J.cols, J.cols, J.type()))
.inv(CV_SVD)*(J.t()*err);
implements the core of Levenberg-Marquardt optimization
algorithm.
Image Processsing
Filtering
filter2D()
sepFilter2D()
boxFilter(),
GaussianBlur(),
medianBlur(),
bilateralFilter()
Sobel(), Scharr()
Laplacian()
erode(), dilate()
Geometrical Transformations
Histograms
Object Detection
Contours
Data I/O