MATLAB Answers

Refresh webcamlist in app designer

2 views (last 30 days)
gaylord durand
gaylord durand on 18 Jul 2020
Edited: Srijith Vijay on 18 Jul 2020
I try to create a little code to acquire all cameras devices connected to my computer. To assure that the camera is plug in a lamp light up in yellow, if not the lamp is red.
I try this in the start up fonction in app designer but my problem is that the code execute well at the start but no refresh seems to appears when i unplug a camera.
So my question is : how can i have a continous refresh of that little code in app designer ?
Here is my code :
% Code that executes after component creation
function startupFcn(app)
x = string(webcamlist); % x get back all camera devices
[Rangenumb,~]= size(x); % Rangenumb get the number of devices
lamp = [app.Lamp_1;app.Lamp_2;app.Lamp_3]; % lamp get all UILamp in a matrix
for ii = 1:Rangenumb % the for loop turn on in yellow as many lamp as there is camera devices
lamp(ii).Color = 'yellow';
end
end
I use only 3 Lamps in this code because i only have 3 differents cameras to test it.
Thanks in advance for the answers.

Answers (1)

Srijith Vijay
Srijith Vijay on 18 Jul 2020
Edited: Srijith Vijay on 18 Jul 2020
You could create a function (say refreshWebcam) and use this as the callback function for a MATLAB timer.
Start the timer in the startupFcn of the app and this should continuously keep checking for any new webcams connected, every 't' seconds. 't' being the timer period.

Community Treasure Hunt

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

Start Hunting!