Video processing Simple example [OpenCV NOTE 2]

Source: Internet
Author: User

Videocapture is a new class in OpenCV 2.X that provides a C + + interface for capturing video from a camcorder or video file. There are two ways to use it to read video in general:

// Method 1 videocapture Capture;capture.open ("1.avi"); // Method 2 Videocapture Capture ("1.avi");

Read and Play Video

Readplayvideo.cxx

#include <opencv2/opencv.hpp>intMain () {//Read VideoCv::videocapture Capture ("1.avi"); //Show each frame     while(1) {Cv::mat frame; //read current frame;Capture >>frame; if(Frame.empty ()) Break; //Show Current FrameImshow ("Read Video", frame); Cv::waitkey ( -); }    return 0;}

CMakeList.txt

2.8 ) Project (readplayvideo) # Find OpenCV packagesfind_package (OpenCV REQUIRED) include_directories (${opencv_include _dirs}) # Add the executableadd_executable (Readplayvideo readplayvideo.cxx) target_link_libraries (ReadPlayVideo Opencv_core Opencv_highgui Opencv_videoio opencv_imgcodecs)

Call the camera to capture the image

Getvideofromcam.cxx

#include <opencv2/opencv.hpp>#include<opencv2/imgproc/imgproc.hpp>intMain () {//Read VideoCv::videocapture Capture (0); //Show each frame     while(1) {Cv::mat frame, edges; //read current frame;Capture >>frame; //Convert to Gray-scaleCv::cvtcolor (frame, edges, cv_bgr2gray); //denoiseCv::blur (edges, edges, cv::size (7,7)); //Canny operatorCv::canny (edges, edges,0, -,3); //Show Current FrameImshow ("Read Video", edges); //if input ' e ', exit        Charc = Cv::waitkey ( -); if(c=='e') {             Break; }    }    return 0;}

CMakeList.txt

2.8find  OpenCV packagesfind_package (OpenCV REQUIRED) include_directories (${opencv_ Include_dirs}) # Add the executableadd_executable (Readplayvideo readplayvideo.cxx) target_link_libraries ( Readplayvideo opencv_core Opencv_highgui opencv_videoio opencv_imgcodecs opencv_imgproc)

Video processing Simple example [OpenCV NOTE 2]

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.