opencv c++基本操作

常用操作

imread

imread (char *filename, int flag=1);

第二个参数,int类型的flags,为载入标识,它指定一个加载图像的颜色类型。可以看到它自带缺省值1.
flags >0返回一个3通道的彩色图像。
flags =0返回灰度图像。
flags <0返回包含Alpha通道的加载的图像

threshold

threshold(imag_gay, dst_binary, 200, 255, THRESH_BINARY);    //将imag_gray转化为二值图。以200为阈值,小于200均变为黑色。

创建空白图像

Mat newpic = Mat::zeros(rows, cols, CV_8UC3)

CV_8UC3表示3通道的图像,每个通道的灰度级为256

常用数据结构

Scalar(blue, green, red) 
MatND类是用于存储直方图的一种数据结构

Rectangle && Rect

C++: void rectangle(Mat& img, Point pt1,Point pt2,const Scalar& color, int thickness=1, int lineType=8, int shift=0)
C++: void rectangle(Mat& img, Rect rec, const Scalar& color, int thickness=1, int lineType=8, int shift=0 )

notes:
1.可以看到最后三个参数描述画图用的线条,有时候系统没有给缺省值,我们需要手动加上,不然就会报错。
2.第一种创建方式的第二个参数是点的坐标,而不是矩形的长与宽,而类Rect则不相同,千万别搞混Rect( startx, starty, rectwidth, rectheight);

posted @ 2017-03-04 18:47  fariver  阅读(502)  评论(0编辑  收藏  举报