opencv+ to get an image of a frame in a video and save it

Source: Internet
Author: User

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 &LT;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;

 }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.