3. Write AVI video File

Source: Internet
Author: User

Create a write device to write the video stream to a video file frame by frames, implemented with function Cvcreatevideowriter (). When the output device is created, call Cvwriterframe () to write the video stream to the file frame-wise. Finally, call Cvreleasevideowriter () to release the resource.

Functions involved:

1 iplimage* cvqueryframe (cvcapture* capture);

Grab a frame from the camera or file and return the frame, the returned image can not be modified or released by the user. Cvqueryframe uses memory that has already been allocated in the cvcapture structure.

1 Const Char int Double int is_color=1 );

Create a video writer.

FileName: The output file name.

FOURCC: Four characters used to represent the codec of a compressed frame.

CV_FOURCC (' P ', ' I ', ' M ', ' 1 ') = MPEG-1 codec

CV_FOURCC (' M ', ' J ', ' P ', ' G ') = Motion-jpeg codec

CV_FOURCC (' M ', ' P ', ' 4 ', ' 2 ') = MPEG-4.2 codec

CV_FOURCC (' D ', ' I ', ' V ', ' 3 ') = MPEG-4.3 codec

CV_FOURCC (' D ', ' I ', ' V ', ' X ') = MPEG-4 codec

CV_FOURCC (' U ', ' 2 ', ' 6 ', ' 3 ') = H263 codec

CV_FOURCC (' I ', ' 2 ', ' 6 ', ' 3 ') = H263i codec

CV_FOURCC (' F ', ' L ', ' V ', ' 1 ') = FLV1 codec

If the encoder code is-1, an encoder selection box pops up at run time.

FPS: The frame rate of the video stream being created.

Frame_size: The size of the video stream.

Is_color: If nonzero, the encoder will want to get a colored frame and encode it, otherwise it is a grayscale frame.

1 void Const Double int flags=cv_inter_linear+cv_warp_fill_outliers);

Map images to polar exponential space

SRC: Input image

DST: Output image

Center: Transform Centers

M: Scale parameter of amplitude

Flags: Interpolation method and the combination of the following selection flags

Cv_warp_fill_outliers-fills the output image with all pixels, or zero if the points have corresponding to the outer points.

Cv_warp_inverse_map-Represents the inverse transformation of the matrix from the output image to the input image, and can therefore be used directly for pixel interpolation. Otherwise, the function looks for inverse transformations from the Map_matrix.

The fillval is used to fill the value of the outer point.

The function cvlogpolar the input image with the following transformation transformation:

Positive transform (Cv_warp_inverse_map not placed):

DST (Phi,rho) <-src (x, y)

Inverse transform (CV_WARP_INVERSE_MAP):

DST (x, y) <-src (Phi,rho),

Over here

Rho=m * Log (sqrt (x^2+y^2))

Phi=atan (y/x)

This function mimics the central concave vision of the human retina and can be used for fast scale and rotational transformation invariant template matching for target tracking.

Sample program:

1#include"cv.h"2#include"highgui.h"3 4 intMainintargcChar**argv)5 {6     //open a video file7cvcapture* capture = Cvcreatefilecapture ("E:\\test.avi");8 9     //If the file does not exist, exitTen     if(!capture) One         return-1; A  -     //grab a frame from a video file -iplimage* Bgr_frame =Cvqueryframe (capture); the  -     //get the number of frames to prepare to create a write device -     Doublefps =Cvgetcaptureproperty ( - capture, + Cv_cap_prop_fps -         ); +  A     //get the dimensions of each frame atCvsize size =Cvsize ( -(int) Cvgetcaptureproperty (capture,cv_cap_prop_frame_width), -(int) Cvgetcaptureproperty (capture,cv_cap_prop_frame_height) -         ); -  -     //creating a Write device incvvideowriter* writer =Cvcreatevideowriter ( -             "E:\\out.avi", toCV_FOURCC ('M','J','P','G'), + fps, - size, the             1 *         ); $ Panax Notoginseng     //Create a Write frame -iplimage* Logopolar_frame =Cvcreateimage ( the size, + ipl_depth_8u, A             3 the         ); +  -     /*If there are still frames to crawl, go into the loop.  $ Map the original frame to the polar exponential space and write to the video write device $     */ -      while(Bgr_frame=cvqueryframe (capture))! =NULL) -     { the Cvlogpolar ( - Bgr_frame,Wuyi Logopolar_frame, thecvpoint2d32f (bgr_frame->width/2, bgr_frame->height/2), -                  +, Wucv_inter_linear+cv_warp_fill_outliers -             ); About Cvwriteframe (writer, logopolar_frame); $     } -  -     //Freeing Memory -Cvreleasevideowriter (&writer); ACvreleaseimage (&bgr_frame); +Cvreleasecapture (&capture); the  -     return 0; $}

3. Write AVI video File

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.