opencv调用摄像头+灰度图+高斯滤波+Canny算子

来源:互联网 发布:淘宝货到付款怎么退货 编辑:程序博客网 时间:2024/05/16 11:44

闲来无事(主要剃了个头)


来把opencv经常要用的一些函数来梳理一下


效果图震楼



惯例opencv配置环境地址:http://blog.csdn.net/zmdsjtu/article/details/52235056



具体代码如下:

#include <opencv2/highgui/highgui.hpp>  #include <opencv2/imgproc/imgproc.hpp>  #include <opencv2/core/core.hpp>  using namespace cv;int main() {VideoCapture cap(0);Mat frame;while (waitKey(30) != 27){cap >> frame;imshow("原图", frame);cvtColor(frame, frame, CV_BGR2GRAY);//转化为灰度图imshow("去色", frame);GaussianBlur(frame, frame, Size(7, 7), 1.5, 1.5);//高斯滤波imshow("高斯滤波", frame);Canny(frame, frame, 60, 100);//Canny算子检测边缘,两个参数随便调imshow("Canny边缘", frame);}} 

转化为灰度图的代码:

cvtColor(frame, frame, CV_BGR2GRAY);//转化为灰度图

高斯滤波代码:(参数自己调节。。。)

GaussianBlur(frame, frame, Size(7, 7), 1.5, 1.5);//高斯滤波


Canny边缘检测

Canny(frame, frame, 60, 100);//Canny算子检测边缘,两个参数随便调



最后祝大家使用opencv愉快~

1 0