Duanxx opencv learning: Converting images into videos

Source: Internet
Author: User

I have explained the method and code for converting videos to images in opencv. This time, I want to explain how opencv converts images to videos:


Download the complete code in this article

1 videowriter description

Here we mainly use a class in opencv: videowriter

Its api reference link: API link.

Function prototype:

VideoWriter::VideoWriter(const string& filename, int fourcc, double fps, Size frameSize, bool isColor=true)

Parameter description:

Filename: the name of the output video file, for example, "Out. Avi"

Fourcc: it is the encoding method defined by four characters. For details about the encoding method, refer to: encoding method reference.

It should be noted that this value is defined by cv_fourcc, for example:Cv_fourcc ('P', 'I', 'M', '1') indicatesMPEG-1 Coding

FPS: Video Frame Rate

Framsize: Video size

2. The image is written into the video in two ways: 1. Call the write function 2. Stream operator <
C++: VideoWriter& VideoWriter::operator<<(const Mat& image)C++: void VideoWriter::write(const Mat& image)


3 main code example

/// <Video parameters int width = 0, Height = 0, FPS = 0, fourcc = 0; MAT frame; // <image frame int framecounter = 0; /// <image frame counter namedwindow (windows_name_original); // <read the first image to obtain the image width and height, set FPS and encoding method string framename = namegenerate (framecounter); frame = imread (framename); width = frame. cols; // <obtain the image width and height = frame. rows; FPS = 15; // <FPS is 15 fourcc = cv_fourcc ('x', 'V', 'I', 'D '); /// <set the image encoding method cout <width <Endl 

Duanxx opencv learning: Converting images into videos

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.