我创建了一个简单的 GUI 来预览网络摄像头流并从中获取快照。为此,我在轴上创建了显示视频,一个按钮(pushbutton1)开始预览,一个按钮(pushbutton2)获取快照。以下是这两个按钮的代码。
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes1);
vidObj = videoinput('winvideo',1);
videoRes = get(vidObj, 'VideoResolution');
numberOfBands = get(vidObj, 'NumberOfBands');
handleToImage = image( zeros([videoRes(2), videoRes(1), numberOfBands], 'uint8') );
preview(vidObj, handleToImage);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a=getsnapshot(get(axes,'Children'));
imshow(a);
在 pushbutton2_Callback 中,我试图获得轴的孩子,即。vidObj
. 但这给了我错误??? Undefined function or method 'getsnapshot' for input arguments of type 'double'.
。为什么它返回双类型而不是子对象vidObj
?如何修复它并获取快照?还有其他更好的方法吗?(我刚开始学习 GUI。)谢谢。