嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在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;
}