1. In cvcreatevideowriter (), the second parameter: Avi corresponds to the following encoding formats:
Cv_fourcc ('P', 'I', 'M', '1') = MPEG-1 Codec
Cv_fourcc ('M', 'J', 'P', 'G') = motion-JPEG codec (does not work well)
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
Changing-1 will open a encoder selection window.
2, video grayscale write (to: http://www.pengjun.org.cn/post/22.html)
The blue code shows the video.
========================================================== ==================================
# Include <cv. h>
# Include
Int main (INT argc, char * argv [])
{
// Exit the program if the input parameter is not 3
If (argc! = 3) Return-1;
// Create a cvcapture * Type Variable
Cvcapture * capture = NULL;
// Use the cvcreatefilecapture function to read a video file from the first input parameter
Capture = cvcreatefilecapture (argv [1]);
// Exit the program if the video file fails to be read.
If (! Capture) Return-1;
// Use the cvqueryframe function to obtain the first frame of the video file and save it to bgr_frame.
Iplimage * bgr_frame = cvqueryframe (capture );
// Use the cvgetcaptureproperty function to obtain the Frame Rate of the video file, so that the frame rate of the input video is consistent with that of the video file.
Double FPS = cvgetcaptureproperty (capture, cv_cap_prop_fps );
// Use the cvsize function to create a cvsize variable with the same width and height as the input video file.
Cvsize size = cvsize (INT) cvgetcaptureproperty (capture, cv_cap_prop_frame_width ),
(INT) cvgetcaptureproperty (capture, cv_cap_prop_frame_height ));
// Use the cvcreatevideowriter function to create a cvvideowriter * type variable to output video files.
Cvvideowriter * Writer = cvcreatevideowriter (argv [2], cv_fourcc ('M', 'J', 'P', 'G '),
FPS, size );
Cvnamedwindow ("mainwin", cv_window_autosize); // create a window to display the modified video;
// Use the cvcreateimage function to create an iplimage * type variable logpolar_frame
Iplimage * logpolar_grame = cvcreateimage (size, ipl_depth_8u, 3 );
// Use the cvqueryframe function to continue reading the input video file until the end of the file.
While (bgr_frame = cvqueryframe (capture ))! = NULL)
{
// Map the image to the polar index space using the cvlogpolar Function
Cvlogpolar (bgr_frame, logpolar_grame, cvpoint2d32f (bgr_frame-> width/2,
Bgr_frame-> height/2), 40, cv_inter_linear + cv_warp_fill_outliers );
// Use the cvwriteframe function to save the image of the polar index space to the writer.
Cvwriteframe (writer, logpolar_frame );
Cvshowimage ("mainwin", logpolar_frame); // The generated video is displayed in the mainwin window;
Char c = cvwaitkey (33 );
If (C = 27) break; // exit the window when the ESC key is entered;
}
// After conversion, use the cvreleasevideowriter function to release the memory space occupied by the cvvideowriter * type variables
Cvreleasevideowriter (& writer );
// Use the cvreleaseimage function to release the memory occupied by iplimage * type variables
Cvreleaseimage (& logpolar_frame );
// Use the cvreleasecapture function to release the memory space occupied by cvcapture * type variables
Cvreleasecapture (& capture );
// When the program ends, 0 is returned.
Return 0;
}
Remember:
1. Use the cvcreatevideowriter function to create a video file writer. The specific parameters are as follows:
Cvvideowriter * cvcreatevideowriter (const char * filename, int fourcc, double FPS,
Cvsize frame_size, int is_color = 1 );
Filename: name of the output video file.
Fourcc: four characters are used to indicate the codec of the compressed frame. For example, cv_fourcc ('P', 'I', 'M', '1') is the MPEG-1 codec,
Cv_fourcc ('M', 'J', 'P', and 'G') is motion-JPEG codec.
In Win32, if-1 is input, you can select the compression method and parameters from a dialog box.
FPS: The Frame Rate of the created video stream.
Frame_size: the video stream size.
Is_color: If it is non-zero, the encoder will want to get the color frame and encode it; otherwise, it is a grayscale frame (this flag is supported only in Windows ).
2. Use the cvlogpolar function to map the image to the polar index space (similar to polar coordinates, but the abscissa is the value after log removal ). Specific parameters:
Void cvlogpolar (const cvarr * SRC, cvarr * DST,
Cvpoint2d32f center, double m,
Int flags = cv_inter_linear + cv_warp_fill_outliers );
SRC: input image.
DST: output image.
Center: the center of the transformation. The output image is the most accurate here.
M: The scale parameter of the amplitude. See the following formula:
ROV = m * log (SQRT (X2 + y2 ))
Phi = atan (y/X)
Flags: the combination of the interpolation method and the following selection marks;
Cv_warp_fill_outliers-fill all pixels in the output image. If these vertices correspond to the outer vertices, set them to zero.
Cv_warp_inverse_map-indicates the inverse transformation from the output image to the input image, and therefore can be directly used for pixel interpolation. Otherwise, the function looks for Inverse transformations from map_matrix.
Fillval: used to fill the value of an external vertex.
The function cvlogpolar transforms the input image using the following transform:
Positive transformation (cv_warp_inverse_map not set): DST (PHI, rock) <-Src (x, y)
Inverse Transformation (cv_warp_inverse_map): DST (x, y) <-Src (PHI, rock ),
This function imitates the central concave visual acuity of human retina, and can be used for rapid scaling and constant rotation transformation template matching for target tracking.
3. Use the cvpoint2d32f function to create a point in two-dimensional coordinates. Its type is floating point. Its definition is as follows:
Typedef struct cvpoint2d32f
{
Float X;/* x coordinate, usually based on 0 */
Float y;/* Y coordinate, usually based on 0 */
}
Cvpoint2d32f;
/* Constructor */
Inline cvpoint2d32f cvpoint2d32f (Double X, Double Y );
/* Convert from cvpoint */
Inline cvpoint2d32f cvpointto32f (cvpoint point );
4. Use the cvwriteframe function to write an image to the video file writer.
5. Use cvreleasevideowriter to release the memory space occupied by the video writer.