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

1 view (last 30 days)
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.

Accepted Answer

Walter Roberson
Walter Roberson on 30 Aug 2015
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);

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!