Using timer to capture images from webcam
2 次查看(过去 30 天)
显示 更早的评论
Hi,I have a question. I want to use a webcam to capture an image every 1s.I made a GUI with 2 axes and 2 button.Axes 1 is used to show video from webcam and axes 2 is used to contain images that I capture from axes 1.Button 1(start) callbacks the function of starting recording from webcam and button 2(capture) is used to activate the timer.I tried this code:
function start_Callback(hObject, eventdata, handles)
global vid
imaqhwinfo;
info=imaqhwinfo('winvideo');
vid = videoinput('winvideo', 1, info.DeviceInfo(1,1).SupportedFormats{1});
vidRes = get(vid, 'VideoResolution');
nBands = get(vid, 'NumberOfBands');
hImage = image(zeros(vidRes(2),vidRes(1), nBands),'Parent',handles.axes1);
preview(vid,hImage);
function capture_Callback(hObject, eventdata, handles)
% hObject handle to capture (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global vid
handles.t=timer('ExecutionMode','fixedRate' ,'TimerFcn', {@TimeUpdate,handles},'Period',1);
start(handles.t);
set(gcf, 'DeleteFcn', {@DeleteFcn, handles.t});
function TimeUpdate(obj,eventdata,handles)
global vid
axes(handles.axes2)
start(vid);
im=getdata(vid,1);
imshow(im);
guidata(hObject, handles);
function DeleteFcn(hObject, eventdata, t)
stop(t);
delete(t);
clear all;
The problem is I just can capture image only one time when I push capture button and after that nothing happened(there are no new images appear in axes2).I tried to increase the Period to 5s and remove this row: axes(handles.axes2) in TimeUpdate function and the GUI run correctly but images is no more stored in axes2.But I want to store image in axes 2 and the Period is still 1s or less.Can you tell me how can I do that. Thanks a lot.
0 个评论
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!