// opencv6_videocapturefromcamera.cpp : 此文件包含 "main" 函數。程序執行將在此處開始並結束。
//
#include <iostream>
//#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/imgproc.hpp>
using namespace cv;
using namespace std;
//debug下在lib文件的名稱後加d,release下不加d。
int main()
{
VideoCapture capture(0); // 0爲電腦自帶攝像頭
/*capture.open(0);*/
if (capture.isOpened())
{
cout << "已打開攝像頭" << endl;
}
else
{
cout << "攝像頭打開失敗" << endl;
}
while (1)
{
Mat frame;
capture >> frame; //讀取當前幀
if (frame.data == NULL)
break;
imshow("讀取視頻的當前幀", frame);
Mat edges;
cvtColor(frame, edges, COLOR_BGR2GRAY); //轉爲灰圖
blur(edges, edges, Size(8, 8)); //降噪
Canny(edges, edges, 3, 9, 3); //邊緣檢測
imshow("邊緣檢測效果", edges);
if (waitKey(30) >= 0)
break;
}
capture.release();
return 0;
}
opencv從攝像頭獲取圖片幀並做邊緣檢測
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.