OpenCV (Study note 6)-Video reading and display

Source: Internet
Author: User

The reading of video mainly utilizes the Videocapture class in OpenCV. You can also make calls to the camera.

There are two ways to provide read-in video in the Videocapture class.

Instantiate and initialize first

VideoCapture capture;capture.open("Sugar.avi");

Initializing at the same time as instantiation

capture("Sugar.avi");

After the video is read into the Videocapture class object, it is immediately possible to display each frame with a loop.
Sugar.avi also needs to be placed in the directory as 1.jpg.

#include<opencv2/opencv.hpp>usingnamespace cv;int main(){    VideoCapture capture("Sugar.avi");    while(1)    {        Mat frame;        capture>>frame;        imshow("读取视频", frame);        if(waitKey(600)                break;    }    return0;}

The results of the operation are as follows:

Earlier in the study note 5 written about canny edge detection, in fact, in the video we can also add in. The code is as follows:

#include <opencv2/opencv.hpp>using namespaceCvintMain () {Videocapture capture ("Sugar.avi"); Mat edges; while(1) {Mat frame;        capture>>frame;        Cvtcolor (frame, edges, cv_bgr2gray); Blur (edges, edges, Size (7,7)); Canny (edges, edges,0, -,3); Imshow ("read Video", edges);if(Waitkey ( -) >=0) Break; }return 0;}

The results of the operation are as follows:

More learning materials about OPENCV and image processing and pattern recognition will continue to be updated, so stay tuned for this blog.

OpenCV (Study note 6)-Video reading and display

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.