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