Debugging OPENCV problems when calling the camera program

Source: Internet
Author: User

Last night to OPENCV study notes to tidy up, when running OPENCV call camera program always appear assertion failed (size.width>0 && size.height>0) in CV:: Imshow, the last look at the data to know is because the call Imshow () function when the mat is empty caused, may be at the beginning of the camera is not initialized successfully, call Imshow () cause the program has been started down, Just determine if the incoming mat is empty in the while loop.

#include <opencv2/opencv.hpp>#include<iostream>using namespaceCV;using namespacestd;intMainintargcChar*argv[]) {Videocapture Cap (0); //setting up the cameraCap.Set(Cv_cap_prop_frame_width,640); Cap.Set(Cv_cap_prop_frame_height,480); //confirm that the camera is turned on successfully    if(!cap.isopened ()) {cout<<"Open camera failed, exit"; Exit (-1); } Namedwindow ("Capture", Cv_window_autosize |cv_window_freeratio);  while(1) {Mat frame; Cap>>frame; if(!Frame.empty ()) {Imshow ("Capture", frame); }                if(Waitkey ( -) >=0) Break; }    return 0;}

Debugging OPENCV problems when calling the camera 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: 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.