Today in the camera read Video lab found that the original read the file based on directly modified Veidocapture capture ("string") for Vediocapture capture (0) Although the compilation can be successful, but the video can not read normally (card at the first frame , or cannot be opened).
Videocapture Capture (0);//Note here the //Verify that the video is turned on successfully if(!capture.isopened ()) {return 1; }//Get frame rate //double fps = capture.get (cv_cap_prop_fps); BOOLStopfalse); Mat frame;//Current video frameNamedwindow ("Show");//The delay time for each frame is the same as the frame rate //int delay = 1000/fps; //Iterate through each frame while(!stop) {if(Capture.read (frame)) {//medianblur (frame, frame, 3);Imshow ("Show", frame);//waitkey (+);}Else Break;if(Waitkey ( -) >=0) {stop =true; } }//Close fileCapture.release ();
After consulting the data found that the problem in the Waikey () function of the delay parameter, when reading the file delay is the video file frame interval, which can be obtained from the video file information (through the Get function). However, when using the camera, this information is not available (or can not be obtained in time), so the program does not work properly, we only need to give delay to an empirical constant, as shown in the code above.
In this statement: I am also a beginner, this is only one of my experience, if there is not right, look at the great God advice, thank you!
OPENCV read camera without reading frame rate