Callback functions for displaying videos

1 回表示 (過去 30 日間)
NAVNEET NAYAN
NAVNEET NAYAN 2020 年 1 月 6 日
コメント済み: Max Murphy 2020 年 1 月 6 日
I am making a GUI in Matlab using AppDesigner. It displays a video after pressing the push button. This video is already stored in a folder and I am reading it first and then playing it. But the problem is "The video is displayed in a different window". How can I display the video in the same window where push button was pressed. I am attaching here the piece of code used as callback function for dispalying window.
function ButtonPushed(app, event)
app1.VFR= vision.VideoFileReader('newfile.avi');
app1.VPR = vision.VideoPlayer;
% Play video. Every call to the step method reads another frame.
while ~isDone(app1.VFR)
frame = step(app1.VFR);
step(app1.VPR,frame);
end
end
Please suggest a way for this. In case anyone need details regarding the problem please leave a comment.
  2 件のコメント
Mohammad Sami
Mohammad Sami 2020 年 1 月 6 日
If you have the latest version of Matlab and your videos are mp4 standard, you can use the uihtml element to embed your video as an html.
The html tags for embedding a video can be seen here.
NAVNEET NAYAN
NAVNEET NAYAN 2020 年 1 月 6 日
My Matlab is MATLAB R2019a and videos are in .avi format.

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

採用された回答

Max Murphy
Max Murphy 2020 年 1 月 6 日
% In app constructor
...
% Initialize image
app.Figure = figure('Name','Main Video GUI');
app.VidAx = axes(app1.Figure,'XColor','none','YColor','none',...
'XLim',[0 1],'YLim',[0 1]);
% Can't remember, but here if your video is upside down:
% app1.VidAx.YDir = 'reverse';
app.VFR= vision.VideoFileReader('newfile.avi');
[h,w] = app.VFR.VideoSize;
app.VideoImage = imagesc(app.VidAx,linspace(0,1,w),linspace(0,1,h),zeros(h,w));
...
% Rest of app constructor
function ButtonPushed(app, event)
% Reset the video first
reset(app.VFR);
% Play video. Every call to the step method reads another frame.
while ~isDone(app.VFR)
% Update image frame
app.VideoImage.CData = step(app.VFR);
drawnow limitrate; % Limits to 20 fps
end
end
Rough outline to get you started.
  2 件のコメント
NAVNEET NAYAN
NAVNEET NAYAN 2020 年 1 月 6 日
I am using your suggested piece of code but it is still creating a different window. I am attaching the picture of resulted windows.
results after using your code.png
So I am getting two windows. What I want that the window of video should appear in 'UI Figure' window.
Max Murphy
Max Murphy 2020 年 1 月 6 日
In my code, this line
app.Figure = figure('Name','Main Video GUI');
Should correspond to whatever the intrinsic property of app that corresponds with the current window figure handle. If you don't know what that property is, you could just replace that line with this and I think it would still work (unless the app figure is created later on in the code):
app.Figure = gcf;

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by