Code covered by the BSD License  

Highlights from
imaqutils

imaqutils

by

 

24 Sep 2004 (Updated )

Convenience functions to find hardware & create objects for supported Image Acquisition devices.

imaqcreate(desiredFormat)
function vid = imaqcreate(desiredFormat)
%IMAQCREATE creates a videoinput object for image acquisition.
%   VID = IMAQCREATE returns videoinput object. If multiple devices
%   available, user must select from list which device to use. If no
%   devices available (or no Image Acquisition Toolbox), returns empty.
%
%Note: This function calls IMAQRESET, which closes and deletes any
%   previously active videoinput objects.
%
%Example:
%   vid = imaqcreate;    %make IMAQ object (defaults)
%   preview(vid)         %preview live video input
%
%See also IMAQAVAIL.

% Copyright 2004-2010 RBemis The MathWorks, Inc. 

%TODO:
%   1. if create format error, offer available alternatives

error(nargchk(0,1,nargin))
error(nargoutchk(1,1,nargout))

%IMAQAVAIL does most of the work
if nargin>0
  devInfo = imaqavail(desiredFormat);
else
  devInfo = imaqavail;
end

%if multiple devices available, make user choose from list
if length(devInfo)>1
  names = {devInfo(:).name};
  index = listdlg('ListString',names,'Name','Select Video Device',...
    'SelectionMode','single');
  if isempty(index) %user aborted dialog
    devInfo = []; %don't return any cameras
  else
    devInfo = devInfo(index);
  end
end

%create object
if isempty(devInfo) %no IMAQ device available
  vid = []; %return empty
else
  try %create object
    vid = eval(devInfo.constructor);
  catch %create error
    msg = ['Unable to create ' devInfo.constructor];
    if nargin>0 %desired format problem
      %warning(msg)
      disp(['Device: ' devInfo.name])
      specificInfo = imaqhwinfo(devInfo.adaptor,devInfo.id);
      availableFormats = specificInfo.SupportedFormats;
      disp('Available formats:')
      for i=1:length(availableFormats)
        disp(['  ' availableFormats{i}])
      end
      error(msg) %remove once fixed (TODO #1)
    else
      error(msg)
    end
  end
end

Contact us