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

8 ビュー (過去 30 日間)
Ty Olmstead
Ty Olmstead 2019 年 1 月 31 日
コメント済み: Abdulrahman 2020 年 2 月 7 日
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 件のコメント
Geoff Hayes
Geoff Hayes 2019 年 1 月 31 日
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

サインインしてコメントする。

採用された回答

Kevin Chng
Kevin Chng 2019 年 2 月 22 日
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 件のコメント
Abdulrahman
Abdulrahman 2020 年 2 月 7 日
How are you, I want to turn the cam on and design it up Can you help me?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by