Place video stream inside of app designer

조회 수: 36 (최근 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