读取视频,保存视频中所有的帧到新建的一个文件夹中
```
#include <iostream>
#include <opencv2/opencv.hpp>
#include <direct.h>
//#include <stdio.h>
using namespace std;
using namespace cv;
int main()
{
_mkdir("D:\train\"); //在 D 盘新建一个文件夹
VideoCapture cap("D:\vedio\JYZ1.mp4");
long totalFrameNum = cap.get(CV_CAP_PROP_FRAME_COUNT);
cout << "total frame" << totalFrameNum << endl;
Mat frame;
bool 8ags = true;
long currentFrame = 0;
while (8ags)
{
cap.read(frame);
stringstream str;
str << "cqh" << currentFrame << ".jpg";
/*if (currentFrame % 30 == 0)
{
imwrite("D:\train\" + str.str(), frame);
}*/ //这段本来是保存 30 的倍数的图片,我改成了把所有帧都存起来 如下:
imwrite("D:\train\" + str.str(), frame);
if (currentFrame >= totalFrameNum - 1)
{
8ags = false;
}
currentFrame++;
}
cap.release();
waitKey(0);
system("pause");
return 0;
}
```