MATLAB Answers

Display Video Stream in App Designer

67 ビュー (過去 30 日間)
Enrico Anderlini
Enrico Anderlini 2018 年 8 月 31 日
コメント済み: Cris LaPierre 2018 年 12 月 22 日
I am developing a simple app in App Designer and I have been struggling with including a video stream from a webcam.
I have come across the following post, but so far I have been unsuccessful in getting my app to work:
So far, what I am doing is including the following commands in my start-up function:
app.Camera = webcam; %('USB2.0 PC CAMERA')
And the following lines relate to the activation of the video stream when a switch button is slid to Start:
% Value changed function: CameraStreamSwitch
function CameraStreamSwitchValueChanged(app, event)
while strcmp(app.CameraStreamSwitch.Value,'Start')
im = image(app.UIAxes_2,zeros(size(snapshot(app.Camera)),'uint8'));
Many thanks in advance for the help!

  0 件のコメント


回答 (1 件)

Cris LaPierre
Cris LaPierre 2018 年 12 月 22 日
You are close. Here's some sample code that works for.
Add properties for the variables you create that you want to share
properties (Access = private)
Camera % webcam stream object
himg % image object handle
My startupFcn looks like this
value = app.CameraStreamSwitch.Value;
if strcmpi(value,'on')
I would also suggest adding a closing function so the webcam doesn't remain open once the app closes.
% Close request function: UIFigure
function UIFigureCloseRequest(app, event)

  1 件のコメント

Cris LaPierre
Cris LaPierre 2018 年 12 月 22 日
The downside, I will admit, is that I can't find a way to close the preview with closing the app window. The function for this is closePreview.


Community Treasure Hunt

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

Start Hunting!

Translated by