攝像頭的打開
include<opencv2/opencv.hpp>
include<cv.h>
using namespace cv;
using namespace std;
//-----------------------------------【main()函數(shù)】---------------------------------
-----------
// 描述:控制臺應用程序的入口函數(shù),我們的程序從這里開
始
//-----------------------------------------------------------------------------------------
--------
//stringname = "我的攝像頭";
int main()
{
//【1】從攝像頭讀入視頻
VideoCapture capture(0);//若測試攝像頭有沒有打開,/*if(!capture.isOpened()) {cout<< "cannot open the camera.";cin.get();return -1;}*
Mat edges; //定義一個Mat變量,用于存儲每一幀的圖像
//【2】循環(huán)顯示每一幀
while (1)
{
Mat frame; //定義一個Mat變量,用于存儲每一幀的圖像
capture >> frame; //讀取當前幀
if (frame.empty())
{
printf("--(!) No captured frame -- Break!");
//break;
}
else
{
cvtColor(frame, edges, CV_BGR2GRAY);//彩色轉(zhuǎn)換成灰度
blur(edges, edges, Size(7, 7));//模糊化
Canny(edges, edges, 0, 30, 3);//邊緣化
imshow("讀取被邊緣后的視頻", frame); //顯示當前幀
}
waitKey(30); //延時30ms
}
return 0;
}