get webcam hardware ID to distinguish/address 2 identical webcams

6 views (last 30 days)
dear all,
I have 2 identical USB webcams (Microsoft® LifeCam Studio) plugged in. imaqhwinfo sees both
>> imaqhwinfo('winvideo')
ans =
struct with fields:
AdaptorDllName: 'C:\ProgramData\MATLAB\SupportPackages\R2017b\toolbox\imaq\supportpackages\genericvideo\adaptor\win64\mwwinvideoimaq.dll'
AdaptorDllVersion: '5.3 (R2017b)'
AdaptorName: 'winvideo'
DeviceIDs: {[1] [2]}
DeviceInfo: [1×2 struct]
i can display both DeviceInfo
ans =
struct with fields:
DefaultFormat: 'M420_1280x720'
DeviceFileSupported: 0
DeviceName: 'Microsoft® LifeCam Studio(TM)'
DeviceID: 1
VideoInputConstructor: 'videoinput('winvideo', 1)'
VideoDeviceConstructor: 'imaq.VideoDevice('winvideo', 1)'
SupportedFormats: {1×36 cell}
ans =
struct with fields:
DefaultFormat: 'M420_1280x720'
DeviceFileSupported: 0
DeviceName: 'Microsoft® LifeCam Studio(TM)'
DeviceID: 2
VideoInputConstructor: 'videoinput('winvideo', 2)'
VideoDeviceConstructor: 'imaq.VideoDevice('winvideo', 2)'
SupportedFormats: {1×36 cell}
they are identical except of course DeviceID.
the problem is that i have no control over DeviceID (that seems random or casue by which one was plugged first)
my question is how can i know which one is which? is there a way to read a hardware ID (or serial number or the like) related to DeviceID, so i could determine which DeviceID belongs to which physical webcam?
thanks for your time
  4 Comments
Roman Koetitz
Roman Koetitz on 9 Mar 2022
thanks walter. yes exactly, i thinks the question boils down to how to read the "device instance path" from matlab or the command line. i think this path consists of 4 parts and the 3rd part is different for my 2 identical webcams
Roman Koetitz
Roman Koetitz on 9 Mar 2022
i also opened a ticket with mathworks about this issue. it would be great if more hardware info could be included in the output of imaqhwinfo

Sign in to comment.

Answers (1)

Pratyush Swain
Pratyush Swain on 8 Feb 2024
Edited: Pratyush Swain on 8 Feb 2024
Hi Roman,
I agree its hard to distinguish between two identical cameras just by device ID.One practical approach to differentiate between identical webcams is to physically distinguish them by observing the video feed from each camera. You can do this by capturing a frame from each webcam and displaying it to uniquely identify cameras from each other.
Here's a MATLAB script that captures and displays a single frame from each webcam:
% Get the video device information
info = imaqhwinfo('winvideo');
% Assuming you have 2 webcams connected with DeviceIDs 1 and 2
for i = 1:length(info.DeviceIDs)
% Create a video input object for each webcam
vid = videoinput('winvideo', i);
% Set the properties for the video object
src = getselectedsource(vid);
vid.FramesPerTrigger = 1;
vid.TriggerRepeat = 0;
src.Tag = 'motion';
% Start the webcam
start(vid);
% Get the frame data
frameData = getdata(vid, 1);
% Stop the webcam
stop(vid);
% Display the frame
figure;
imshow(frameData);
title(['Webcam DeviceID: ', num2str(i)]);
% Clean up
delete(vid);
clear vid;
end
You will obtain two camera frames with their corresponding device ID as their title,hence you can identify which device id refers to which camera and accordingly carry out further tasks.
For more information on "imaqhwinfo" , please refer to https://www.mathworks.com/help/imaq/imaqhwinfo.html .
Hope this workaround helps.

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!