| MIL 10 User Guide
| Customize Help

Grabbing images



See also
Availability
Available in MIL-Lite

Available in MIL

Many applications depend on the ability to grab an image for later analysis or inspection. With MIL, you use an allocated digitizer to grab from a video source (typically a video camera). To allocate a digitizer, use MdigAlloc() and specify a digitizer configuration format (DCF) that is compatible with the output format of your camera. This configures the required acquisition paths (camera interface) on the frame grabber so that they can accept input from the camera. With a call to MdigGrab(), you can then grab into a grab image buffer (an image buffer with an M_GRAB attribute).

Allocate the grab image buffer on the same system, and of the same data format, as the digitizer. For color cameras, use color image buffers.

By default, when MdigGrab() is issued, it grabs a complete frame of data, as defined by the DCF used to allocate the digitizer and not by the size of the image buffer. For more details on how to grab with the digitizer, see Chapter 23: Grabbing with your digitizer.

Continuous grabbing and adjusting your camera

When adjusting and focusing your camera, grabbing a single frame at a time can be tedious. MIL features a continuous grab function, MdigGrabContinuous(), that grabs image frames into a specified buffer until you issue MdigHalt(). Since you are grabbing continuously into the same buffer, this function is only really useful if you select the buffer to a display, using MdispSelect(), prior to starting the continuous grab, so that you can view what is being grabbed.

If your camera supports remote lens adjustment, you can use MdigFocus() to automatically adjust the lens motor of the camera to achieve optimum focus in your images. For more information, see the Auto-focusing section of Chapter 23: Grabbing with your digitizer.

Sequential grabbing

Typically, you need to grab and process images continuously. To ensure that no frames are missed, the MdigProcess() function allows you to grab images sequentially, store them into a list of image buffers, and process them as they are being grabbed.

MdigProcess() has the same requirements as MdigGrab(), except MdigProcess() accepts an array of grab image buffers and can cause a user-defined function to be called after an image has been grabbed into any of the image buffers. MdigProcess() can round-robin through the buffers; that is, after it has finished grabbing into the last buffer in the array, it begins grabbing again into the first buffer.

For more information and examples, see the Multiple buffering subsection of the Grabbing and processing section of Chapter 23: Grabbing with your digitizer.

An example

The following example grabs a single image from the camera.

/* Allocate a system for a Matrox Morphis board. Use a different */
/* value or "M_DEFAULT" for other types of systems.              */
MappAlloc(M_NULL, M_DEFAULT, &MilApplication);
MsysAlloc(M_SYSTEM_MORPHIS, M_DEFAULT, M_DEFAULT, &MilSystem);
MdispAlloc(MilSystem, M_DEFAULT, MIL_TEXT("M_DEFAULT"), M_WINDOWED, &MilDisplay);

/* Allocate a digitizer for RS170 camera. Use a different */
/* value or "M_DEFAULT" for other types of cameras.       */
MdigAlloc(MilSystem, M_DEV0, MIL_TEXT("M_RS170"), M_DEFAULT, &MilDigitizer);

/* Allocate an image buffer with the default dimensions. */
MbufAlloc2d(MilSystem, 512, 512, 8 + M_UNSIGNED, M_IMAGE + M_DISP + M_GRAB, &MilImage);

/* Display the image buffer. */
MdispSelect(MilDisplay, MilImage);

/*Grab an image into image buffer*/
MdigGrab(MilDigitizer, MilImage);


/* Free all allocations */
MbufFree(MilImage);
MdigFree(MilDigitizer);
MdispFree(MilDisplay);
MsysFree(MilSystem);
MappFree(MilApplication);