Losing frames when "getdata"

4 次查看(过去 30 天)
Giorgos Papakonstantinou
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 个)

Walter Roberson
Walter Roberson 2013-10-4
Perhaps wait() on the timer after you stop() it.
  2 个评论
Giorgos Papakonstantinou
Thank you Walter, but who is going to wait for what?
Giorgos Papakonstantinou
I added |flushdata | in my switchoff callback. However, the problem persists. I think that the actual problem lies on the fact I am calling other functions while the timer is executing.
Therefore, I the interruption of the timer is causing the problems. How can I interrupt the timer?
Apart from that I cannot do much while I try to debug my code.
function switchoff(varargin)
flushdata(vid);
stop(vid)
end
Thank you

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by