//-----------------------------------OpenCV实现基于canny检测-------------------------------------
// 所用IDE版本: Visual Studio 2013
// 开发所用OpenCV版本: 2.4.9
// 2016年10月 Created by 孙立波
//*****从笔记本电脑摄像头读取视频抠图进行blur高斯模糊和canny边缘检测处理,并实时显示处理效果
#include<opencv2/opencv.hpp>
using namespace cv;
int main()
{
//从摄像头读入视频
VideoCapture capture(0);//或者写成:VideoCapture capture;capture.open(0)
Mat cameraPicture;//这个变量很重要,用于显示
while (1)
{
//读入图像
Mat frame;//变量用于存储当前帧图像
capture>>frame;
cvtColor(frame, cameraPicture, CV_BGR2GRAY);
//使用3*3模板去噪高斯模糊(3*3+1=7)
blur(cameraPicture, cameraPicture, Size(7, 7));
//进行canny边缘检测并输出显示
Canny(cameraPicture, cameraPicture, 0, 30, 3);
imshow("处理后的摄像视频", cameraPicture);
waitKey(30);//延时30毫秒
}
}
OpenCV学习系列:OpenCV实现基于canny检测
最新推荐文章于 2023-07-13 16:25:33 发布