#include <iostream>
#include <vector>
#include "opencv2\highgui\highgui.hpp"
using namespace std;
using namespace cv;
void video2image(string video,string path)
{
VideoCapture capture(video);
if(!capture.isOpened())
{
cerr<<"Failed to open a video"<<endl;
return ;
}
Mat frame;
int num=1;
string filename;
char temp_file[5];
for(;;)
{
capture>>frame;
if(frame.empty())
break;
sprintf(temp_file,"%06d",num);//每张图片前缀由六个字符构成,不够六个字符的前面用0补完整
filename = temp_file;
cout<<temp_file<<endl;
filename = path+filename+".jpg";
num++;
imwrite(filename,frame);
}
capture.release();
}
//假定图像集已经按帧号顺序排列
void images2video(string _Imagespath,string &_videoTosave)
{
int numframes = 120; //需要合成视频的帧数
int fourcc = CV_FOURCC('D','I','V','X'); //编解码类型
double fps = 30;
bool iscol
C++ 视频转换成图片
最新推荐文章于 2024-07-10 22:49:54 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)