• 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"
  • 相关阅读:
    截取url中最后斜杆的文件名
    html span从上往下,从左往右排序
    浪漫源码记录
    微信小程序TypeError: Cannot read property 'elem' of undefined
    tomcat8 性能优化
    Bandicam神奇使用法
    DataStage 七、在DS中使用配置文件分配资源
    DataStage 六、安装和部署集群环境
    DataStage 错误集(持续更新)
    DataStage 三、配置ODBC
  • 原文地址:https://www.cnblogs.com/Vince-Wu/p/11182420.html
Copyright © 2020-2023  润新知