To optimize application performance when grabbing, you can:
Set the grab mode.
Perform multiple buffering.
When grabbing data with MdigGrab(), you can control the synchronization by setting the M_GRAB_MODE control type of MdigControl() to M_SYNCHRONOUS, M_ASYNCHRONOUS, or M_ASYNCHRONOUS_QUEUED (if supported).
If the grab mode is set to M_SYNCHRONOUS, your application will be synchronized with the end of a grab operation. In other words, your application will wait until the grab has finished before executing the next function.
If the grab mode is set to M_ASYNCHRONOUS, your application will not be synchronized with the end of a grab operation. This option allows other functions to execute while you are still grabbing. This is a useful option when performing multiple buffering, a technique whereby you can grab data into one buffer while processing previously grabbed buffers (discussed below). Note, another call to MdigGrab() before the current grab has finished will cause your application to wait until the current grab has finished.
If your frame grabber supports queuing, you can set the grab mode to M_ASYNCHRONOUS_QUEUED; if another grab is issued before the first one is finished, the grab will be queued on-board, allowing you to perform other processes while waiting for the next MdigGrab() to be executed. Note, you can still force your application to wait until the end of a grab before executing an operation, by calling MdigGrabWait().
Note that MdigGrabContinuous() is by definition asynchronous since you must use MdigHalt() to stop the grab.
Multiple buffering involves grabbing into one image buffer while processing previously grabbed images. This technique allows you to grab and process images concurrently.
To perform multiple buffering in MIL, you can use MdigProcess(). It allows you to use a list of previously-allocated buffers to hold a series of sequentially grabbed images and process them as they are being grabbed. These grabs can either continue until stopped (using MdigProcess() with M_START to start and then M_STOP to stop) or continue until all buffers in the list are filled (using MdigProcess() with M_SEQUENCE). In the former case, MdigProcess() grabs round-robin through the list of buffers, however care must be taken to ensure that the average time it takes to process a frame is not greater than the frame rate of a camera, so that frames will not be missed.
MdigProcess() hooks a user-defined function to the modification of any buffer in the specified list. So every time a new frame is grabbed in a buffer in the list, the user-defined function is called. If the hook-handler function modifies the buffer that called it, the hook-handler function for that buffer will not be called again until that buffer is modified by a new grab. This is to avoid infinite recursive calls being generated. Note that, if the buffer is modified by some function other than the one hooked to it, the hooked function will be called. In addition, if the hook-handler function modifies another buffer which has another function hooked, that function will be called.
Note, processing is generally faster if the buffer is not on the display.
The following example shows you how to perform multiple buffering.