Configuration:
opencv3.2
VS2017
WINDOWS10 download OpenCV and add path path to configure specific web on vs. many examples are good.
You can see the http://blog.csdn.net/poem_qianmo/article/details/19809337/.
2. The Code section
GetApictureOfVideos.cpp: Defines the entry point for a console application. #include "stdafx.h" #include "string" #include <iostream>//io stream cout #include <OPENCV2/HIGHGUI/HIGHGUI.HPP&G
t;//Add this sentence without error stating that the installation configuration was successful #include <time.h> using namespace std;
using namespace CV;
void Video_to_image (string filename) {videocapture capture (filename);//Get Videocapture Object if (!capture.isopened ())
{cout << "open video Error";
//capture.get is very powerful to get a lot of information about frames int frame_width = (int) capture.get (cap_prop_frame_width);
int frame_height = (int) capture.get (cap_prop_frame_height);
int frame_number = Capture.get (Cap_prop_frame_count);
cout << "Frame_width is" << frame_width << Endl;
cout << "Frame_height is" << frame_height << Endl;
cout << "Frame_number is" << frame_number << Endl; Srand ((unsigned) time (NULL)), #时间点 long Frametostart = rand ()% Frame_number; #取 random number within the maximum number of frames cout << "where frame Begins" &l t;< FRAmetostart << Endl; Capture.set (Cap_prop_pos_frames, frametostart); get frame Mat frames from the number of frames at this point;
#Mat对象 is actually the image object Char image_name[20];
if (!capture.read (frame)) {cout << read video failure << Endl; } imshow ("Che", frame);//Display sprintf (image_name, "%s%s", "image", ". jpg");//Saved picture name Imwrite (image_name, frame);
Write in front is path+name don't forget suffix is frame capture.release (); #释放对象} int main () {string filename = "F:/1.mp4";
Video_to_image (filename);
Waitkey (0);
return 0;
}