04 顯示攝影機WebCam的畫面

使用OpenCV 顯示攝影機WebCam的資料,並顯示在畫面上。

範例程式:sample03_camera
[php]
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <string.h>
#include <fstream>

using namespace cv;
int main( int argc, char** argv )
{
VideoCapture cap(0); //開啟攝影機
if(!cap.isOpened()) return -1; //確認攝影機打開
namedWindow("MyCamera",1); //建立一個視窗,名稱為MyCamera
Mat frame; //用矩陣紀錄抓取的每張frame
for(;;){
cap >> frame; //把取得的影像放置到矩陣中
imshow("MyFrame", frame); //建立一個視窗,顯示frame到camera名稱的視窗
if(waitKey(30) >= 0) break; //按鍵就離開程式
}
system("PAUSE");
return 0;
}
[/php]

Screen Shot 2014-11-23 at 12.03.36 PM

OpenCV
CH01 簡介CH02 OpenCV APICH03 繪圖CH04 應用範例CH06 haarcascadesCH06 surf和siftCH07 OCRCH09 FaceCH5 輪廓(findContours、drawContours)