OpenCV学习(二、写视频)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_30901441/article/details/75309404

opencv2.0之后可以调用VideoWriter类来写视频

opencv采集视频并保存AVI视频到本地

#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
    VideoCapture cap(0);
    //获取采集视频图像的宽和高
    Mat frame;
    cap >> frame;
    int height = frame.rows;
    int width = frame.cols;


    //规定视频文件名,编码方式,每秒帧数,视频大小
    VideoWriter writeAVI = VideoWriter("1.avi",CV_FOURCC('D','I','V','X'),25,Size(width,height));

    while(cap.isOpened())
    {
        cap >> frame;
        namedWindow("摄像头采集");
        imshow("摄像头采集",frame);

        writeAVI << frame;
        if(waitKey(20) >= 0)//延迟40ms,如果有按键则退出循环
            break;
    }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_30901441/article/details/75309404