MATLAB: Can we use the DeviceName instead of adaptorName to connect a camera to Matlab

image acquisition

In my project, I am using 3 different cameras and order of these cameras are important in the code. Wondering if it is possible using the DeviceName info. instead of the adaptorName info. to determine the specific camera.

Best Answer

I am guessing you are using the Image Acquisition interface; http://www.mathworks.com/help/imaq/imaqhwinfo.html
targetname = 'IBM PC Camera'; %for example
summaryinfo = imaqhwinfo();
for adapter = summaryinfo.InstalledAdaptors
adaptinfo = imaqhwinfo(adapter);
devids = adaptinfo.DeviceIDs; %oddly, a cell array
devinfo = adaptinfo.DeviceInfo; %structure array
found_target = false;
for K = 1 : length(devinfo)
devname = devinfo(K).DeviceName;
if strcmpi(devname, targetname)
targetid = devids{K}; %remember it is a cell array
found_target = true;
break;
end
end
if found_target; break; end
end
if ~found_target
fprintf('Could not find device "%s\n', targetname);
error('Device not found');
end
obj = videoinput(adapter, targetid);