#include<opencv2/opencv.hpp>
using namespace cv;intmain(){
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;}return0;}
使用图片进行边缘检测(需要将文中的路径改为自己的路径)
#include<opencv2/opencv.hpp>
using namespace cv;intmain(){
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);return0;}
电脑连接摄像头即可,或者将摄像头改为图片也可进行边缘检测。#include <opencv2/opencv.hpp>using namespace cv;int main(){ VideoCapture capture(0); Mat edges; while (1) { Mat frame; ca...