OpenCV C++ real-time video canny edge detection
Procedure description
// Program description: call the camera, detect the edge of the real-time video canny collected, and display it with Gaussian blur
// Operating system: Windows 10 64bit
// Development language: C++
// IDE version: Visual Studio 2019
// OpenCV version: 4.20
Code
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
VideoCapture cap(0);
while (1)
{
Mat frame; //存储每一帧图像
cap >> frame; //读取当前视频
Mat edge, grayImage; //参数定义
cvtColor(frame, grayImage, COLOR_BGR2GRAY);
//【3】先用使用 3x3内核来降噪(2*3+1=7)
blur(grayImage, edge, Size(7, 7));
//【4】运行Canny算子
Canny(edge, edge, 0, 30, 3);
//【5】显示效果图
imshow("【效果图】Canny边缘检测", edge);
if(waitKey(30)>=0) break;//延时30毫秒
}
return 0;
}