目录
第一个:imread,imshow,waitKey
第二个:cvtColor,GaussianBlur,Canny
配置就不再说太多了,有很多教程
#include
#include
using namespace cv;
using namespace std;
int main(){
Mat img = imread("./shapes.png");
imshow("handsome",img);
waitKey(0);
return 0;
}
头文件可以直接包括opencv.hpp
imread: 从目录下的图片读取到 Mat img中
imshow:显示一张图片
参数一:窗口标题
参数二:显示Mat
waitKey: 参数是0等待按键按下,其他则等待参数秒,返回按下的ascoll码
#include
#include
using namespace cv;
using namespace std;
int main(){
Mat img = imread("./shapes.png");
Mat imgGray,imgBlur,imgCanny;
cvtColor(img,COLOR_BGR2GRAY);//将图片转为灰色
GaussianBlur(imgGray,imgBlur,Size(3,3),3);//模糊图片,在Canny检测前常用
Canny(imgBlur,imgCanny,25,75);
}
cvtColor: 转换色彩空间(opencv使用bgr,不是rgb,bgr及blue,grean,red)
参数三:转换的色彩空间。常用有:COLOR_BGR2GRAY(转灰度),COLOR_BGR2HSV(颜色检测常用)....
GaussianBlur: 高斯模糊(其实就是模糊图片)
参数三,四 一般一样:模糊程度,Canny常用3(Size(3,3),2),高度模糊用7(Size(7,7),7)
Canny: 边缘检测:
参数三,四:25,75精准,50,150粗点,能将物体的边缘检测出来。