get webcam hardware ID to distinguish/address 2 identical webcams
5 次查看(过去 30 天)
显示 更早的评论
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
回答(1 个)
Pratyush Swain
2024-2-8
编辑:Pratyush Swain
2024-2-8
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 GigE Vision Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!