The essential
A parameter in the resolution of the resolution of the image itself, instead of specifying the video resolution generated. If you want to modify the resolution, or post-processing software, either in image when resize
2 To quit normal, do not force quit.
3 is generated only avi format.
#include <iostream> #include <string> #include "opencv2/highgui/highgui.hpp" #include "opencv2/core/core.hpp" #include "opencv2/opencv.hpp" using namespace std; using namespace cv; void Video_To_Image(string filename); void Image_To_Video(); int imagetovideo(); int main() { //string video_name = "test.avi";//注意,使用string时,若不用using namespace std,需要使用std::string //Video_To_Image(video_name); Image_To_Video(); //imagetovideo(); return 0; } void Video_To_Image(string filename) { cout << "---------------Video_To_Image-----------------" << endl; Capture :: VideoCapture CV (filename); if (!capture.isOpened()) { COUT << "Open Video error"; } / * CV_CAP_PROP_POS_MSEC - the current position of the video (in milliseconds) CV_CAP_PROP_POS_FRAMES - the current position of the video (frame) CV_CAP_PROP_FRAME_WIDTH - width of the video stream CV_CAP_PROP_FRAME_HEIGHT - video stream height CV_CAP_PROP_FPS - frame rate (frames / sec) * / int frame_width = (int) capture.get (CV_CAP_PROP_FRAME_WIDTH); int FRAME_HEIGHT = (int) capture.get (CV_CAP_PROP_FRAME_HEIGHT); a float frame_fps = capture.get (CV_CAP_PROP_FPS); int Frame_Number = capture.get (CV_CAP_PROP_FRAME_COUNT); // total number of frames COUT << "frame_width IS" << endl << frame_width; COUT << "FRAME_HEIGHT IS" << endl << FRAME_HEIGHT; COUT << "frame_fps is " << frame_fps << endl; int num = 0; // count the number of frames cv :: Mat img; String img_name; char image_name [20 is]; CV :: namedWindow ( "MyVideo", CV_WINDOW_AUTOSIZE); the while (to true) { CV :: Mat Frame; // read from a video frame BOOL bSuccess capture.read = (frame); IF (! bSuccess) { COUT << "video files can not be read from the frame" << endl; BREAK; } // displaying the current frame on the window MyVideo imshow ( "MyVideo" , Frame); // save the image name // sprintf (const_cast <char *> (img_name.data ()), "% s% d% s", "image", ++ num, ".jpg"); // save the image name sprintf (image_name, "% s% d% s", "image", ++ num, ".jpg"); // save the image name img_name = image_name; imwrite (img_name, frame); // save to save a picture IF (CV ::waitKey (30) == == 27 || NUM Frame_Number) { COUT << "Press ESC" << endl; BREAK; } } capture.release (); // this sentence need not seemingly } void Image_To_Video () { COUT << "------ --------------- Video_To_Image ----------- "<< endl; String s_image_name; CV :: VideoWriter Writer; int isColor = 1; // do not know is doing with int frame_fps = 25; int frame_width = 1920; / / must be true image resolution, which is not specified resolution of generated video int FRAME_HEIGHT = 1080; String video_name = "out.avi"; // CV_FOURCC ( 'M', 'J', 'P', 'G' ) CV_FOURCC ( 'D', 'the I', 'V', 'X-') COUT << "FRAME_HEIGHT IS" <<frame_height << endl; cout << "frame_fps is " << frame_fps << endl; Writer = VideoWriter (video_name, CV_FOURCC ( 'D', 'I', 'V', 'X'), frame_fps, Size(frame_width, frame_height), isColor); << cout "frame_width IS" << endl << frame_width; CV :: namedWindow ( "Image to Video", CV_WINDOW_AUTOSIZE); int NUM = 50; // Enter the total number of sheets of pictures int i = 1; Mat img; IF (! writer.isOpened ()) { COUT << "Error: Fail to Open Video Writer \ n-" << endl; return; } the while (I <= NUM) { String path = "F.: / dongdong / learning materials. 1 / paper 1/2 released / dense tracking / latest paper / Code / data 0 / optical flow tracking / Result / test2 / 2GUI / 1 / "; s_image_name the to_string :: = path STD + (I ++) +" .jpg "; img = imread (s_image_name); // read into the picture if (! img.data) // determine whether the images transferred successfully { cout << "Could not the Load Image File ... \ the n-" << endl; break; } //imshow(); // write writer << img; imshow("image to video", img); waitKey(1); if (cv::waitKey(30) == 27 || i == num) { cout << "按下ESC键" << endl; cvReleaseVideoWriter; break; } } cvReleaseVideoWriter; }