Opencv open the camera to get the video program

Source: Internet
Author: User
//// Main. CPP // opencv3 // created by PKU on 14-9-16. // copyright (c) 2014 PKU. all rights reserved. // # include <opencv2/opencv. HPP> using namespace CV; using namespace STD; int main () {cvcapture * capture = cvcapturefromcam (-1); cvvideowriter * Video = NULL; iplimage * frame = NULL; int N; if (! Capture) // if the camera cannot be opened, a warning is given {cout <"can not open the camera. "<Endl; Return-1;} else {frame = cvqueryframe (capture); // first obtain a frame of Video = cvcreatevideowriter (" camera. avi ", cv_fourcc ('M', 'J', 'P', 'G'), 32, cvsize (frame-> width, frame-> height )); // create a cvvideowriter object and allocate space. // The saved file name is camera. avi: the encoding should be selected when the program is running. The size is the video size of the camera, and the frame frequency is 32 If (video) // If the cvvideowriter object can be created, it indicates that {cout <"videowriter has created is successful. "<Endl;} CV Namedwindow ("camera video", 1); // create a window while (1) {frame = cvqueryframe (capture); // obtain a frame from cvcapture if (! Frame) {cout <"can not get frame from the capture. "<Endl; break;} n = cvwriteframe (video, frame); // determines whether the write is successful. If 1 is returned, the write is successful. <n <Endl; cvshowimage ("camera video", frame); // If (cvwaitkey (1)> 0) break of the image displaying the video content; // other keyboard responses are available, exit} cvreleasevideowriter (& Video); cvreleasecapture (& capture); cvdestroywindow ("camera video");} return 0 ;}

 

Opencv open the camera to get the video program

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.