您的位置:首页 > 运维架构

OpenCV之视频——将视频分割成图像

2017-03-20 10:35 309 查看
将视频分割成一帧帧的图像,并保存在指定位置:

#include <cv.h>
#include <highgui.h>
#include <iostream>
#include <string>

using namespace std;
using namespace cv;

void splitIntoFrames(string file_path) {
CvCapture *capture = cvCaptureFromFile(file_path.c_str());
if (!capture) {
cerr << "cvCaptureFromVideo failed!!" << endl;
}
IplImage* frame = NULL;
int frame_num = 0;
//char* prefix  = "F:\Research\Deep Learning\Project\Lip\images\";

while (frame = cvQueryFrame(capture)) {
frame_num++;
string curr_filename("F:\\Research\\Deep Learning\\Project\\Lip\\images\\frame_");
curr_filename += to_string(frame_num) ;
curr_filename += ".jpg";
cvSaveImage(curr_filename.c_str(), frame);
cout << "save images." << curr_filename << endl;
}
}

int main() {
cout << "split video into frames" << endl;
string file_path("F:\\Research\\Deep Learning\\Project\\Lip\\video\\video.mp4");
splitIntoFrames(file_path);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: