The Image Acquisition Toolbox in Matlab (Windows version) allows one to interface Matlab with a Webcam. This is available from R2007a (not sure about earlier versions). Similar to the audio recording object created earlier, here we create a videoinput
object. But before that is done, Matlab needs to find out what are the webcam devices that are connected to your computer.
imaqhwinfo gives information about the existing adaptors for your webcam device. You can get more information on each adapter, by using
imaqhwinfo('winvideo') where winvideo is one of the adaptors. In this, (if you have a device connected) you shall get a Device IDs attached to your webcam device. Further information pertaining to the device can be obtained by
imaqhwinfo('winvideo',1) where 1 is the Device ID you saw earlier.
This gives you much needed information regarding the capture device. The resolution (800×600, 1024×768, 1600×1200, etc.), format (RGB, YUV, etc.) which needs to be selected when creating a video object.
Armed with all this imaqhwinfo (image acquisition hardware information) you are ready to create your own video object.
vidobj = videoinput('winvideo',1,'RGB_1024x768');
‘RGB_1024x768’ was just the format that I selected. You should use one of those that were available in your device info query. The most important command now would be to start your video object
start(vidobj). It is at this point, or during the creation of video object, that the light (if any) on your webcam would start glowing indicating capture.
You can obtain snapshots of capture by using the
frame = getsnapshot(vidobj); or view the continuous stream of frames by saying
A safe closure (unlocking of the video handles) of the video object is extremely important so that it can be started again easily. A
stop(vidobj) followed by
delete(vidobj) is the best way to follow.
Another point to note is that all external capture devices, are locked by software which try to access it. Thus, you would get errors like Device not ready, or Device already in use in case you are already viewing the capture stream in any other software. So its recommended that you cleanly stop that software first and then let Matlab take over.
There are a variety of options that are not discussed here for lack of purpose like an automatic trigger (after a defined interval). All the options can be seen by
You now have the power of both Audio and Image / Video Capture now with which amazing tricks can be played 😉
UPDATE (2013-Aug-23): Might be interesting to just start exploring using