How can i check if there is an active connection to webcam ?

2 ビュー (過去 30 日間)
mack cartagena
mack cartagena 2018 年 6 月 1 日
回答済み: Matthew Gingerich 2018 年 10 月 3 日
I'm making a GUI with a webcam and i'm taking a snapshot every time i click a push button, but first i have to create the webcam object in order to take the photo, so i'm wondering if there is a way to check if the GUI already make connection with the webcam and skip the creation of this object because it takes a lot of time in the creation. This is the code im trying but seems not working on the GUI:
exst = exist(vid)
if exst==0
clear('vid');
maxAttempts = 30;
attempt = 1;
hasProperty = false;
while attempt < maxAttempts
vid = webcam('USB Camera');
hasProperty = max(ismember(properties(vid), 'Exposure'));
if hasProperty
% We got all the properties so we can quit trying.
fprintf('We have all camera properties after %d attempts. Now continuing with program.\n', attempt);
break;
end
fprintf('We do not have all camera properties after %d attempts. Trying again.\n', attempt);
attempt = attempt + 1;
clear('vid');
end
%CAMERA CONFIGURATION
vid.Resolution='2048x1536';
vid.WhiteBalanceMode='manual';
vid.ExposureMode='manual';
vid.Exposure=-5.7;
vid.Gain=0;
vid.Hue=0; %-40 40
vid.Gamma=72; %72-500
vid.Contrast=64;
vid.Saturation=35;
vid.Sharpness=1;
vid.Brightness=15; %-64 64
vid.WhiteBalance=6500; %2800-6500
vid.BacklightCompensation=2; %0-2
end
img=snapshot(vid);

回答 (1 件)

Matthew Gingerich
Matthew Gingerich 2018 年 10 月 3 日
This should open the camera unless it is already open:
if (exist('vid') == 0)
vid = webcam('USB Camera');
end

カテゴリ

Help Center および File ExchangeDesktop についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by