placing figure in current GUI in a particular location
3 次查看(过去 30 天)
显示 更早的评论
I created an gui and named it as maingui i have a pushbutton, and in the call back function using uigetfile I browse the location of a video. Then in the same callbackfunction I call a function which reads the video and extract a frame from video, but I want to display the extracted frame on that GUI , how can I do that ?
function fntest_final()
MW.f = figure('Name','Project','Position', [1 1 700 1000]);
setappdata(0,'maingui',gcf);
MW.pb2 = uicontrol('Style', 'Pushbutton'.....
....
set(MW.pb2, 'Callback', {@loadbutton,MW});
end
function loadbutton(varargin)
MW = varargin{3};
reqfilename = uigetfile(....)
readvideofn %%i get error in navigating to this function
end
function readvideofn(reqfilename)
videoObject = VideoReader(reqfilename);
rgbImage = read(videoObject, 3200);
%%now I want to display this on the GUI in a particular fixed position
%%how ?
end
when I call the function it says Error while evaluating UIControl Callback
0 个评论
采纳的回答
Walter Roberson
2016-1-25
image() accepts x and y coordinates to display at. But I suspect that what you want is to generate an axes ahead of time, retrieve the axes handle in the routine, and pass the axes handle to image() as the first parameter.
2 个评论
Walter Roberson
2016-1-25
At the top when you are creating MW, create MW.video_axes as the axes configured with the Position where you want the frame to be displayed.
function loadbutton(varargin)
MW = varargin{3};
[reqfilename, reqpath] = uigetfile(....);
thisfile = fullfile(reqpath, reqfilename);
readvideofn(thisfile, MW);
end
function readvideofn(reqfilename, MW)
videoObject = VideoReader(reqfilename);
rgbImage = [];
for K = 1 : 3200
if hasFrame(videoObject)
rgbImage = readFrame(videoObject);
else
break;
end
end
delete(videoObject);
dest_axes = MW.video_axes;
image(dest_axes, rgbImage);
axes(dest_axes, 'image');
end
You might notice that I replaced the read() with a loop. The read() method is deprecated and the replacement readFrame does not allow frames to be requested by number. I do not know why that is, but I suspect it might have to do with variable frame-rate videos.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!