"Opencv2" Operation of the video

Source: Internet
Author: User

Opencv2 , provides two video operation related classes,videocapture and videowriter, of course, there are corresponding constructors.

For videocapture, there are several operation functions:

Open (const string &filename)// opening video file

Open (int device)// turn on camera, device is serial number

Isopened ()// determine if the video file or camera is open and its return value is bool type

Release ()// close video file or webcam

Grab ()// Gets the video or camera next frame, if successful, returns TRUE, and its function type is bool type.

Retrieve (mat& image, int channel= ())// decodes a frame image that has just been acquired and assigns it to Image, the return value of this function is also bool type.

Read (mat& image)// gets, decodes, and reads the next frame of the video. In OpenCV , it overloads the function with the ">>" operator, which is the video >> image

Get (int propid)// return properties of the video

Propid values are different, the returned properties are also different. when propid takes the following values:

Cv_cap_prop_pos_msec the location of the current video file in milliseconds or timestamps

Cv_cap_prop_pos_frames capturing index with 0 -start video frame decoding

Cv_cap_prop_pos_avi_ratio Video relative position,0 for start,1 for end

Cv_cap_prop_frame_width The width of the video frame picture

Cv_cap_prop_frame_height The height of the video frame picture

Cv_cap_prop_fps Frame rate

CV_CAP_PROP_FOURCC Four-character code for video

total number of frames in Cv_cap_prop_frame_count video

picture format for Cv_cap_prop_format video

Cv_cap_prop_mode back-end specific values indicate the current capture mode

The following properties are only valid in camera mode:

Cv_cap_prop_brightness The brightness of the image

Cv_cap_prop_contrast Image Contrast Ratio

saturation of the cv_cap_prop_saturation image

chroma of Cv_cap_prop_hue image

exposure of cv_cap_prop_exposure images

Cv_cap_prop_convert_rgb whether the image is converted to an RGB type

Set (int propid)// Sets the property with the same value as the get function for the parameter

For Videowriter, there are several operation functions:

Open (const string &filename, int FourCC, double fps, Size framesize, color = True)

Several of the above parameters have been described above.

Isopened ()// with the front is a meaning

This function is also overloaded in the write (const mat& image)//opencv, with the operator <<

The following section of the program, the function of the program is to make a segment of the video smaller, that is, the original 1024*780 video, into 320*280, in order to use a few video operation functions, So some places can be greatly simplified or modified I have not modified, in order to show the use of various functions.

#include "opencv2/objdetect/objdetect.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/ Imgproc.hpp "#include <opencv2/opencv.hpp> #include <iostream> #include <stdio.h>using namespace std ; using namespace Cv;int main (int argc, const char** argv) {Mat frame; Videocapture video;   Videowriter newvideo;double FourCC, fps, width, height;video.open ("25.avi"); Open Video FOURCC = Video.get (CV_CAP_PROP_FOURCC); fps = Video.get (cv_cap_prop_fps); width = Video.get (cv_cap_prop_frame_width); height = Video.get (cv_cap_prop_frame_  HEIGHT); Get some parameters for the video//create a new video Markvideo.open ("Markvideo10.avi", FourCC, fps); if (video.isopened () &&  Markvideo.isopened ()) {while (true) {video >> frame;  Read each frame of the video resize (frame, frame, Size (320, 280)); Zoom out every frame of the video if (!frame.empty ()) {Markvideo << frame;//each frame is written into a new video}else{printf ("-(!) No captured Frame--break! "); break;} if (char) waitkey (1) = = ' C ') {video.release (); Markvideo.release (); break;}}} return 0;}


"Opencv2" Operation of the video

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.