OpenCv 012---视频文件读写

1 前备知识

null

2 所用到的主要OpenCv Class

VideoCapture capture;
    capture.open("G:\CVworkstudy\program_wwx\研习社140课时\ZhaiZhigang140\vtest.avi");
VideoWriter writer("G:\CVworkstudy\program_wwx\研习社140课时\ZhaiZhigang140\test.avi", CV_FOURCC('D', 'I', 'V', 'X'), fps, S, true);

3 程序代码

同OpenCv研习社例程代码

#include<opencv2/opencv.hpp>
#include<iostream>

using namespace cv;
using namespace std;

int main(int argc, char** argv) {
    // 打开摄像头
    // VideoCapture capture(0); 

    // 打开文件
    VideoCapture capture;
    capture.open("G:\CVworkstudy\program_wwx\研习社140课时\ZhaiZhigang140\vtest.avi");
    if (!capture.isOpened()) {
        printf("could not read this video file...
");
        return -1;
    }
    Size S = Size((int)capture.get(CV_CAP_PROP_FRAME_WIDTH),
        (int)capture.get(CV_CAP_PROP_FRAME_HEIGHT));
    int fps = capture.get(CV_CAP_PROP_FPS);
    printf("current fps : %d 
", fps);
    VideoWriter writer("G:\CVworkstudy\program_wwx\研习社140课时\ZhaiZhigang140\test.avi", CV_FOURCC('D', 'I', 'V', 'X'), fps, S, true);

    Mat frame;
    namedWindow("camera-demo", CV_WINDOW_AUTOSIZE);
    while (capture.read(frame)) {
        imshow("camera-demo", frame);
        writer.write(frame);
        char c = waitKey(50);
        if (c == 27) {
            break;
        }
    }
    capture.release();
    writer.release();
    waitKey(0);
    return 0;
}

4 运行结果

display:ignore

5 扩展及注意事项

null

One day,I will say "I did it"
原文地址:https://www.cnblogs.com/Vince-Wu/p/11182420.html