| Customize Help
| Save Settings

MdigProcess



Function Map
Synopsis
Grab frames of data sequentially into a list of image buffers or containers, and process them with a user-defined function as they are grabbed.
Syntax
void MdigProcess(
MIL_ID DigId, //in
const MIL_ID *DestContainerOrImageBufArrayPtr, //in
MIL_INT ImageCount, //in
MIL_INT64 Operation, //in
MIL_INT64 OperationFlag, //in
MIL_DIG_HOOK_FUNCTION_PTR HookHandlerPtr, //in
void *UserDataPtr //in-out
)
Description

This function uses the specified digitizer to acquire frames of data and stores them sequentially in a list of image buffers or a list of containers. It also hooks a user-defined function to the modification of any buffers/containers in the specified list. The user-defined function is therefore called every time a new frame is grabbed.

When grabbing an image, you should use an image buffer as a destination. When grabbing any other type of data (such as 3D data), you should use a container as a destination. You can determine what type of MIL object the digitizer is designed to grab into using MdigInquire() with M_TARGET_BUFFER_OBJECT.

If set synchronously, MdigProcess() will block the thread until the list of sequential grabs has completed. If set asynchronously, the buffers/containers are prepared, and then control is returned to the calling thread while, in the background, the grabs will begin.

The grabs can stop at the end of the list, after a predefined number of grabs occur, or when a stop instruction is explicitly given. In the latter two cases, grabbing occurs in a round robin fashion; buffers/containers are filled with the grabbed data typically in the order they are stored in the list, wrapping around to the first buffer/container in the list once the last buffer/container in the list is filled.

The index of the modified buffer/container can be inquired using MdigGetHookInfo() with M_MODIFIED_BUFFER + M_BUFFER_INDEX. The MIL identifier of the modified buffer/container can be inquired using MdigGetHookInfo() with M_MODIFIED_BUFFER + M_BUFFER_ID. To identify whether the modified buffer/container (that is, the current frame) is corrupt (for example, because a packet was not received successfully), use MdigGetHookInfo() with M_CORRUPTED_FRAME.

Once a frame of data is grabbed into a buffer/container, MIL will not grab into that buffer/container again until the hook function has finished processing it. Once the hook function finishes executing, the buffer/container becomes available for MIL to grab into it. If all buffers/containers are filled with data and are waiting to be processed by the hook function, MIL waits for the next available buffer/container (typically the next buffer/container in the list) before grabbing another frame of data.

If the average time it takes to process a frame of data is greater than the frame rate of a camera, frames will eventually be missed. You can determine how many of the processing buffers are currently available using MdigInquire() with M_PROCESS_PENDING_GRAB_NUM.

To grab until a stop instruction, you must call MdigProcess() with M_START; when you want to stop grabbing, you must call MdigProcess() with M_STOP. Once the stop instruction is issued, no more frames will be grabbed. Buffers/containers that store unprocessed frames are processed before the original calling thread continues, unless the stop instruction is issued by calling MdigProcess() from within the hook-handler function itself (in which case, processing is completed while the original calling thread continues).

By default, buffers/containers are processed sequentially, in the order into which grabbed; a single instance of the hooked user-defined function will run on a single thread, processing one buffer/container at a time. When running on a computer with multiple CPU cores, you can have the grabbed buffers/containers handled by different instances of the user-defined function running on different threads. To do so, use MsysControl() with M_MODIFIED_BUFFER_HOOK_MODE set to M_MULTI_THREAD.

If you are grabbing from multiple cameras simultaneously with the hook function executing in single-threaded mode, each instance of MdigProcess() will use its own thread to execute an instance of the hooked function. Additionally, many MIL functions are transparently multi-threaded. These factors can combine to generate a large number of threads, potentially slowing down your application. Since having the hook function execute in multi-threaded mode can multiply the number of threads generated by the number of physical CPU cores in your computer (or, optionally, the number of threads that you specify with M_MULTI_THREAD), it is often more efficient to have the hook function execute in single-threaded mode. If you are considering multi-threaded mode, you should benchmark your application under real-world conditions before making a final decision.

When processing with the hook function executing in multi-threaded mode, it is possible for buffers/containers to be grabbed and processed in a different order than they are stored in the list because they are processed at different rates. For example, if the list contains 3 buffers and all of them are being processed, it is possible that processing will finish on the second buffer in the list before the first buffer in the list. In this case, MIL will grab into the second buffer and cue it for processing instead of waiting for the first buffer to become available.

When the specified digitizer is set to perform triggered grabs, the default behavior of the function is to wait for a trigger event before grabbing each frame. To grab all or a specific number of frames per trigger, set the OperationFlag parameter to M_TRIGGER_FOR_FIRST_GRAB and use the Operation parameter to specify how many frames to grab per trigger. To grab continuously after just one trigger, use + M_FRAMES_PER_TRIGGER() set to M_INFINITE.

Note that if the camera is in triggered mode, you should not also use the digitizer in triggered mode.

It is not recommended to change the digitizer settings of the digitizer currently being used when grabs are still pending.

[Host system]

When grabbing from a video or directory of files, once the last image is grabbed, grabbing will restart from the beginning of the video or from the first file in the directory.

Note that this function reference has not been updated for a MIL system added during a MIL update. Refer to the MIL system's release note to see which MIL system’s documentation you should use in its place and any possible differences.
Parameters
This function is not supported on the selected boards.
This function reference has not been updated for the selected MIL system. To show the content of this page, choose a second MIL system; refer to the MIL system's release note to see which MIL system’s documentation to choose and any possible differences.
Parameters
DigId

Specifies the identifier of the digitizer to be used to perform the grabs.

DestContainerOrImageBufArrayPtr
Accepts the address of one of the following:
  • array of type MIL_ID [optionally, in C++: a reference to a constant std::vector<MIL_ID> ] (and a maximum array rank for C# of 1)
    Required array size:(ImageCount)

Specifies the address of the array containing the identifiers of the image buffers or containers in which to place the grabbed frames of data. Image buffers should be of an appropriate type and depth to hold the grabbed frames of data. To allocate each buffer, use MbufAlloc...() with M_GRAB. To allocate each container, use MbufAllocContainer() or MbufAllocDefault() with M_GRAB.

Note image buffers in the array must not have a region of interest (ROI) associated with them. Using an image buffer with an ROI will cause an error.

function map For specifying the MIL identifiers to grab into
Click to summarizeValue Description MIL system-specific
tooltip (‡)
Click to summarize MIL color image buffer identifier

Specifies the identifier of a color destination image buffer with an M_IMAGE + M_GRAB attribute.

This image buffer must not have a region of interest (ROI) associated with it. Using an image buffer with an ROI will cause an error.

If the grab buffer is smaller than the digitizer's frame size, the image buffer will be filled and all other data will be lost. If the grab buffer is larger than the digitizer's frame size, the buffer will be filled up to the digitizer's frame size. The rest of the buffer will remain untouched.

If you grab into a buffer from a digitizer that outputs data in a format suitable for a container, the first intensity component in the frame of data will be grabbed. If there is no intensity component, the first component that is not metadata will be grabbed.

(summarize)
a c
M10
g h i j k
M10
l m o p r
U27
t
U28
u
U36
v y
U75
aa
MIL system specific

The destination buffer's depth can only be 8 bits per band.

g h i u
U36

The destination buffer's depth can be 8 or 16 bits per band.

c
M10
o v

The width of the destination buffer must be at least 17 bytes. If not, an error will occur.

l m

When dealing with color smart-cameras, the destination image buffer can only be a BGR packed buffer with a 32-bit color depth (allocated using MbufAllocColor() with M_IMAGE + M_GRAB + M_BGR32). When dealing with monochrome smart-cameras, you cannot grab into a MIL color image buffer.

t
U28
Click to summarize MIL container identifier

Specifies the identifier of a container with an M_GRAB attribute.

When grabbing into a container for the first time, MIL will free all existing components and allocate the components required to store the current frame of data. MIL will typically reuse these automatically allocated components during subsequent grabs, unless you add or remove components from the container (in which case all components will be freed and new components will again be allocated for the grabbed data).

MIL will not grab into components of the container that you have allocated manually using MbufAllocComponent(), MbufCopyComponent(), or MbufCreateComponent().

In rare applications, you might configure your camera/3D sensor to transmit components of a different size or format with each grab. If there is any mismatch between the components from the previous grab and those required to store the current frame of data (for example, if the ordering, component type, or size has changed), all components will be automatically freed and new components will be allocated; the components will be assigned new identifiers. You can inquire the new buffer identifiers using MbufInquireContainer() with M_COMPONENT_ID.

If you need the buffer identifier of a component, and it is possible that the components might be reallocated, you should inquire the current buffer identifier after each grab.

(summarize)
a c
U85
o
Click to summarize MIL monochrome image buffer identifier

Specifies the identifier of a monochrome destination image buffer with an M_IMAGE + M_GRAB attribute.

This image buffer must not have a region of interest (ROI) associated with it. Using an image buffer with an ROI will cause an error.

It is not possible to grab into a color-band child buffer (that is, a child buffer created from one band of a color parent buffer) when the parent buffer is packed.

When grabbing into an image buffer, if the grab destination buffer is smaller than the digitizer's frame size, the image buffer will be filled and all other data will be lost. If the grab destination buffer is larger than the digitizer's frame size, the buffer will be filled up to the digitizer's frame size. The rest of the buffer will remain untouched.

If you grab into a buffer from a digitizer that outputs data in a format suitable for a container, the first intensity component in the frame of data will be grabbed. If there is no intensity component, the first component that is not metadata will be grabbed.

(summarize)
a c
M10
g h i j k
M10
l m o p r
U27
t
U28
u
U36
v y
U75
aa
MIL system specific

When using a color camera, the color data is first converted into YUV, and then the Y (luminance) component is stored in the buffer. The color space conversion is done in hardware.

g h i k
M10
l m t
U28
u
U36
y
U75

The destination buffer's depth can only be 8 bits per band.

g h i u
U36

The destination buffer's depth can be 8 or 16 bits per band.

c
M10
j k
M10
l m o p r
U27
v y
U75
aa

The width of the destination buffer must be at least 17 bytes. If not, an error will occur.

l m

The destination buffer can only be an 8-bit monochrome buffer.

t
U28
ImageCount INQ

Specifies the number of buffers or containers in the array.

When using a standard vector (std::vector) overload function in C++, you can pass M_DEFAULT to this parameter and MIL will automatically determine the size based on the number of items in the vector passed to the DestContainerOrImageBufArrayPtr parameter.

Operation

Specifies the type of operation to perform.

function map For specifying the type of operation to perform
Click to summarizeValue Description
Click to summarize M_SEQUENCE +

Grabs a specific number of frames, storing them sequentially in a list of buffers or containers. Grabbing ends once the specified number of frames have been captured.

When using a digitizer set to perform triggered grabs and the OperationFlag parameter is set to M_TRIGGER_FOR_FIRST_GRAB, the function will grab the specified number of frames when the first trigger event occurs.

(summarize)
Click to summarize M_START +

Starts grabbing round-robin into the list of buffers or containers; the grabs will continue until stopped (using MdigProcess() with M_STOP).

When using a digitizer set to perform triggered grabs and the OperationFlag parameter is set to M_TRIGGER_FOR_FIRST_GRAB, the function will, by default, start grabbing all frames when the first trigger event occurs.

(summarize)
Click to summarize M_STOP +

Stops the grab. By default, it also cancels all grabs that might have been queued. Note that cancelled grabs will not trigger the hooked function, but the events for the previous grabs are still processed.

To stop a grab started in synchronous mode, the Operation parameter must be set to M_STOP and the MdigProcess() function called from a separate thread.

(summarize)
Combination value for M_STOP.

You can add the following value to the above-mentioned value to specify that previously queued grabs should not be cancelled when stopping.

function map For M_STOP
Click to summarizeCombination value Description
Click to summarize M_WAIT

Stops queuing new grabs and waits for all previously queued grabs to finish before returning control to the Host.

Combination value for M_SEQUENCE.

You can add the following value to the above-mentioned value to specify the number of frames to grab.

function map For M_SEQUENCE
Click to summarizeCombination value Description
Click to summarize
M_COUNT (
MIL_INT n
)

Specifies the number of frames to grab in the sequence.

This combination constant will cause MdigProcess() to stop grabbing when the grab count (n) is reached. If the grab count is greater than the buffer count, the grab will be done in round-robin style. By default, the grab count is equal to the number of buffers or containers in the destination image array.

(summarize)
Parameters

Specifies the number of frames to grab.

1 <= Value <= 268435456

Sets to grab a specific number of frames.

Combination value for M_START.

You can add the following value to the above-mentioned value to specify the number of frames to grab sequentially when a digitizer trigger event occurs.

function map For M_START
Click to summarizeCombination value Description MIL system-specific
tooltip (‡)
Click to summarize

Specifies the number of frames to grab sequentially when a digitizer trigger event occurs.

Note that to use this setting, the OperationFlag parameter must be set to M_TRIGGER_FOR_FIRST_GRAB and the digitizer used must be configured to grab upon a trigger.

(summarize)
g h i j k
M10
l m p r
U27
t
U28
u
U36
y
U75
aa
Parameters

Specifies the number of frames to grab sequentially for each digitizer trigger event.

g h i j k
M10
l m p r
U27
t
U28
u
U36
y
U75
aa
M_INFINITE

Sets to grab an infinite number of frames. No other trigger is necessary.

g h i j k
M10
l m p r
U27
t
U28
u
U36
y
U75
aa
1 <= Value <= 268435456

Sets to grab a specific number of frames.

g h i j k
M10
l m p r
U27
t
U28
u
U36
y
U75
aa
OperationFlag

Specifies more information about the synchronization and triggering of the grab.

function map For controlling the order in which processing occurs
Click to summarizeValue Description
Click to summarize M_DEFAULT

Specifies the default execution mode.

If the Operation parameter is set to M_START, the default is the same as M_ASYNCHRONOUS.

If the Operation parameter is set to M_SEQUENCE, the default is the same as M_SYNCHRONOUS.

If the Operation parameter is set to M_STOP, the default is the same as M_SYNCHRONOUS unless MdigProcess() is called from the user-defined function, in which case the default is the same as M_ASYNCHRONOUS. Note that when the Operation parameter is set to M_STOP, M_DEFAULT is the only possible setting for the OperationFlag parameter.

(summarize)
Click to summarize M_ASYNCHRONOUS +

Allows your thread to continue after initiating the start of the grabs, rather than waiting for MdigProcess() to finish.

Note that when you are grabbing and processing a sequence of images asynchronously, you must make an additional call to MdigProcess using M_STOP to free internally allocated resources.

(summarize)
Click to summarize M_SYNCHRONOUS +

Synchronizes your thread with the end of MdigProcess().

Combination values for M_ASYNCHRONOUS; M_SYNCHRONOUS.

You can add one of the following values to the above-mentioned values to specify how the camera calibration context associated with the digitizer is propagated to each modified image buffer in the list.

Note that these settings are not available when grabbing into a container.

function map For how the camera calibration context is propagated
Click to summarize
Combination value
Description
Click to summarize M_CALIBRATION_PROPAGATE_AT_EACH_FRAME

Specifies that the camera calibration context associated with the digitizer is re-associated with the buffer each time the buffer is modified and just before calling the hook-handler function. This is less error-prone than M_CALIBRATION_PROPAGATE_ONCE, but it might slow down the hook-handler function.

(summarize)
Click to summarize M_CALIBRATION_PROPAGATE_OFF

Specifies to not affect the camera calibration context associated with the modified image buffer. You must associate the required camera calibration context with the image buffers before calling MdigProcess(), if necessary.

(summarize)
Click to summarize M_CALIBRATION_PROPAGATE_ONCE

Specifies that before starting image acquisition, the camera calibration context associated with the digitizer is also associated with each image buffer.

Since the camera calibration context associated with the digitizer is only propagated at the beginning of the grab sequence, be cautious when using the hook-handler function to change the camera calibration context settings; the camera calibration context associated with the digitizer will not be re-associated with the modified buffer afterwards.

This is the default value.

(summarize)
Combination values for M_ASYNCHRONOUS; M_SYNCHRONOUS.

You can add one of the following values to the above-mentioned values to specify whether to keep or remove the ROI.

Note that these settings are not available when grabbing into a container.

function map For specifying whether to clear the ROI of the previous grab
Click to summarize
Combination value
Description
Click to summarize M_REGION_DELETE_AT_EACH_FRAME

Specifies that any ROI associated with the modified buffer is deleted immediately before calling the user-defined hook function. This is equivalent to calling MbufSetRegion() to clear the ROI of the modified buffer after every grab. This is less error-prone, but might slow down the user-defined hook function's execution slightly.

(summarize)
Click to summarize M_REGION_KEEP

Specifies that any ROI associated with the modified buffer is left as is.

This is the default value.

(summarize)
Combination value for M_ASYNCHRONOUS; M_SYNCHRONOUS.

You can add the following value to the above-mentioned values to set how the function will behave when the digitizer is configured for triggered grabs.

function map For only controlling the grab of the first frame with a trigger
Click to summarizeCombination value Description
Click to summarize M_TRIGGER_FOR_FIRST_GRAB

Specifies that a trigger will only be used to control the grab of the first frame. When there is no preset end to the list of grabs (M_START), you can also force every n th grab to wait for a trigger. To do so, set the Operation parameter to M_START + M_FRAMES_PER_TRIGGER().

Note that if the digitizer is not configured for triggered grabs, M_TRIGGER_FOR_FIRST_GRAB is ignored. Also, when the digitizer is configured for triggered grabs, but M_TRIGGER_FOR_FIRST_GRAB is not set (the default behavior), the function will only grab each frame when triggered.

(summarize)
HookHandlerPtr

Specifies the address of the function that is called when a buffer/container is modified in the array of destination image buffers/containers.

The hook-handler function, pointed to by HookHandlerPtr, must be declared as follows:

MIL_INT MFTYPE HookHandler(
MIL_INT HookType,
MIL_ID EventId,
void *UserDataPtr
)

Parameters
HookType

Type of event that generated the call (M_MODIFIED_BUFFER).

EventId

Event identifier. You can pass the identifier to MdigGetHookInfo() to inquire about the hooked event.

UserDataPtr

User data pointer that was passed (as UserDataPtr) to MdigProcess().

Upon successful completion, the hook-handler function should return M_NULL. Note MFTYPE and MIL_DIG_HOOK_FUNCTION_PTR are reserved MIL predefined types for functions and data pointers.

If the hook-handler function modifies the buffer or container which triggered the hook-handler function, it will not be called again for that buffer/container.

UserDataPtr

Specifies the address of the user data that you want to make available to the hook-handler function. This address is passed to the hook-handler function, through its UserDataPtr parameter, when the specified event occurs. Set this parameter to M_NULL if not used.

Compilation information
Header Include mil.h.
Library Use mil.lib.
DLL Requires mil.dll.
GRAB GRAB GRAB SEQUENCE START STOP WAIT INFINITE DEFAULT ASYNCHRONOUS SYNCHRONOUS CALIBRATION PROPAGATE AT EACH FRAME CALIBRATION PROPAGATE OFF CALIBRATION PROPAGATE ONCE REGION DELETE AT EACH FRAME REGION KEEP TRIGGER FOR FIRST GRAB IMAGE