操作视频-对视频进行canny边缘检测

#include<opencv2/opencv.hpp>
using namespace cv;

int main()
{
    VideoCapture capture(0);        //从摄像头读入视频
    Mat edges;

    while (1)
    {
        Mat frame;       //定义一个Mat变量读取当前帧
        capture >> frame;  //读取当前帧
        cvtColor(frame, edges, COLOR_BGR2GRAY);  //转化为灰度图
        blur(edges, edges, Size(7, 7));   //均值模糊
        Canny(edges, edges, 0, 30, 3);    //进行canny边缘检测
        imshow("读取摄像头", edges);
        waitKey(30);
    }
    return 0;
}

显示效果:

posted @ 2018-09-11 13:18  RamboBai  阅读(704)  评论(0编辑  收藏  举报