Display Video Stream in App Designer

조회 수: 7 (최근 30일)
Enrico Anderlini
Enrico Anderlini 2018년 8월 31일
편집: Cris LaPierre 2023년 7월 10일
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: https://uk.mathworks.com/matlabcentral/answers/357814-how-to-create-a-custom-preview-window-for-matlab-webcam
So far, what I am doing is including the following commands in my start-up function:
app.Camera = webcam; %('USB2.0 PC CAMERA')
image(app.UIAxes2,zeros(size(snapshot(app.Camera)),'uint8'));
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'));
preview(app.Camera,im);
end
end
Many thanks in advance for the help!

답변 (1개)

Cris LaPierre
Cris LaPierre 2018년 12월 22일
편집: Cris LaPierre 2023년 7월 10일
You are close. Here's some sample code that works for me.
Add properties for the variables you create that you want to share
properties (Access = private)
Camera % webcam stream object
himg % image object handle
end
My startupFcn looks like this
value = app.CameraStreamSwitch.Value;
if strcmpi(value,'on')
preview(app.Camera,app.himg)
end
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)
delete(app)
delete(app.Camera)
end
  댓글 수: 3
Pien Vinke
Pien Vinke 2023년 7월 3일
Did you maybe find a solution for closing the preview of the camera?
Cris LaPierre
Cris LaPierre 2023년 7월 10일
편집: Cris LaPierre 2023년 7월 10일
In the most recent version of MATLAB, closePreview no longer closes the app. Looking back, this seems to be the case since R2019b. What version of MATLAB are you using?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB Support Package for IP Cameras에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by