【发布时间】:2017-11-30 06:23:34
【问题描述】:
我正在尝试在 MATLAB GUI 中设置一个滑块来控制视频,例如移动到视频的某些帧中。 'obj' 是用户选择的视频文件。以下代码用于获取输入视频并显示在 GUI 的轴上。
global b
filename = get(handles.edit3, 'String');
if ~exist(filename, 'file')
warndlg( 'Text in edit box is not the name of a file');
return
end
try
obj = VideoReader(filename);
catch
warndlg( 'File named in edit box does not appear to be a usable movie file');
return
end
axes(handles.axes2)
handles.pushbutton5=0;
guidata(hObject,handles);
while ~(handles.pushbutton5)
if hasFrame(obj)
vidFrame = readFrame(obj);
obj;
image(vidFrame, 'Parent', handles.axes2);
set(axes, 'Visible', 'off');
pause(1/obj.FrameRate)
end
handles = guidata(hObject);
end
clear obj
当用户控制滑块时,滑块将提供“b”值。
function slider2_Callback(hObject, eventdata, handles)
% hObject handle to slider2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
global b
b = get(handles.slider2,'Value');
有谁知道如何解决这个问题,以便可以通过滑块控制视频?
【问题讨论】:
-
您能否更清楚地表述您的问题?您想通过值
b控制视频的哪个属性?它应该是帧索引吗?播放速度还是视频亮度? -
我需要使用滑块跳转或移动到视频的多个部分或帧。
-
视频帧的绘制必须在
slider2_Callback函数中进行。在那里,您需要访问您的视频文件并读取索引为b的帧。要访问您的数据,请将它们放在您的guidatastructure 中。变量b不需要是全局的。但是为什么不用matlab的implay()函数呢? de.mathworks.com/help/images/ref/implay.html -
我们可以在 GUI 中使用 implay 吗?我在 GUI 中提供了轴。是否可以将implay窗口放在GUI的轴上?
标签: matlab user-interface video uislider