#include <opencv2/opencv.hpp>
#include <tchar.h>
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <ostream>
using namespace std;
using namespace cv;
void main()
{
//类VideoCapture实例化再初始化
//VideoCapture capture;
//capture.open("Megamind.avi");
//类VideoCapture实例化的同时初始化
VideoCapture capture("1.mp4");
if (!capture.isOpened())
{
return;
}
int imgIndex = 0;
for (;;)
{
Mat frame;
capture >> frame;
if (frame.empty())
{
break;
}
char* imageSaveName = new char[200];
//将图片的路径及名称输入到imageSaveName中
sprintf(imageSaveName, "%05d.jpg", imgIndex);
//将每一帧图像frame保存到imageSaveName指定的文件中
//4表示每隔四帧进行保存
if(imgIndex%4==0)
{
imwrite(imageSaveName, frame);
}
delete[] imageSaveName;
imgIndex++;
}
int i;
i = int(imgIndex / 4);
cout << "total frames: " << i << endl;
}
//转载https://blog.csdn.net/weixin_38621214/article/details/77200528