Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Interfacing Camera to Matlab

Subject: Interfacing Camera to Matlab

From: Kushagra Garg

Date: 25 Aug, 2008 04:50:16

Message: 1 of 4

I tried to interface Gemini usb 2.0 webcam to matlab using following commands--

cam=videoinput('winvideo')
It gives the following output.

Summary of Video Input Object Using 'USB2.0 Web Camera'.

   Acquisition Source(s): input1 is available.

  Acquisition Parameters: 'input1' is the current selected source.
                           10 frames per trigger using the selected source.
                           'RGB24_640x480' video data to be logged upon START.
                           Grabbing first of every 1 frame(s).
                           Log data to 'memory' on trigger.

      Trigger Parameters: 1 'immediate' trigger(s) on START.

                  Status: Waiting for START.
                           0 frames acquired since starting.
                           0 frames available for GETDATA.



start(cam);
preview(cam);
Till this point it works fine.

frame=getsnapshot(cam);
imshow(frame);

The image shown is completely black.The array frame has all RGB values 0.

Subject: Interfacing Camera to Matlab

From: Dave Tarkowski

Date: 25 Aug, 2008 13:33:24

Message: 2 of 4

Kushagra Garg wrote:
> I tried to interface Gemini usb 2.0 webcam to matlab using following commands--
>
> cam=videoinput('winvideo')
> It gives the following output.
>
> Summary of Video Input Object Using 'USB2.0 Web Camera'.
>
> Acquisition Source(s): input1 is available.
>
> Acquisition Parameters: 'input1' is the current selected source.
> 10 frames per trigger using the selected source.
> 'RGB24_640x480' video data to be logged upon START.
> Grabbing first of every 1 frame(s).
> Log data to 'memory' on trigger.
>
> Trigger Parameters: 1 'immediate' trigger(s) on START.
>
> Status: Waiting for START.
> 0 frames acquired since starting.
> 0 frames available for GETDATA.
>
>
>
> start(cam);
> preview(cam);
> Till this point it works fine.
>
> frame=getsnapshot(cam);
> imshow(frame);
>
> The image shown is completely black.The array frame has all RGB values 0.

Is the preview window open when you call getsnapshot?

Some cameras, notably web cams, start out with black frames. It takes
the automatic gain control a couple frames to adjust and give you a
proper image. This is most likely happening when you start the video
preview, but since it only last a few frames, you don't really notice it.

If the preview window is closed when you call getsnapshot, the camera is
not acquiring data therefore the automatic gain control isn't working.
Since it takes a few frames to get good images back, you'll always get
black images that way. However, there a few workarounds. One, you can
leave the preview window open while calling getsnapshot. This leaves
the camera active, and you should get valid images back.

If you don't want to have the preview window open, you can use the
manual triggering mode of the toolbox. Try this:

 >> triggerconfig(cam, 'manual');
 >> start(cam);
 >> pause(.5); % Wait for the camera to adjust the AGC
 >> frame = getsnapshot(cam);
 >> stop(cam);

You can see
http://www.mathworks.com/products/imaq/demos.html?file=/products/demos/shipping/imaq/demoimaq_Getsnapshot.html
for more information on using manual triggering and getsnapshot.

-Dave

Subject: Interfacing Camera to Matlab

From: Kushagra Garg

Date: 25 Aug, 2008 16:47:19

Message: 3 of 4

It works by keeping the preview window open!!!!!
Thanks a lot!!!

I have one more query--
When I try to take continuous images,after taking 6 to 7 images,the cam gives a timeout.
Actually,I want to get a frame rate of 10-12 frames per second but it's giving timeout.
Any solution?

Subject: Interfacing Camera to Matlab

From: Dave Tarkowski

Date: 25 Aug, 2008 19:31:01

Message: 4 of 4

Kushagra Garg wrote:
> It works by keeping the preview window open!!!!!
> Thanks a lot!!!
>
> I have one more query--
> When I try to take continuous images,after taking 6 to 7 images,the cam gives a timeout.
> Actually,I want to get a frame rate of 10-12 frames per second but it's giving timeout.
> Any solution?

I'm not sure that I understand your problem. Can you post some code
that reproduces the issue and the exact error message that you are
receiving?

-Dave

Tags for this Thread

No tags are associated with this thread.

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.

Contact us