Losing frames when "getdata"

4 Ansichten (letzte 30 Tage)
Giorgos Papakonstantinou
Giorgos Papakonstantinou am 4 Okt. 2013
Kommentiert: Ramu Pradip am 7 Okt. 2021
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 Kommentar
Ramu Pradip
Ramu Pradip am 7 Okt. 2021
I have the same problem as well. Any tips ?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 4 Okt. 2013
Perhaps wait() on the timer after you stop() it.
  2 Kommentare
Giorgos Papakonstantinou
Giorgos Papakonstantinou am 4 Okt. 2013
Thank you Walter, but who is going to wait for what?
Giorgos Papakonstantinou
Giorgos Papakonstantinou am 4 Okt. 2013
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

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by