High-Level Snap Functions

NI IMAQ

High-Level Snap Functions

A snap acquires a single image into a memory buffer. Snap functions include imgSnap and imgSnapArea. Use these functions to acquire a single frame or field to a buffer. To use these functions, you must have a valid session handle.

When you invoke a snap, it initializes the device and acquires the next incoming video frame (or field) to a buffer. Use a snap for low-speed or single-capture applications in which ease of programming is essential.

The following figure illustrates a typical snap programming order.

The hlsnap.c example demonstrates how to perform a single snap using imgSnap. The example opens an interface and a session and then performs a single snap. The buffer pointer that is passed to imgSnap is initialized to NULL, which instructs imgSnap to automatically allocate a buffer for the image. The size of the buffer is calculated based on the ROI and the rowPixel attributes: ROI height multiplied by rowPixel multiplied by the number of bytes per pixel. When you open a session, the ROI values are initialized from the acquisition window (ACQWINDOW) dimensions that are configured in MAX. The ACQWINDOW dimensions vary depending on the type of camera you are using.

The sample then calls a process function to analyze the image. When the program is finished, it calls imgClose with the interface handle and sets the freeResources flag to TRUE. This instructs NI-IMAQ to free all of the resources associated with this interface, which releases the session as well as the memory buffer allocated by imgSnap.