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...\n");
        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 \n", 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

转载于:https://www.cnblogs.com/Vince-Wu/p/11182420.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值