09 錄影

screen-shot-2016-11-26-at-9-05-46-pm

#include <cstdio>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(){
    VideoCapture capture(0);
    if(!capture.isOpened()){
        return -1;
    }
    /*
    int fps = 15;
    //capSize = (1028,720) # this is the size of my source video
    fourcc = cv2.cv.CV_FOURCC('m', 'p', '4', 'v');
    //self.vout = cv2.VideoWriter();
    success = self.vout.open('/Users/powenko/Desktop/output.mov',fourcc,fps,capSize,True)
    
    */
    Size videoSize = Size((int)capture.get(CV_CAP_PROP_FRAME_WIDTH),(int)capture.get(CV_CAP_PROP_FRAME_HEIGHT));
    VideoWriter writer;
  //  writer.open("/Users/powenko/Desktop/VideoTest.avi", CV_FOURCC('m', 'p', '4', 'v'), 15, videoSize); //其他系統上使用
    writer.open("/Users/powenko/Desktop/VideoTest.mov", CV_FOURCC('m', 'p', '4', 'v'), 15, videoSize);   // MAC 可以使用
  
    
    /*
     CV_FOURCC('P', 'I', 'M', '1') = MPEG-1 codec
     CV_FOURCC('M', 'J', 'P', 'G') = motion-jpeg codec
     CV_FOURCC('M', 'P', '4', '2') = MPEG-4.2 codec
     CV_FOURCC('D', 'I', 'V', '3') = MPEG-4.3 codec
     CV_FOURCC('D', 'I', 'V', 'X') = MPEG-4 codec
     CV_FOURCC('U', '2', '6', '3') = H263 codec
     CV_FOURCC('I', '2', '6', '3') = H263I codec
     CV_FOURCC('F', 'L', 'V', '1') = FLV1 codec
     */
    namedWindow("show image",0);
    
    
    while(true){
        Mat frame;
        capture >> frame;
        if(!frame.empty()){
            writer.write(frame);
            
            //capture >> frame;
            //writer << frame;
            
            
            
            imshow("show image", frame);
            if(waitKey(33) == 27){
                break;
            }
        }
    }
    return 0;
}

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