Duanxx opencv learning: Converting videos into images

Source: Internet
Author: User

Read a video and save each frame of the video as a PNG image,

Download the code in this article

The first problem to be solved here is to generate a name for the image by Subscript:

This function counts the image frames in the video and outputs the file name, which is saved in PNG format.

Example: f00005.png

String namegenerate (unsigned int framecounter) {unsigned int num = num2str1 (framecounter ). length (); // <obtain the number of digits assert (Num <= 5); // <The value cannot exceed 5 digits string temp = ". \ image \ f "; // <save in. in the/image folder, the file name prefix is ffor (INT I = 0; I <5-num; I ++) {temp + = "0 "; /// <add zero before} temp + = num2str1 (framecounter) + ". PNG "; // <Add the PNG file name return temp ;}

Main Code for converting a video into an image:

/// <Select to read the video videocapture video (video_file_07); If (! Video. isopened () {cout <"Open failed! "<Endl; Return-1 ;}/// <obtain part of the video's parameter int width = 0, Height = 0, FPS = 0, fourcc = 0; width = static_cast <int> (video. get (cv_cap_prop_frame_width); Height = static_cast <int> (video. get (cv_cap_prop_frame_height); FPS = static_cast <int> (video. get (cv_cap_prop_fps); fourcc = static_cast <int> (video. get (cv_cap_prop_fourcc); cout <"input video: (" <width <"X" 

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.