Acquire or Read an Image

NI Vision for LabVIEW Basics

Acquire or Read an Image

After you create an image reference, you can acquire an image into your imaging system in three ways. You can acquire an image with a camera through your image acquisition device, load an image from a file stored on your computer, or convert the data stored in a 2D array to an image. VIs that acquire images, load images from file, or convert data from a 2D array automatically allocate the memory space required to accommodate the image data.

Use one of the following methods to acquire images with a National Instruments image acquisition device:

  • Acquire a single image using the IMAQ Snap VI. When you call this VI, it initializes the image acquisition device and acquires the next incoming video frame. Use this VI for single capture applications where ease of programming is essential.
  • Acquire images continually through a grab acquisition. Grab functions perform an acquisition that loops continually on one buffer. Use the grab functions for high-speed image acquisition. Use the IMAQ Grab Setup VI to start the acquisition. Use the IMAQ Grab Acquire VI to return a copy of the current image. Use the IMAQ Stop VI to stop the acquisition.
  • Acquire a fixed number of images using the IMAQ Sequence VI. IMAQ Sequence acquires one image after another until it has acquired the number of images you requested. If you want to acquire only certain images, supply IMAQ Sequence with a table describing the number of frames to skip after each acquired frame.
Note   When you are finished with the image acquisition, you must use the IMAQ Close or IMAQdx Close Camera VI to release resources associated with the image acquisition device.

Use the IMAQ ReadFile VI to open and read data from a file stored on your computer into the image reference. You can read from image files stored in a standard format—such as BMP, TIFF, JPEG, JPEG2000, PNG, and AIPD—or a nonstandard format you specify. In all cases, the software automatically converts the pixels it reads into the type of image you pass in.

Use the IMAQ Read Image and Vision Info VI to open an image file containing additional information, such as calibration information, template information for pattern matching, or overlay information. Refer to Performing Machine Vision Tasks ,for information about pattern matching templates and overlays.

You also can use the IMAQ GetFileInfo VI to retrieve image properties—image size, pixel depth, recommended image type, and calibration units—without actually reading all the image data.

Use the IMAQ AVI Open and IMAQ AVI Read Frame VIs to open and read data from an AVI file stored on your computer into the image reference. NI Vision automatically converts the pixels it reads into the type of image you pass in.

Note   When you are finished with the AVI file, you must use IMAQ AVI Close to release resources associated with the AVI file.

Use the IMAQ ArrayToImage VI to convert a 2D array to an image. You also can use the IMAQ ImageToArray VI to convert an image to a LabVIEW 2D array.