Getting snapshot from webcam in Matlab
Posted
by
Harsh
on Stack Overflow
See other posts from Stack Overflow
or by Harsh
Published on 2012-05-27T06:29:30Z
Indexed on
2012/06/09
16:40 UTC
Read the original article
Hit count: 513
I have created a simple GUI to preview webcam stream and to get snapshot from it. For this I have created on axes to show video, one push button(pushbutton1) to start preview, one push button(pushbutton2) to get snapshot. Following is the code for these two push buttons.
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);
In pushbutton2_Callback I am trying to get child of axes ie. vidObj
. But this gives me error ??? Undefined function or method 'getsnapshot' for input arguments of type 'double'.
. Why is it returing double type instead of child object vidObj
?
How can I fix it and get snapshot?
Is there any other better way?
(I just started learning GUI.)
Thanks.
© Stack Overflow or respective owner