opencv将frame帧保存为视频

#include "opnecv2/opencv.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
    int c=0;
    VideoCapture cap(c);//调用摄像头,如果有多个摄像头,可以调整c(0,1,2,...)来选择到你想要的摄像头,
    if (!cap.isOpened())
    {
        return -1;
    }
    bool stop = false;
    int a = 0;
    //设置视频编写器
    VideoWriter write;
    string outVideo = "Show_Example.avi";
    int fps = 30;//帧率double fps=cap.get(CV_CAP_PROP_FPS);但是我调用该函数返回的是0
    int height = static_cast<int>(cap.get(CV_CAP_PROP_FRAME_HEIGHT));//读取视频的高度
    int width = static_cast<int>(cap.get(CV_CAP_PROP_FRAME_WIDTH));//读取视频的宽度
    //目前opencv对保存视频的支持格式不是很多,我尝试了很多种,后面有格式和编码方式的补充。我这里使用的是.avi格式,编码方式选择XVID
    write.open(outVideo, CV_FOURCC('X','V','I','D'), fps, Size(width, height), true);
    while (!stop)
    {
        Mat frame;
        cap >> frame;
        blur(frame,frame,Size(3,3),Point(-1,-1));
        imshow("当前视频", frame);
        write.write(frame);
        if (waitKey(30) >= 0)
            stop = true;
    }
    return 1;
}

 

  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值