此随笔只为记录,以备后续的回顾
一、图像的载入与显示
C++: Mat imread(const string& filename, intflags=1 );
flags >0返回一个3通道的彩色图像
flags =0返回灰度图像。
flags <0返回包含Alpha通道的加载的图像。
C++: void namedWindow(const string& winname,int flags=WINDOW_AUTOSIZE );
WINDOW_NORMAL设置了这个值,用户便可以改变窗口的大小(没有限制)
WINDOW_AUTOSIZE如果设置了这个值,窗口大小会自动调整以适应所显示的图像,并且不能手动改变窗口大小。
WINDOW_OPENGL 如果设置了这个值的话,窗口创建的时候便会支持OpenGL
C++: void imshow(const string& winname, InputArray mat);
C++: bool imwrite(const string& filename,InputArray img, const vector<int>& params=vector<int>() );
二、设定感兴趣区域--ROI
Mat imageROI=image(Rect(500,250,logo.cols,logo.rows));
void addWeighted(InputArray src1, double alpha, InputArray src2, double beta, double gamma, OutputArray dst, int dtype=-1);
三、颜色通道分离和混合
C++: void split(InputArray m,OutputArrayOfArrays mv);
C++: void merge(InputArrayOfArrays mv,OutputArray dst)
四、创建Trackbar & 图像对比度、亮度值调整
C++: int createTrackbar(conststring& trackbarname, conststring& winname,
int* value, int count, TrackbarCallback onChange=0,void* userdata=0);
五、线性邻域滤波专场:方框滤波、均值滤波与高斯滤波
C++: void boxFilter(InputArray src,OutputArray dst, int ddepth, Size ksize, Point anchor=Point(-1,-1), boolnormalize=true, int borderType=BORDER_DEFAULT )
C++: void blur(InputArray src, OutputArraydst, Size ksize, Point anchor=Point(-1,-1), int borderType=BORDER_DEFAULT )
C++: void GaussianBlur(InputArray src,OutputArray dst, Size ksize, double sigmaX, double sigmaY=0, intborderType=BORDER_DEFAULT )
六、 非线性滤波专场:中值滤波、双边滤波
C++: void medianBlur(InputArray src,OutputArray dst, int ksize)
C++: void bilateralFilter(InputArray src, OutputArraydst, int d, double sigmaColor, double sigmaSpace, int borderType=BORDER_DEFAULT)
七、形态学图像处理(一):膨胀与腐蚀
C++: void dilate( InputArray src,OutputArray dst, InputArray kernel, Point anchor=Point(-1,-1), int iterations=1,
int borderType=BORDER_CONSTANT, const Scalar& borderValue=morphologyDefaultBorderValue() );
C++: void erode( InputArray src,OutputArray dst,InputArray kernel,Point anchor=Point(-1,-1), int iterations=1,
int borderType=BORDER_CONSTANT,const Scalar& borderValue=morphologyDefaultBorderValue() );
八、形态学图像处理(二):开运算、闭运算、形态学梯度、顶帽、黑帽合辑
switch( op )
{
case MORPH_ERODE:
erode( src, dst, kernel, anchor, iterations, borderType, borderValue );
break;
case MORPH_DILATE:
dilate( src, dst, kernel, anchor, iterations, borderType, borderValue );
break;
case MORPH_OPEN:
erode( src, dst, kernel, anchor, iterations, borderType, borderValue );
dilate( dst, dst, kernel, anchor, iterations, borderType, borderValue );
break;
case CV_MOP_CLOSE:
dilate( src, dst, kernel, anchor, iterations, borderType, borderValue );
erode( dst, dst, kernel, anchor, iterations, borderType, borderValue );
break;
case CV_MOP_GRADIENT:
erode( src, temp, kernel, anchor, iterations, borderType, borderValue );
dilate( src, dst, kernel, anchor, iterations, borderType, borderValue );
dst -= temp;
break;
case CV_MOP_TOPHAT:
if( src.data != dst.data )
temp = dst;
erode( src, temp, kernel, anchor, iterations, borderType, borderValue );
dilate( temp, temp, kernel, anchor,iterations, borderType, borderValue );
dst = src - temp;
break;
case CV_MOP_BLACKHAT:
if( src.data != dst.data )
temp = dst;
dilate( src, temp, kernel, anchor, iterations, borderType, borderValue);
erode( temp, temp, kernel, anchor, iterations, borderType, borderValue);
dst = temp - src;
break;
default:
CV_Error( CV_StsBadArg, "unknown morphological operation" );
}
九、OpenCV边缘检测:Canny算子,Sobel算子,Laplace算子,Scharr滤波器合
C++: void Canny(InputArray image,OutputArray edges, double threshold1, double threshold2, int apertureSize=3,bool L2gradient=false )
C++: void Sobel (InputArray src,OutputArray dst,int ddepth,int dx,int dy,int ksize=3,double scale=1,double delta=0,int borderType=BORDER_DEFAULT );
C++: void Laplacian(InputArray src,OutputArray dst, int ddepth, int ksize=1, double scale=1, double delta=0, intborderType=BORDER_DEFAULT );
C++: void Scharr(InputArray src,OutputArray dst,int ddepth,int dx,int dy,double scale=1,double delta=0,intborderType=BORDER_DEFAULT )
十、OpenCV图像金字塔:高斯金字塔、拉普拉斯金字塔与图片尺寸缩放
C++: void resize(InputArray src,OutputArray dst, Size dsize, double fx=0, double fy=0, int interpolation=INTER_LINEAR )
C++: void pyrUp(InputArray src, OutputArraydst, const Size& dstsize=Size(), int borderType=BORDER_DEFAULT )
C++: void pyrDown(InputArray src,OutputArray dst, const Size& dstsize=Size(), int borderType=BORDER_DEFAULT)
十一、OpenCV霍夫变换:霍夫线变换,霍夫圆变换合辑
C++: void HoughLines(InputArray image, OutputArray lines, double rho, double theta, int threshold, double srn=0, double stn=0 )
C++: void HoughLinesP(InputArray image, OutputArray lines, double rho, double theta, int threshold, double minLineLength=0, double maxLineGap=0 )
C++: void HoughCircles(InputArray image,OutputArray circles, int method, double dp, double minDist, double param1=100,double param2=100, int minRadius=0, int maxRadius=0 )
十二、水漫金山:OpenCV漫水填充算法(Floodfill)
C++: void setMouseCallback(conststring& winname, MouseCallback onMouse, void* userdata=0 )
C++: int floodFill(InputOutputArray image, Point seedPoint, Scalar newVal,Rect* rect=0,Scalar loDiff=Scalar(),Scalar upDiff=Scalar(),int flags=4 )
C++: int floodFill(InputOutputArray image, InputOutputArray mask, Point seedPoint,Scalar newVal, Rect* rect=0, Scalar loDiff=Scalar(),
Scalar upDiff=Scalar(), int flags=4 )
十三、OpenCV角点检测之Harris角点检测
C++: void cornerHarris(InputArray src,OutputArray dst, int blockSize, int ksize, double k, intborderType=BORDER_DEFAULT )
C++: double threshold(InputArray src,OutputArray dst, double thresh, double maxval, int type)
十四、OpenCV重映射 & SURF特征点检测合辑
C++: void remap(InputArray src,OutputArraydst,InputArray map1,InputArray map2,int interpolation,int borderMode=BORDER_CONSTANT,
const Scalar& borderValue=Scalar())
C++: void drawKeypoints(const Mat&image, const vector<KeyPoint>& keypoints, Mat& outImage, constScalar& color=Scalar::all(-1),
int flags=DrawMatchesFlags::DEFAULT )
使用 FeatureDetector 接口来发现感兴趣点。
使用 SurfFeatureDetector 以及其函数 detect 来实现检测过程
使用函数 drawKeypoints 绘制检测到的关键点。
使用 SurfFeatureDetector发现感兴趣点
int minHessian = 400;//定义SURF中的hessian阈值特征点检测算子
SurfFeatureDetector detector( minHessian );
std::vector<KeyPoint> keypoints
detector.detect( srcImage1, keypoints );
使用drawKeypoints画出
Mat img_keypoints;
drawKeypoints( srcImage1, keypoints, img_keypoints, Scalar::all(-1), DrawMatchesFlags::DEFAULT );
十五、OpenCV仿射变换 & SURF特征点描述合辑
C++: void warpAffine(InputArray src,OutputArray dst, InputArray M, Size dsize, int flags=INTER_LINEAR, intborderMode=BORDER_CONSTANT,
const Scalar& borderValue=Scalar())
C++: void drawMatches(const Mat& img1,constvector<KeyPoint>& keypoints1,const Mat& img2,constvector<KeyPoint>& keypoints2,
constvector<DMatch>& matches1to2,Mat& outImg,const Scalar&matchColor=Scalar::all(-1),const Scalar&singlePointColor=Scalar::all(-1),
const vector<char>&matchesMask=vector<char>(),intflags=DrawMatchesFlags::DEFAULT )
C++: void drawMatches(const Mat& img1,constvector<KeyPoint>& keypoints1,const Mat& img2,constvector<KeyPoint>& keypoints2,
const vector<vector<DMatch>>&matches1to2,Mat& outImg,const Scalar&matchColor=Scalar::all(-1),
const Scalar&singlePointColor=Scalar::all(-1),constvector<vector<char>>& matchesMask=vector<vector<char>>(),intflags=DrawMatchesFlags::DEFAULT )
使用 DescriptorExtractor 接口来寻找关键点对应的特征向量。
使用 SurfDescriptorExtractor 以及它的函数 compute 来完成特定的计算。
使用 BruteForceMatcher 来匹配特征向量。
使用函数 drawMatches 来绘制检测到的匹配点。
计算描述子(特征向量)
SurfDescriptorExtractorextractor;
Matdescriptors1, descriptors2;
extractor.compute(srcImage1, keyPoint1, descriptors1 );
extractor.compute(srcImage2, keyPoints2, descriptors2 );
使用BruteForce进行匹配
//实例化一个匹配器
BruteForceMatcher<L2<float> > matcher;
std::vector<DMatch > matches;
//匹配两幅图中的描述子(descriptors)
matcher.match(descriptors1, descriptors2, matches );
绘制从两个图像中匹配出的关键点
MatimgMatches;
drawMatches(srcImage1, keyPoint1, srcImage2, keyPoints2, matches, imgMatches );//进行绘制
imshow("匹配图", imgMatches );
十六、反响投影&寻找凸包&针对整体的轮廓对象操作&计算直方图&分水岭算法
C++: void calcBackProject(const Mat* image,int nimage,const int* channels,InputArray hist,OutputArray backProject,const float** ranges,double scale=1,
bool uniform=true )
通道复制函数
C++: void mixChannels(const Mat* src,size_t nsrcs,Mat* dst,size_t ndsts,const int* formTo,size_t npairs)
C++: void convexHull(InputArray points, int hull, bool clockwise = ture, bool return, points)
C++: void findContours(InputArray src,OutputArrayOfArrays contours,OutputArray hierarchy(如指针的头),int mode(检索模式),int method(近似方法),
Point offset=Point()(偏移量))
C++: void drawContours(IntputArray src,InputArrayOfArrays contours,int contourIdx(若为0,则绘制所有轮廓),const Scalar& color,int thickness(轮廓粗细),
int lineType,InputArray hisrarchy=noArray,int maxLevel,Point offset=Point() )
C++: void calcHist(const Mat* images,int nimages,const int* cannels,InputArray mask,OutputArray hist,int dims,const int* histSize,const float** ranges,
bool uniform,bool accumulate=false)
C++: void minMaxLoc(InputArray src,double* minVal,double* maxVAL=0,Point* minLoc=0,Point* maxLoc=0,InputArray mask=noArray() )
C++: watershed(srcImage, maskImage);具体看博客
十七、模板匹配
C++: void macthTemplate(InputArray src,InputArray temp1,OutputArray result,int method)
十八、寻找透视变化 & FLANN & SIFT
C++: void findHomography(InputArray srcPoints,InputArray dstPoints,int method=0,double ransacReprojThreshold=3,OutputArray mask=noArray() )