How do I actively control a webcam in app designer using a toggle switch?

3 vues (au cours des 30 derniers jours)
I have an application where I am using a stereo camera system that inputs one large image from two cameras into Matlab. I take a snapshot and then sparse the image into two images, crop, offset, display, etc using a subroutine ShowImages. I would like to be able to view the images live while I align the system that is collecting them. Currently I am using a while loop that is linked to a toggle switch. When the toggle switch changes the while loop breaks. Although the code seems to work, it is extremely slow. It can take 20 seconds after the switch is changed to off before the system responds. Is there a way to get the system to respond faster?
% Value changed function: CamsLiveSwitch
function CamsLiveSwitchValueChanged(app, event)
while isequal(app.CamsLiveSwitch.Value,'On')
app.AquiringImagesLamp.Color = [0 1 0];
% Display image and stretch to fill axes
ShowImages(app) % This function manipulates the imagery for display
if isequal(app.CamsLiveSwitch.Value,'Off')
break;
end
end
app.AquiringImagesLamp.Color = [1 0 0];
  1 commentaire
Geoff Hayes
Geoff Hayes le 31 Jan 2019
Ty - I haven't used App Designer for GUIs but if you want to interrupt the "tight" while loop you could add a pause to it so that the change to the state of the toggle button is "captured". For example,
while isequal(app.CamsLiveSwitch.Value,'On')
app.AquiringImagesLamp.Color = [0 1 0];
% Display image and stretch to fill axes
ShowImages(app) % This function manipulates the imagery for display
if isequal(app.CamsLiveSwitch.Value,'Off')
break;
end
pause(0.001);
end

Connectez-vous pour commenter.

Réponse acceptée

Kevin Chng
Kevin Chng le 22 Fév 2019
The algorithm logic given by Geoff Hayes is right.
Code below is the code you may consider to put into the callback function of your 'toggle switch' in app designer.
value = app.Switch.Value;
if strcmp(value,'On')
cam=webcam;
while(strcmp(value,'On'))
img=snapshot(cam);
imshow(img,'Parent',app.UIAxes);
drawnow;
value = app.Switch.Value;
if strcmp(value,'Off')
break;
end
end
end
  1 commentaire
Abdulrahman
Abdulrahman le 7 Fév 2020
How are you, I want to turn the cam on and design it up Can you help me?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by