I am using Matlab to control a webcam that takes images
during my experiments. The commands to control the camera
are nestled in a while loop, so that with each loop of the
program, an image is taken. The whole loop usually takes
between 2-4 seconds for each cycle when the program is
working correctly.
However, every now and then there will be a large pause
between cycles, where Matlab appears to be struggling.
Often Matlab will recover from the pause (although this
could be anywhere from 10-70 seconds later), but
occasionally the pause will lead to the program timing out
(often between 500 and 1000 seconds after starting the
program), and the following error message is displayed:
??? GETDATA timed out before FRAMES were available.
Error in ==> isothermal_scatteringmod_hum at 147
start(vid);imagedata=getdata(vid,1);flushdata(vid);stop
(vid);
Error event occurred at 16:18:24 for video input object:
YUY2_160x120-winvideo-1.
GETDATA timed out before FRAMES were available.
I'm using version R2007a of Matlab on a PC running on
Windows XP. The webcam is a Philips SPC1000NC.
Does anyone know what could be causing this, and more
importantly, is there a solution?!
Many thanks,
Zoe
You could add a timer within the loop to make sure that you
are getting an even frame rate which would help standardize
your experiment. Setting this wait time could also solve
your problem by assuring you are not oversampling the webcam.
Matlab "timing out" with capturing data every 2-4 sec
doesn't make sense. It might be running the loop quicker
than you think and you're maxing out the frame rate of the
webcam. Use tic/toc to time the capture and see where you're
getting an issue.
-Jason
Hi Jason,
Thanks for the suggestions.
My program already has tic/toc in it so that I can plot the
data I get against time while the experiment is running.
Therefore I'm fairly certain that the data capture is
occuring at the 2-4 second rate, and not running away with
itself. I've tried putting a pause in my program before,
but it doesn't seem to make a difference in Matlab timing
out.
I'm not sure how the program can be maxing out the frame
rate of the camera as it seems to work fine for large
chunks of the experiment, and I'm only taking one picture
in each program loop. According to the camera
specification, it should be able to cope with a frame rate
of 60 fr/sec - and I'm definitely working well below this.
I don't suppose you have any other suggestions, I'm at a
complete loss!
Zoe
Instead of putting START inside the loop, it would be better if you set
your acquisition to have a large (possibly inf) TriggerRepeat and set it
for manual triggering. Then before your loop, you can call START which
can take some time, and then inside your loop call TRIGGER which takes
much less time. See the following for an example:
http://www.mathworks.com/support/solutions/data/1-2JB9MK.html
Also, you can go one step further and use a FramesAcquiredFcn with a
FramesAcquiredFcnCount of 1 to have a callback function called after
every frame acquired. Then in your callback function you can call
GETDATA and TRIGGER and avoid a loop all together. See
http://www.mathworks.com/access/helpdesk/help/toolbox/imaq/f6-119409.html
for an example of how to use callback functions.
Mark
Thank you for the suggestions - I've set the TriggerConfig
to Manual and set an infinite TriggerRepeat outside the
loop and it is now working perfectly.
Cheers!
Zoe
Mark Jones <mark....@mathworks.com> wrote in message
<4885D9E0...@mathworks.com>...
my question is how could you do something similar while still being able to use the wait function? In my experience, when I try and use the wait function after a manual trigger with infinite trigger repeat the wait function will always time out.
A work around is simply using a pause set equal to the exposure time of the device for the frame I'm trying to get but that doesn't let me know if any errors have occurred. Last ditch effort is to do what Zoe was doing and start the vid every loop iteration so that the video's running flag is set to On every time (which seems to be the real issue).
Please see pseudocode below for better explanation:
<code>
start(vid);
for( i = 1:FramesToCapture)
trigger(Vid);
wait(Vid,5);
PerformAnotherAction();
end
</code>
work around
<code>
start(vid);
for( i = 1:FramesToCapture)
trigger(Vid);
pause(VidExposureTime);
PerformAnotherAction();
end
</code>
Last ditch effort
<code>
for( i = 1:FramesToCapture)
start(vid);
trigger(Vid);
wait(Vid,5);
PerformAnotherAction();
end
</code>
"Zoe Langham" <pa...@nottingham.ac.uk> wrote in message <g5np89$9se$1...@fred.mathworks.com>...