Place video stream inside of app designer

37 vues (au cours des 30 derniers jours)
Happy PhD
Happy PhD le 12 Avr 2022
Commenté : Happy PhD le 13 Avr 2022
I have an code that i want to place inside of app designer. The code creates a window that shows the frames (live stream) of an video. How do i do the same thing in app designer but with a permanent button and display window for the video stream? I like to have buttons that turn on and turn off the camera steam and remove the while loop. The camera is a gigE camera.
My code:
aviObject = VideoWriter(['videolog.avi']); % Create a new AVI file
open(aviObject);
ButtonHandle = uicontrol('Style', 'PushButton', ...
'String', 'Stop loop', ...
'Callback', 'delete(gcbf)');
%for iImage = 1:200 % Capture X frames
tStart = tic;
tEnd = 0;
while tEnd < 30
timerVal = tic
[img, ts] = snapshot(g);
imshow(img)
writeVideo(aviObject, img); % Add the image to the AVI file
if ~ishandle(ButtonHandle)
disp('Loop stopped by user');
break;
end % end if
tEnd = toc(tStart)
end % end while or for
Many thanks!

Réponse acceptée

Kevin Holly
Kevin Holly le 12 Avr 2022
Did you want to place the video on an axes with the app? Or do you want to place the video on an axes on a different UIFigure/app?
I attached an app assuming you want to place the video on axes within the app's canvas.
Either way, you will need to assign an axes to place your video. For the imshow() function, you can do this as such:
imshow(img,'Parent',app.UIAxes)
You can drag uicomponents (axes and pushbutton) onto the canvas. Then you can right click the pushbutton>Callback>Add PlayButtonPushed callback. I added some icons to make it more aesthetically pleasing.
if app.PlayButton.Text == "Play"
app.PlayButton.Text = "Stop";
app.PlayButton.Icon = "IconEnd.png";
aviObject = VideoWriter(['videolog.avi']); % Create a new AVI file
open(aviObject);
%for iImage = 1:200 % Capture X frames
tStart = tic;
tEnd = 0;
while tEnd < 30
timerVal = tic
% [img, ts] = snapshot(g);
img=rand(40); %Creating random matrix as I don't have the varibale g defined.
imshow(img,'Parent',app.UIAxes)
drawnow
writeVideo(aviObject, img); % Add the image to the AVI file
if app.PlayButton.Text == "Play"
disp('Loop stopped by user');
break;
end % end if
tEnd = toc(tStart)
end % end while or for
else
app.PlayButton.Text = "Play";
app.PlayButton.Icon = "IconPlay.png";
end
  1 commentaire
Happy PhD
Happy PhD le 13 Avr 2022
I solved this in a different way in the end, by using preview (instead of a while loop), but thank you for your input.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by