将视频每帧保存成图像
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
void ExtractFrames(const string& videoName, const string& imagePath, const string& imagePrefix)
{
VideoCapture cap;
Mat img;
cap.open(videoName);
if (!cap.isOpened())
{
cout << "Error : could not load video" << endl;
exit(-1);
}
size_t count = (size_t)cap.get(CAP_PROP_FRAME_COUNT);
for (size_t i = 0; i < count; ++i)
{
cap >> img;
string imgName = imagePath + "/" + imagePrefix + to_string(i) + ".jpg";
imwrite(imgName, img);
cout << "Frames " << i << " ... done" << endl;
}
}
int main(int argc, char* argv[])
{
ExtractFrames("C:/Users/Shy/Desktop/新建文件夹 (2)/李鹏程.avi", "F:/人脸图片/lipengcheng", "lipengcheng");
return 0;
}