Place video stream inside of app designer
47 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Happy PhD
am 12 Apr. 2022
Kommentiert: Happy PhD
am 13 Apr. 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!
0 Kommentare
Akzeptierte Antwort
Kevin Holly
am 12 Apr. 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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu GigE Vision Hardware finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!