1-1打開相機
程式說明:
   OpenCV中打開相機很容易,主要利用 cv::VideoCapture 創立一個物件,
   a. cv::VideoCapture 物件的constructor常用有兩種型式,一個是開啟攝像頭,一個是開啟影片:
       1. 開啟攝像頭  VideoCapture::VideoCapture(int device);
  
          device: 為輸入的設備(如果只有一隻,輸入0即可)
       2. 開啟影片 VideoCapture::VideoCapture(const string& filename); 
          filename: 為輸入的影片名稱,例如 xxx.avi
 
運行結果:
範例程式:
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
 int main(int argc, char** argv)
 {
      cv::VideoCapture webCam(0);  // 宣告OpenCV中管理相機的物件 
 
      if (!webCam.isOpened())
         return -1;
 
    	char key = 'i';
    	cv::namedWindow("Image");
 
    	while (key != 'o')
    	{
       		cv::Mat imgFrame;
       		webCam >> imgFrame;
 
       		cv::imshow("Image", imgFrame);
 
		
       		key = cv::waitKey(30);
    	}
 
    	return 0;
 }