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

조회 수: 7 (최근 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 CenterFile Exchange에서 MATLAB Support Package for USB Webcams에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by