Input from a Camera
Vision can mean many things in the world of computers. In some cases we are analyzing still frames loaded from elsewhere. In other cases we are analyzing video that is being read from disk. In still other cases, we want to work with real-time data streaming in from some kind of camera device.
OpenCVâmore specifically, the HighGUI portion of the OpenCV libraryâprovides us with an
easy way to handle this situation. The method is analogous to how we read AVIs. Instead of
calling cvCreateFileCapture()
, we call cvCreateCameraCapture()
. The latter routine does not take a file
name but rather a camera ID number as its argument. Of course, this is important only when
multiple cameras are available. The default value is â1, which means "just pick one";
naturally, this works quite well when there is only one camera to pick (see Chapter 4 for more details).
The cvCreateCameraCapture()
function returns the same
CvCapture*
pointer, which we can hereafter use exactly
as we did with the frames grabbed from a video stream. Of course, a lot of work is going on
behind the scenes to make a sequence of camera images look like a video, but we are
insulated from all of that. We can simply grab images from the camera whenever we are ready
for them and proceed as if we did not know the difference. For development reasons, most
applications that are intended to operate in real time will have a video-in mode as well,
and the universality of the CvCapture
structure makes this particularly ...
Get Learning OpenCV now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.