Thread Subject: Matlab keeps timing out when I use it to control a webcam

Subject: Matlab keeps timing out when I use it to control a webcam

From: Zoe Langham

Date: 16 Jul, 2008 13:45:04

Message: 1 of 5

Hello,

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

Subject: Matlab keeps timing out when I use it to control a webcam

From: Jason Brown

Date: 16 Jul, 2008 15:30:23

Message: 2 of 5

"Zoe Langham" <paxzl@nottingham.ac.uk> wrote in message
<g5ku10$8b3$1@fred.mathworks.com>...
> Hello,
>
> 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

Subject: Matlab keeps timing out when I use it to control a webcam

From: Zoe Langham

Date: 17 Jul, 2008 15:42:01

Message: 3 of 5

"Jason Brown" <jeb8828@rit.edu> wrote in message
<g5l46f$nqa$1@fred.mathworks.com>...
> "Zoe Langham" <paxzl@nottingham.ac.uk> wrote in message
> <g5ku10$8b3$1@fred.mathworks.com>...
> > Hello,
> >
> > 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


Subject: Matlab keeps timing out when I use it to control a webcam

From: Mark Jones

Date: 22 Jul, 2008 13:00:16

Message: 4 of 5

Hi 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


Zoe Langham wrote:
> Hello,
>
> 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

Subject: Matlab keeps timing out when I use it to control a webcam

From: Zoe Langham

Date: 23 Jul, 2008 12:40:22

Message: 5 of 5

Hi 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.jones@mathworks.com> wrote in message
<4885D9E0.3060404@mathworks.com>...
> Hi 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/f
6-119409.html
> for an example of how to use callback functions.
>
> Mark
>
>
> Zoe Langham wrote:
> > Hello,
> >
> > 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

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com