Place video stream inside of app designer

38 ビュー (過去 30 日間)
Happy PhD
Happy PhD 2022 年 4 月 12 日
コメント済み: Happy PhD 2022 年 4 月 13 日
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!

採用された回答

Kevin Holly
Kevin Holly 2022 年 4 月 12 日
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 件のコメント
Happy PhD
Happy PhD 2022 年 4 月 13 日
I solved this in a different way in the end, by using preview (instead of a while loop), but thank you for your input.

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

その他の回答 (0 件)

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by