#include <iostream>
#include <string>
#include <sstream>
using namespace std;
// OpenCV includes
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
using namespace cv;
int main(int argc, const char** argv)
{
// 1.創建視頻採集對象;
VideoCapture cap;
// 2.打開默認相機;
cap.open(0);
// 3.判斷相機是否打開成功;
if (!cap.isOpened())
return -1;
// 4.顯示窗口命名;
namedWindow("Video", 1);
for (;;)
{
// 獲取新的一幀;
Mat frame;
cap >> frame;
if (frame.empty())
return 0;
// 顯示新的幀;
imshow("Video", frame);
// 按鍵退出顯示;
if (waitKey(30) >= 0) break;
}
// 5.釋放視頻採集對象;
cap.release();
return 0;
}
Opencv C++ 讀取攝像頭並顯示
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.