How can i check if there is an active connection to webcam ?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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);
0 Commenti
Risposte (1)
Matthew Gingerich
il 3 Ott 2018
This should open the camera unless it is already open:
if (exist('vid') == 0)
vid = webcam('USB Camera');
end
0 Commenti
Vedere anche
Categorie
Scopri di più su MATLAB Support Package for IP Cameras in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!