Ubuntu18.04 opecv3.4.4 Canny()函数用于摄像头及图片边缘检测

电脑连接摄像头即可,或者将摄像头改为图片也可进行边缘检测。
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
    VideoCapture capture(0);
    Mat edges;
    while (1)
    {
        Mat frame;        
        capture>>frame;
        cvtColor(frame,edges,COLOR_BGR2GRAY);
        blur(edges,edges,Size(7,7));
        Canny(edges,edges,0,30,3);
        imshow("被canny后的视频",edges);
        if(waitKey(30)>=0) break;
    }

    return 0;

}
使用图片进行边缘检测(需要将文中的路径改为自己的路径)
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
    Mat edges;
    Mat frame;        
    frame=imread("/home/yu/Desktop/ex/2.jpg",1); 
    cvtColor(frame,edges,COLOR_BGR2GRAY);
    blur(edges,edges,Size(7,7));
    Canny(edges,edges,0,30,3);
    imshow("被canny后的图片",edges);
    waitKey(0);
    return 0;
}

发布了17 篇原创文章 · 获赞 16 · 访问量 4479

猜你喜欢

转载自blog.csdn.net/yuteng12138/article/details/97013145