基本信息
源码名称:视频转图片(opencv)
源码大小:1.11KB
文件格式:.cpp
开发语言:C/C++
更新时间:2019-11-11
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
使用opencv将视频转图片

#include <iostream>
#include "cv.h"
#include "opencv2/opencv.hpp"

using namespace std;
using namespace cv;

// 描述:将视频帧转成图片输出
int main()
{
    // 获取视频文件
    VideoCapture cap("D:\\qt\\opencv_example\\mouse_detection_sysu\\mouse_detection\\5-20190731_170216.mp4");

    // 获取视频总帧数
    long totalFrameNumber = cap.get(CV_CAP_PROP_FRAME_COUNT);
    cout << "total frames: " << totalFrameNumber << endl;

    Mat frame;
    bool flags = true;
    long currentFrame = 0;
    int num=201;
    while (flags){
        // 读取视频每一帧
        cap.read(frame);

        stringstream str;
        str << num << ".jpg";
        cout << "正在处理第" << currentFrame << "帧" << endl;
        printf("\n");

        // 设置每30帧获取一次帧
        if (currentFrame % 50 == 0){
            // 将帧转成图片输出
            imwrite("D:\\qt\\opencv_example\\untitled2\\images\\" str.str(), frame);
            num ;
        }
        // 结束条件
        if (currentFrame >= totalFrameNumber){
            flags = false;
        }
        currentFrame ;

    }

    return 0;
}