日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

opencv图片处理和摄像头边缘检测

發布時間:2025/4/5 编程问答 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 opencv图片处理和摄像头边缘检测 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

腐蝕

結果

代碼
erode函數

#include "pch.h" #include <iostream> #include<opencv2/opencv.hpp> #include <opencv2/highgui/highgui.hpp>//Opencv highgui 模塊頭文件 #include<opencv2/imgproc/imgproc.hpp>//圖像處理頭文件 using namespace cv;int main(){//功能一。進行腐蝕操作Mat srcImage = imread("cat15.jpg",2|4);//loading pictureimshow("原始圖", srcImage);//show picturewaitKey(0);//按鍵Mat element = getStructuringElement(MORPH_RECT,Size(15,15));Mat dstImage;erode(srcImage,dstImage,element);imshow("效果圖",dstImage);waitKey(0);//wait for any keyreturn 0; }

圖像模糊

結果

代碼
均值濾波blur()函數的使用

#include "pch.h" #include <iostream> #include<opencv2/opencv.hpp> #include <opencv2/highgui/highgui.hpp>//Opencv highgui 模塊頭文件 #include<opencv2/imgproc/imgproc.hpp>//圖像處理頭文件 using namespace cv;int main(){//功能二:圖像模糊Mat srcImage = imread("catandmao.jpg");imshow("均值濾波原始圖",srcImage);Mat dstImage;blur(srcImage,dstImage,Size(7,7));imshow("均值濾波效果圖",dstImage);waitKey(0); }

邊緣檢測

結果

代碼
canny算子

#include "pch.h" #include <iostream> #include<opencv2/opencv.hpp> #include <opencv2/highgui/highgui.hpp>//Opencv highgui 模塊頭文件 #include<opencv2/imgproc/imgproc.hpp>//圖像處理頭文件 using namespace cv;int main(){//功能三練習。canny 邊緣檢測Mat srcImage = imread("catandmao.jpg");imshow("原始圖",srcImage);Mat edge, greyImage;//將原圖轉化為灰度圖像cvtColor(srcImage,greyImage,CV_BGR2GRAY);//使用3*3內核來降噪blur(greyImage,edge,Size(3,3));//運行canny算子Canny(edge, edge, 3, 9, 3);//顯示效果圖imshow("邊緣檢測,效果圖",edge);waitKey(0);}

視頻顯示

讀取并播放視頻
代碼

#include "pch.h" #include <iostream> #include<opencv2/opencv.hpp> #include <opencv2/highgui/highgui.hpp>//Opencv highgui 模塊頭文件 #include<opencv2/imgproc/imgproc.hpp>//圖像處理頭文件 using namespace cv;int main(){VideoCapture capture("H:\\how.mp4");//需要使用兩個反斜杠while (1){Mat frame;//定義一個Mat變量,用于存儲每一幀的圖像capture >> frame;//讀取當前幀imshow("讀取視頻",frame);waitKey(30);}}

打開攝像頭

代碼

#include "pch.h" #include <iostream> #include<opencv2/opencv.hpp> #include <opencv2/highgui/highgui.hpp>//Opencv highgui 模塊頭文件 #include<opencv2/imgproc/imgproc.hpp>//圖像處理頭文件 using namespace cv; int main(){//功能五:攝像頭采集VideoCapture capture(0);while (1){Mat frame;//定義一個Mat變量,用于存儲每一幀的圖像capture >> frame;//讀取當前幀imshow("讀取視頻", frame);waitKey(30);} }

攝像頭配合邊緣檢測

結果
代碼

#include "pch.h" #include <iostream> #include<opencv2/opencv.hpp> #include <opencv2/highgui/highgui.hpp>//Opencv highgui 模塊頭文件 #include<opencv2/imgproc/imgproc.hpp>//圖像處理頭文件 using namespace cv; int main(){//功能五:攝像頭配合canny邊緣檢測VideoCapture capture(0);Mat edges;while (true){Mat frame;capture >> frame;cvtColor(frame, edges, CV_BGR2GRAY);blur(edges,edges,Size(7,7));Canny(edges, edges, 0, 30, 3);imshow("canny邊緣化之后的視頻", edges);if (waitKey(30) >= 0)break;}return 0; }

注:以上基于x64,debug模式

總結

以上是生活随笔為你收集整理的opencv图片处理和摄像头边缘检测的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。