Place video stream inside of app designer
32 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 GigE Vision Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!