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:
Creating an axes object in the GUI. This is the second figure, so it is automatically labelled as
app.UIAxes2
.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'));
where app.Camera
is my camera object (I have included the property in the class) and the second command is supposed to resize the image to the camera video stream size. I may be wrong about this.
Creating a switch (
CameraStreamSwitch
), which is supposed to show the video stream when switched on (toStart
).Creating the following function in the App code, which is activated whenever the switch is pressed:
% 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
Now, although the other figures showing graphs that updated in real-time are working, this figure is clearly not working, i.e. it is resized to the correct size, but remains black all the time (I have checked, opening preview from the command line (outside of the app) results in a figure popping up and showing a functioning video stream). I am not sure if the problem is related to calling preview
within an app, my not specifying the the correct image or image properties correctly, or whether I should simply display fewer images at a slower frame rate within an App.
What can be done to solve this?