一、流程图
二、源代码
/************************************************************************ * @ Creator:OYXL * @ Project Creation time:2018/5/22 * @ Function:从文件中获取视频分解成图片 ************************************************************************/ #include<opencv2/opencv.hpp> #include "iostream" using namespace cv; using namespace std; int main() { Mat frame; char outfile[50]; VideoCapture cap("F:\\磊神视频\\Glasses.avi"); if(!cap.isOpened()) { cout<<"打开视频失败!"<<endl; return -1; } int totalFrame=cap.get(CV_CAP_PROP_FRAME_COUNT);//<获取视频总帧数 for (int i = 1; i <=totalFrame; i++) { cap>>frame; if (frame.empty()) { cout<<"图片为空!"<<endl; break; } sprintf(outfile,"E://pic//%d.png",i); imwrite(outfile,frame); imshow("video",frame); waitKey(15); } cap.release(); destroyAllWindows(); return 0; }
三、效果图
代码是根据进击的小猴子的博客修改的,挺有意思的。