OpenCV open camera turn on webcam

Source: Internet
Author: User

This is an example of opening the camera with a OpenCV2.4.10, see the code below:

#include <iostream>#include<stdio.h>#include<opencv2/opencv.hpp>using namespaceCV;using namespacestd;intMainintargcChar*argv[]) {Cvcapture* Cam0 = Cvcapturefromcam (0); if(!cam0) {fprintf (stderr,"Could not initialize opening of Camera 0..\n"); System ("Pause"); return-1; } printf ("Cam0 initialized\n"); Cvnamedwindow ("Camera 0", cv_window_autosize);//Create a window called "Camera 0"     while(1) {Iplimage*cam0frame =Cvqueryframe (CAM0); if(cam0frame) {cvshowimage ("Camera 0", Cam0frame); }        if(Cvwaitkey ( -) == -)//wait for the ' ESC ' key press for 30ms. If ' ESC ' key is pressed, break loop{cout<<"ESC key is pressed by user"<<Endl;  Break; }} cvreleasecapture (&cam0); Cvdestroywindow ("Camera 0"); return 0;}

If you want to open two cameras at the same time, see my previous blog OpenCV show two cameras display two cameras simultaneously.

OpenCV open camera turn on webcam

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.