Losing frames when "getdata"
Show older comments
In a simple user interface I want to include a capture the image from my camera. To do this I have two push button. A start button to start acquiring the live image and a stop button to stop acquiring the image.
The basic problem is that I get the error:
GETDATA timed out before FRAMES were available.
And this is because I interrupt the TimerFcn of the vid. How can I tackle this?
Here is what I do:
function mycam
S.fh = figure('units','pixels',...
'position',[300 300 400 400],...
'menubar','none',...
'name','stopwatch',...
'numbertitle','off');
S.pb(1) = uicontrol('style','push',...
'units','pixels',...
'position',[10 10 85 30],...
'fontsize',14,...
'string','start',...
'CallBack',@switchon);
S.pb(2) = uicontrol('style','push',...
'units','pixels',...
'position',[105 10 85 30],...
'fonts',14,...
'str','stop',...
'Callback',@switchoff);
NumberFrameDisplayPerSecond=20;
vid=videoinput('winvideo',1);
set(vid, 'timerFcn',@updater,...
'TimerPeriod', 1/NumberFrameDisplayPerSecond,...
'FramesPerTrigger',1,...
'TriggerRepeat',Inf);
triggerconfig(vid, 'Manual');
function updater(varargin)
persistent stream
trigger(vid);
IM=getdata(vid,1,'uint8');
if isempty(stream)
stream = imshow(IM);
else
set(stream, 'CData', IM)
end
end
function switchon(varargin)
start(vid)
end
function switchoff(varargin)
stop(vid)
end
end
Thank you
1 Comment
Ramu Pradip
on 7 Oct 2021
I have the same problem as well. Any tips ?
Answers (1)
Walter Roberson
on 4 Oct 2013
0 votes
Perhaps wait() on the timer after you stop() it.
Categories
Find more on Image Data Acquisition in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!