OpenCV camera Capture Video and save method

Source: Internet
Author: User
I. Reading a video sequence

OPENCV provides an easy-to-use framework for extracting image frames from video files and USB cameras, and if you simply want to read a video, you just need to create a cv::videocapture instance and extract each frame in the loop. Here the video is taken with the camera and saved as AVI file, the code is as follows:

#include <opencv2\highgui\highgui.hpp> #include <opencv2\imgproc\imgproc.hpp> #include <opencv2\core
\core.hpp> using namespace CV;
using namespace Std;
    int main () {//Open camera Videocapture captrue (0);
    Video Write Object Videowriter write;
    Write the video file name string Outflie = "E://fcq.avi";
    Get the width of the frame int w = static_cast<int> (Captrue.get (cv_cap_prop_frame_width));
    int h = static_cast<int> (Captrue.get (cv_cap_prop_frame_height));
    Size S (W, h);
    Get frame rate Double r = captrue.get (Cv_cap_prop_fps);
	Open video file, ready to write Write.open (Outflie,-1, R, S, True);
    Open Failed if (!captrue.isopened ()) {return 1;
    } bool stop = FALSE;
    Mat frame;
        Loop while (!stop) {//Read frame if (!captrue.read (frame)) break;
        Imshow ("Video", frame);
        Write file Write.write (frame);
        if (Waitkey () > 0) {stop = true;
 }}//Release object Captrue.release ();   Write.release (); 
	Cvdestroywindow ("Video"); 
return 0; }
A video file named "Fcq.avi" was created in the E-drive directory after it was run.

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.