LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Grabbing and image from a live webcam

I am doing a school project on image correction. Previously we corrected image motion by taking a video file, extracting a single frame and using that frame as a template where i could drag and select the object and obtain its coordinates. Now in a different function each frame of the video was extracted and the object along with its coordinates where found. The coordinates of the template image then had coordinates of said object in each particular frame subtracted from it. This is accomplished using for loops and then saved into a new video file. This code completely works, might not be the best way but it works.

 

Now i am trying to do nearly the exact same thing expect i take a picture with a camera and use that as my template image instead of extracting a single frame (this part of the code works). Instead of a video file i have a live feed from my webcam. I have the template working but i am unable to extract a frame from my webcam to have it go through my motion correction function.

 

i am unable to get an image from IMAQdx Get Image VI and place it into either

IMAQ ExtractSingleColorPlane VI, IMAQ Match Pattern 2 VI to be corrected. I placed everything in a while loop and at either ExtractSingleColorPLane or pattern match i get an invalid image.

 

The purpose is to have a corrected live feed of my webcam at the end.

 

Any help would be greatly appreciated on this issue. Thank you

0 Kudos
Message 1 of 12
(8,062 Views)

Project2-1d.png

Screenshot (14)_LI.jpg

 Sorry here is a picture of my problem, i am terrible at this.

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

Attach your VI.  A blurry picture that we can't inspect, edit, test hampers our ability to help.  Do you have the LabVIEW Vision Development Module and Vision Acquisition Software installed?

 

Bob Schor

 

 

0 Kudos
Message 4 of 12
(7,971 Views)

Sorry and i have vision development module 2019 installed. However i am unsure about the Vision acquisition software. I am unsure about the big while loop around the nested for loops. i was trying random things to get it to work.

0 Kudos
Message 5 of 12
(7,967 Views)

@Mitch899 wrote:

Sorry and i have vision development module 2019 installed.


You need Vision Acquisition Software (VAS) to "acquire" images from a camera.  Since you are using a WebCam, you will need IMAQdx.  When you open the Vision and Motion Palette on the Block Diagram, do you see a sub-Palette called IMAQdx?  If you open NI-MAX and expand the Software tab, do you see IMAQ and IMAQdx (with a camera icon) listed, about half-way down?  If you open the NI License Manager, do you see an entry for Vision Acquisition Software?

 

If the answer to any of these (and especially if to all of these) is "No", then you are missing the Vision Acquisition Software and will not be able to acquire Images from a Camera using LabVIEW.

 

Bob Schor

0 Kudos
Message 6 of 12
(7,933 Views)

Yes i have Vision Acquisition software 19.5, NI-IMAQ, and NI-IMAQdx.

0 Kudos
Message 7 of 12
(7,926 Views)

OK.  Then you should be able to get images from a WebCam (or your PC's Camera).

  1. Plug in the Camera to your computer (skip if using the Computer's camera).
  2. Open MAX.
  3. In Devices and Interfaces, choose your Camera.
  4. In the right-hand pane, click "Snap" (= take a snapshot).

Do you have an Image?  Then your camera is working and you should be able to acquire images with LabVIEW.

 

  1. Open LabVIEW.  Create a new VI.
  2. Look at Palettes for Front Panel.  Find Vision, open, and put down an Image Display.
  3. Go to Block Diagram.  From Vision and Motion:  Vision Utilities, Image Management, drop IMAQ Create -- this creates a (named) Buffer to hold an Image.  Create a name for this Buffer (upper left input). 
  4. From IMAQ-dx, drop Snap to right of IMAQ Create.  Connect Error In and Image In to Error Out and Image Out of IMAQ Create.
  5. Right-click Session In of Snap, choose Create Constant.  See the little triangle?  Click it, and choose the Camera you want to use.
  6. Wire the Image Indicator (from the Front Panel) to Image Out of the Snap.
  7. Run the Vi.  You should see an Image.

Bob Schor

0 Kudos
Message 8 of 12
(7,916 Views)

Thank you. My issue is not necessary getting a video feed from the camera. But trying to put the video feed through my image correction function and receiving a video feed out at the end. (the video feed out the end probably has issues to)

 

The way i did this previously was reading each frame from a video file and placing it through my function and then writing each corrected frame to a new video file.

 

However with a live feed from camera i cannot get a valid image to place into IMAQ ExtractSingleColorPlane VI.

 

I was trying to use  IMAQ AVI2 Read Frame VI (as i did reading frames from a pre-made video file in my last project) but trying to get some sort of frame out of the live feed from the camera is what has me stumped. I keep getting an invalid image error.

 

I suspect there is something i may not understanding about the live freed from the camera.

0 Kudos
Message 9 of 12
(7,895 Views)

OK, I confess that I didn't look at your code in my earlier replies, as it sounded like Image Acquisition was the problem.  Now I have looked, and it looks strange, as though you "draw the box" not around the actual Image but around a more-or-less blank Image.

 

I haven't done Image isolation for a few years, so I'll have to dig into my old code and see if I can come up with some general principles for you to try.  Stay tuned ...

 

Bob Schor

0 Kudos
Message 10 of 12
(7,880 Views)