Detecting installed webcam via command line/m script file

On my previous Matlab tips, I already show you how to create a GUI (GUIDE)  to capture webcam picture. I show you how to easily detect installed and supported video format using imaqtool command. This time I’ll show you how to detect installed webcam without calling imaqtool window. This would be useful if you want to automatically detect installed webcam without needing user interaction/input.

Your Matlab still need Image Acquisition Toolbox though and your webcam should be connected before you open Matlab.

  • First step is to detect installed webcam drivers on in your Matlab, because it could be different on different platform (Windows/Linux/Mac).

Variable adaptors now will contain installed drivers on your Matlab. Example output would be (InstalledAdaptors is a cell):

>> adaptors.InstalledAdaptors

ans = 

    'matrox'    'winvideo'
  • Now we know that my Matlab knows ‘matrox’ and ‘winvideo’ driver. Our next step would be detecting is there any webcam attached to those drivers. Use this command :
  • For detecting how many installed webcam that detected as ‘matrox’ we can use:
>> numel(matrox_webcam.DeviceIDs)

ans =

  • Oh, as you can see, there’s no webcam detected as ‘matrox’ so we are certainly will not use this driver. How about ‘winvideo’ webcam, let’s check:
>> numel(winvideo_webcam.DeviceIDs)

ans =

  • Yup, there’s one installed and active there, let’s check further to know how to command Matlab to use this webcam:
>> winvideo_webcam.DeviceInfo(1).ObjectConstructor

ans =

videoinput('winvideo', 1)
  • Now you got what command that you should use to activate the webcam [videoinput(‘winvideo’, 1)]. How about the supported image/video formats supported by this webcam? Use this command:
>> winvideo_webcam.DeviceInfo(1).SupportedFormats

ans = 

  Columns 1 through 4

    'YUY2_160x120'    'YUY2_176x144'    'YUY2_320x240'    'YUY2_352x288'

  Column 5


Oh, there are 5 types of supported image/video. You can choose one.

Your information is now complete, you know which webcam is active, what command that need to be called to activate the webcam and which format available for this webcam. You can begin to capture the image/video from webcam using Matlab.

matlab 2011a logo

Tested on Matlab 2011a on Windows 7 64 bit within Asus Notebook A43SV

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>