OpenCV C++ 基础api

模糊 Smoothing

GaussianBlur( src, dst, Size( 9, 9 ), 0, 0); 
medianBlur( src, dst2, 9);
OpenCV C++ 基础api_第1张图片
image.png

锐化边缘 Sharpening

Sobel(src, dst, -1, 1, 1 );
Laplacian(src, dst2, -1 );
OpenCV C++ 基础api_第2张图片
image.png

滤波 Pyramids

pyrDown(src, dst); 
pyrDown(dst, dst2);
pyrUp(dst2, dst);
pyrUp(dst, src);
OpenCV C++ 基础api_第3张图片
image.png

形态运算 Morphological operations

inRange(src, Scalar(0, 0, 100), Scalar(40, 30, 255), dst);
Mat element = getStructuringElement(MORPH_ELLIPSE,Size(15,15));
dilate(dst, dst2, element);
erode(dst2, dst3, element);
OpenCV C++ 基础api_第4张图片
image.png

查找表 Look-up tables (LUTs)

uchar * M = (uchar*)malloc(256*sizeof(uchar));
for(int i=0; i<256; i++){
   M[i] = i*0.5;
}
Mat lut(1, 256, CV_8UC1, M);
 // Apply the LUT
Mat dst;
LUT(src,lut,dst);
OpenCV C++ 基础api_第5张图片
image.png

几何变换 Geometrical transformations

仿射变换 Affine
缩放 scale

resize(src, dst, Size(0,0), 0.5, 0.5);
OpenCV C++ 基础api_第6张图片
image.png

位移 Translation

Mat M = (Mat_(2,3) << 1, 0, 200, 0, 1, 150); warpAffine(src,dst,M,src.size());
OpenCV C++ 基础api_第7张图片
image.png

旋转 rotation

Mat M = getRotationMatrix2D(Point2f(src.cols/2,src.rows/2),45,1); warpAffine(src,dst,M,src.size());
OpenCV C++ 基础api_第8张图片
image.png

斜切 Skewing

double m = 1/tan(M_PI/3);
Mat M = (Mat_(2,3) << 1, m, 0, 0, 1, 0); warpAffine(src,dst,M,Size(src.cols+0.5*src.cols,src.rows));
OpenCV C++ 基础api_第9张图片
image.png

翻转 reflextion

Mat Mh = (Mat_(2,3) << -1, 0, src.cols, 0, 1, 0
Mat Mv = (Mat_(2,3) << 1, 0, 0, 0, -1, src.rows);
Mat M = (Mat_(2,3) << -1, 0, src.cols, 0, -1, src.rows); warpAffine(src,dsth,Mh,src.size()); warpAffine(src,dstv,Mv,src.size()); warpAffine(src,dst,M,src.size());
OpenCV C++ 基础api_第10张图片
image.png

你可能感兴趣的:(OpenCV C++ 基础api)