The OpenCV Highgui module provides the Cvcreatecameracapture (), which can be read into the video stream from the camera device, and the function parameter is the device ID instead of the file name. The default value is-1, which is to randomly select a device.
Sample program:
1 /************************************************************************/2 /*read data by camera*/3 /************************************************************************/4 5#include"cv.h"6#include"highgui.h"7 8 intMainintargcChar**argv)9 {TenCvnamedwindow ("cameracapture", cv_window_autosize); Onecvcapture*capture; A if(ARGC = =1) - { -Capture = cvcreatecameracapture (-1); the } - Else - { -Capture = Cvcreatefilecapture (argv[1]); + } -ASSERT (Capture! =NULL); + Aiplimage*frame; at while(1) - { -frame =Cvqueryframe (capture); - if(!frame) Break; -Cvshowimage ("cameracapture", frame); - Charc = Cvwaitkey ( -);//Set Frame rate in if(c = = -) Break;//Press ESC to exit - } to +Cvreleasecapture (&capture); -Cvdestroywindow ("cameracapture"); the * return 0; $}
2. Read data from camera