| MIL 10 Reference
| Customize Help
| Save Settings

MdigFocus



See also
Availability
Not available in MIL-Lite
Available in MIL

Available on Windows
Available on Linux

Not supported on:
Not supported on Host system
Not supported on Matrox GPU processing driver
Fully supported on:
Fully supported on Matrox CronosPlus
Fully supported on Matrox GigE Vision driver
Fully supported on Matrox IEEE 1394 IIDC driver
Fully supported on Matrox Iris GT
Fully supported on Matrox Morphis
Fully supported on Matrox Morphis QxT
Fully supported on Matrox Orion HD
Fully supported on Matrox Radient eCL
Fully supported on Matrox Radient eV-CXP
Fully supported on Matrox Solios eA/XA
Fully supported on Matrox Solios ecl/xcl/ev-cl
Fully supported on Matrox USB3 Vision driver (requires Update 19)
Fully supported on Matrox Vio

For any information regarding a MIL system added during a MIL Update, see the MIL system’s release note

Available on Non-Matrox computer
Available on Matrox 4Sight-X
Available on Matrox 4Sight GP
Available on Matrox Supersight
function map Function map
Examples
Synopsis
Adjust a camera's lens motor to a position that produces optimum focus, or only calculate the focus quality of a specified image or an image grabbed at the current lens motor position.
Syntax
void MdigFocus(
MIL_ID DigId, //in
MIL_ID DestImageBufId, //in
MIL_ID FocusImageRegionBufId, //in
MIL_FOCUS_HOOK_FUNCTION_PTR FocusHookPtr, //in
void *UserDataPtr, //in
MIL_INT MinPosition, //in
MIL_INT StartPosition, //in
MIL_INT MaxPosition, //in
MIL_INT MaxPositionVariation, //in
MIL_INT64 ProcMode, //in
MIL_INT *ResultPtr //out
)
Description

This function adjusts a camera's lens motor to a position that produces optimum focus, or only calculates an indicator of the focus quality (focus indicator) of a specified image or an image grabbed at the current lens motor position. The operation mode establishes which is performed.

To adjust a camera's lens motor to a position that produces optimum focus, this function calls a user-defined function to move the lens motor to a specified initial position, grabs an image, calculates the focus indicator of the grabbed image, and based on the focus indicator and the specified optimum focus search strategy, calculates a new position for the lens motor. The process repeats, calling the user-defined function to move the lens motor to the newly calculated position and comparing the new focus indicator with the old. The process continues repeating until the optimum focus position is found. You can optionally have the user-defined function perform the grab, instead of having MdigFocus() directly perform the grab.

Regardless of the operation mode, the image is subsampled and filtered by default before the focus indicator is calculated; you can override this default.

This function establishes the focus indicator of an image by analyzing the edges within a specified focus region (a child image of the grabbed or provided image). An image with a good focus indicator has a sharp intensity transition between its edges and their background.

The specified search strategy (set using the operation mode parameter) determines how each new position of the lens motor is calculated between grabs. For more information, see the Auto-focusing section of Chapter 23: Grabbing with your digitizer.

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. If you want to provide the image (that is, either have the user-defined function perform the grab, or use an existing image) set this parameter to M_NULL. The provided image must be stored in the destination image buffer.

DestImageBufId

Specifies the identifier of the buffer that contains the image to analyze or in which to grab. This buffer should be of an appropriate type to hold the image. This buffer cannot be a signed 3-band buffer, a 32-bit buffer, or a 1-bit buffer.

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.

FocusImageRegionBufId

Specifies the identifier of a child buffer of the destination buffer. Analysis of each grabbed image is limited to the region specified by this buffer. To analyze the entire image, set this parameter to M_DEFAULT.

You should pass a child buffer when there are objects at different distances within the camera's field of view; this is because in this case, each object will have a different optimum focus position.

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

FocusHookPtr

Specifies the address of the user-defined function to call before each grab. When only calculating the focus indicator (that is, using the M_EVALUATE operation mode), this parameter is not used, and must be set to M_NULL.

The user-defined function must be declared as follows:

MIL_INT MFTYPE FocusHook(
MIL_INT HookType,
MIL_INT Position,
void *UserDataPtr
)
Parameters
HookType

Indicates whether the optimum focus position was found or whether a new position needs to be analyzed.

For determining whether the optimum focus position was found or a new position needs to be analyzed
CollapseValue Description
MIL system-specific
tooltip (†)
Collapse M_CHANGE

Specifies that the lens position must change to the position specified by the Position parameter, and a new position needs to be analyzed.

b c e f g h i j k l m n o p q r s
Collapse M_ON_FOCUS

Specifies that the optimum focus position was found and is specified by the Position parameter.

b c e f g h i j k l m n o p q r s
Position

Focus position.

UserDataPtr

Pointer to data.

Upon successful completion, the user-defined function should return M_NULL. Otherwise, the user-defined function should return M_STOP_FOCUS to abort the MdigFocus() operation. In this case, the value returned by MdigFocus() will be undetermined.

UserDataPtr

Specifies the address of the data that you want to make available to the user-defined function. When only calculating the focus indicator (that is, using the M_EVALUATE operation mode), this parameter is not used, and must be set to M_NULL.

function map For specifying the address of the data
CollapseValue Description
MIL system-specific
tooltip (†)
Collapse M_NULL

Specifies that the function does not require data.

b c e f g h i j k l m n o p q r s
Collapse Value

Specifies the address of the data. This address is passed to the user-defined function, through its UserDataPtr parameter, when the user-defined function is called.

(summarize)
b c e f g h i j k l m n o p q r s
MinPosition

Specifies the minimum focus position of the search. When only calculating the focus indicator (that is, using the M_EVALUATE operation mode), this parameter is not used, and must be set to M_DEFAULT.

function map For specifying the minimum focus position of the search
CollapseValue Description
MIL system-specific
tooltip (†)
Collapse M_DEFAULT

Specifies the default value; the default value is 0.

b c e f g h i j k l m n o p q r s
Collapse Value >= 0

Specifies the position, in lens motor steps.

b c e f g h i j k l m n o p q r s
StartPosition

Specifies the starting focus position of the search. When only calculating the focus indicator (that is, using the M_EVALUATE operation mode), this parameter is not used, and must be set to M_DEFAULT.

function map For specifying the starting focus position of the search
CollapseValue Description
MIL system-specific
tooltip (†)
Collapse M_DEFAULT

Specifies the default value; the default value is MinPosition.

b c e f g h i j k l m n o p q r s
Collapse MinPosition <= Value <= MaxPosition

Specifies the position, in lens motor steps.

b c e f g h i j k l m n o p q r s
MaxPosition

Specifies the maximum focus position of the search. When only calculating the focus indicator (that is, using the M_EVALUATE operation mode), this parameter is not used, and must be set to M_DEFAULT.

function map For specifying the maximum focus position of the search
CollapseValue Description
MIL system-specific
tooltip (†)
Collapse M_DEFAULT

Specifies the default value; the default value is 255.

b c e f g h i j k l m n o p q r s
Collapse Value > MinPosition

Specifies the position, in lens motor steps.

b c e f g h i j k l m n o p q r s
MaxPositionVariation

Specifies the positional increment to use in the search. When only calculating the focus indicator (that is, using the M_EVALUATE operation mode), this parameter is not used, and must be set to M_DEFAULT.

function map For specifying the positional increment
CollapseValue Description
MIL system-specific
tooltip (†)
Collapse M_DEFAULT

Specifies the default value. The default value is equal to 1/16 of the value specified by MaxPosition.

(summarize)
b c e f g h i j k l m n o p q r s
Collapse Value > 0

Specifies the position, in lens motor steps.

b c e f g h i j k l m n o p q r s
ProcMode

Specifies the operation mode used by this function. It can be set to:

function map For specifying the optimum focus position search strategy
CollapseValue Description
MIL system-specific
tooltip (†)
Collapse M_DEFAULT

Same as M_SMART_SCAN.

b c e f g h i j k l m n o p q r s
Collapse M_BISECTION +

Specifies that the bisection search strategy will be used. This strategy breaks down the given positional range, step-by-step, until it finds the optimum focus position.

(summarize)
b c e f g h i j k l m n o p q r s
Collapse M_REFOCUS +

Specifies that the refocus search strategy will be used. This strategy scans upward or downward until it finds the optimum focus position or until it reaches the minimum or maximum position.

(summarize)
b c e f g h i j k l m n o p q r s
Collapse M_SCAN_ALL +

Specifies that the scan-all search strategy will be used. This strategy scans, by 1, all positions between the minimum and maximum and returns the position which produced the highest focus indicator.

(summarize)
b c e f g h i j k l m n o p q r s
Collapse M_SMART_SCAN +

Specifies that the smart-scan search strategy will be used. This strategy performs three refocus searches, each with a smaller positional increment.

(summarize)
b c e f g h i j k l m n o p q r s
Combination constant for M_REFOCUS; M_SMART_SCAN.

You can add the following value to the above-mentioned values to specify the number of focus positions at which to compare the focus indicator when a potential optimum focus position (a peak in focus indicator values) is found.

When a potential optimum focus position is found, the process repeats the specified number of times to examine positions beyond that peak. This verifies that the peak focus indicator is truly the optimum focus position.

function map For specifying the number of focus positions at which to compare the focus indicator
CollapseCombination value Description
MIL system-specific
tooltip (†)
Collapse 1 <= Value <= 255

Specifies the required number of focus positions.

Note that this number cannot be greater than the difference between the maximum and minimum positions specified by MaxPosition and MinPosition, respectively.

(summarize)
b c e f g h i j k l m n o p q r s

To calculate only the focus indicator value for a given image or for the image grabbed at the current lens position, set the ProcMode parameter to the following:

function map For specifying that only the focus indicator is calculated
CollapseValue Description
MIL system-specific
tooltip (†)
Collapse M_EVALUATE +

Specifies to only calculate the focus indicator. The user-defined function and all position parameters are unused (but must be set to the specific values mentioned previously). Instead, this operation mode grabs an image and uses it to calculate the focus indicator value. Note that, if you don't specify a digitizer identifier, the image contained in the specified destination buffer is used.

(summarize)
b c e f g h i j k l m n o p q r s
Combination constants for any of the possible values of the ProcMode parameter.

You can add one or more of the following values to the above-mentioned values to specify additional information about the mode of operation.

function map For specifying additional information about the mode of operation
CollapseCombination value Description
MIL system-specific
tooltip (†)
Collapse M_NO_FILTER

Skips the filtering of each image to analyze.

b c e f g h i j k l m n o p q r s
Collapse M_NO_SUBSAMPLING

Skips the subsampling of each image to analyze.

b c e f g h i j k l m n o p q r s
ResultPtr

Specifies the address in which to return either the focus indicator (after performing the calculation on a single image with M_EVALUATE) or the optimum focus position (after performing the calculation on one or more images with one of the optimum focus position search strategies). If you do not want to return the focus indicator or the optimum focus position, you can set this parameter to M_NULL.

Compilation information
Header Include mil.h.
Library Use mil.lib; milim.lib.
DLL Requires mil.dll; milim.dll.
GRAB PROC NONE SIGNED GRAB PROC NONE NONE CHANGE ON FOCUS NULL DEFAULT DEFAULT DEFAULT DEFAULT DEFAULT BISECTION REFOCUS SCAN ALL SMART SCAN EVALUATE NO FILTER NO SUBSAMPLING NULL NULL DEFAULT DEFAULT DEFAULT DEFAULT