LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Capturing still images on webcam

Based on several topics I've read here I've adjusted and put together something that captures still images from a webcam.... sometimes...

 

The problem is that it will work great only about half the time.  The other half it doesn't seem to save the image it.  The file with the correct name will be there, but there will be no picture.  It just shows up blank in the Windows Picture and Fax Viewer.  I'm not getting any errors (I realize that there is no error dialog in the snippit I've included but it's in the one I'm working with).  Any ideas of what might be causing this?

0 Kudos
Message 1 of 12
(3,482 Views)

You're doing a lot of DLL calls to capture from a webcam. Typically the way NI recommends getting webcam images is using our Vision Acqusition Software (generally, the IMAQ drivers). If you don't want to/can't purchase them then you're working somewhat outside of our support. I can tell you some guesses though. Typically cameras we work with in our driver can Snap (still image) or Grab (video frames). In the case of a Snap there is typically a good amount of lag time before you can snap again. For starters to test if it's an error or a timing issue, add a 10 second delete between each consecutive Snap. If it still has the same proportion of images missing, then there's a problem with your code (could be lots of things); if all the images are there, you know it's just a timing issue. You can make your own error checking in your code to watch for that and ignore DLL calls which produce an image which has no data.

0 Kudos
Message 2 of 12
(3,452 Views)

That may be one problem that I've yet to come by as I haven't attempted to snap any images consecutively close together yet...

 

Let me explain what's currently happening.  I'll run the VI and snap a picture, then the correct file name/type will show up in the defined directory.  Let's say this time it worked and a picture shows up.... then I stop the VI.  Now I start it up and repeat the same process but instead the picture file is empty.  It seems random that when I start up the VI it will work or not work.

 

I wish I was able to get and use the Vision Acquisition Software, but it's just not in the budget right now.  Any suggestions would be appreciated, thanks.

0 Kudos
Message 3 of 12
(3,448 Views)

I still think it could be a timing problem. Try doing the same thing with about a minute inbetween each save. It's also possible there's a problem with saving. A similar behavior will occur if the file isn't being properly closed. Try your basic debugging/troubleshooting techniques. Probe wires, use alternative outputs, try alternative methods to perform the file I/O (different VIs that do the same thing).

0 Kudos
Message 4 of 12
(3,428 Views)

So far it seems to be a lot more reliable by extending the timing.  I am still getting a few blank snaps here and there but it has helped a lot.

 

I've noticed that it may be saving dupilcate pictures now.  It takes ~70 pictures as it runs through the program and it seems that a lot of them are the same picture with a different file name for some reason.  Right now I just have it pointed at myself while I run a test and I don't think I stay *that* still between snaps.

 

I appreciate the halp so far... any idea why this might be occurring?

 

Could it be an issue copying to the clipboard?


Thanks.

0 Kudos
Message 5 of 12
(3,420 Views)

It could be a clipboard issue, it could also be that your error checking is handling "no image" incorrectly. It's hard to say with an issue like that. You're going to have to debug and watch for patterns in which images are duplicates. I imagine they're consecutive (which should make it easier to debug).

0 Kudos
Message 6 of 12
(3,409 Views)

This project is a proof of concept I'm doing for developing some new automated testing techniques and so ideally if we get the go ahead we'll be able to purchase the appropriate software and equipment.

 

I'm still have some issues with timing and "blank" snaps, but overall it works alright.  Also as a note to the next thing I'm going to ask, I've been using a cheap Logitech webcam from home just to get a demo working.

 

If we were to buy a better quality/faster camera and use the NI software specifically designed for snapping/grabbing images, what would be an approximate guess for the wait time before consecutive snaps could be copied and saved.

 

I need to show in my presentation of this test method that it will save the company time/money/etc.  You know the usual, but right now with the current set up there is almost a 20 second delay between snaps to ensure a capture.  It makes the length of the test nearly 40 minutes; where as it takes about 3 minutes to do the test if you reduce the time between captures to about 1 second or so (here I get a capture half or less than half the time).

 

If anyone can give me an idea about what sort of execution speed this can run at I'd be greatful.  Thanks.

 

0 Kudos
Message 7 of 12
(3,378 Views)

I just found a way to make it impossible for that "blank" image to apprear.  Although, there is still some problems with getting duplicate images.  I can now snap a picture ever 2 seconds on average and successfully save the file.

 

First off I made a lot of adjustments to the code I posted above.  I broke it down into subVIs and got rid of the event structure altogether (it just didn't work with what I needed this for).

What I did was put a while loop around the capture frame (third frame inside the event structure on the above code).  Then I compared the size of the image to some small number.  For me, 10 worked.  So if the X and Y of the image was greater than 10 it went on otherwise it loops back and tries to save the picture again.

 

I suppose it's possible to be caught in an infinite loop if the picture is less than 10 but none of my images will be.  Maybe this or a variation of this tactic will be useful for someone else.

 

0 Kudos
Message 8 of 12
(3,371 Views)

If you need a more frequent acquisition you might want to use a Grab instead of a Snap. Grab gets a stream of images and typically operates much faster (~15+fps).

0 Kudos
Message 9 of 12
(3,350 Views)

Can you control the rate at which it grabs?  I don't want it to be be turned on and grab images at whatever speed until off.  I need to have precise control of when it grabs or snaps an image.

0 Kudos
Message 10 of 12
(3,343 Views)