从视频读图像按照数字编号增加写入硬盘
void makeImagePath(const string &path, int index, string &imagePath)
{
char s[32];
sprintf(s, "%d", index);
imagePath = path + s + string(".jpg");
}
void getImagesFromVideo(const string &videofilename, const string &savepath,int initNum)
{
cv::VideoCapture cap(videofilename);
int index = initNum;
while (cap.isOpened())
{
Mat img;
cap >> img;
if (img.empty()||img.cols == 0 || img.rows == 0||img.data==NULL)
{
break;
}
string imagePath;
makeImagePath(savepath, index++, imagePath);
cout << imagePath << endl;
imwrite(imagePath, img);
imshow("img", img);
waitKey(1);
}
}