我正在尝试在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');
有谁知道如何解决这个问题,以便可以通过滑块控制视频?