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 |
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.
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.
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.
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.
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:
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
|
|||||||||||||||||||||||||||||||||||||||
Value | Description
|
MIL system-specific tooltip (†) |
|||||||||||||||||||||||||||||||||||||
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 | ||||||||||||||||||||
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 |
Focus position.
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.
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.
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.
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.
For specifying the starting focus
position of the search
|
|||||||||||||||||||||||||||||||||||||||
Value | Description
|
MIL system-specific tooltip (†) |
|||||||||||||||||||||||||||||||||||||
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 | ||||||||||||||||||||
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 |
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.
For specifying the maximum focus position
of the search
|
|||||||||||||||||||||||||||||||||||||||
Value | Description
|
MIL system-specific tooltip (†) |
|||||||||||||||||||||||||||||||||||||
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 | ||||||||||||||||||||
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 |
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.
Specifies the operation mode used by this function. It can be set to:
For specifying the optimum focus position
search strategy
|
|||||||||||||||||||||||||||||||||||||||
Value | Description
|
MIL system-specific tooltip (†) |
|||||||||||||||||||||||||||||||||||||
M_DEFAULT |
Same as M_SMART_SCAN. |
† | b | c | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | ||||||||||||||||||||
M_BISECTION + |
Specifies that the bisection search strategy will be used. (more details...) |
† | b | c | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | ||||||||||||||||||||
M_REFOCUS + |
Specifies that the refocus search strategy will be used. (more details...) |
† | b | c | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | ||||||||||||||||||||
M_SCAN_ALL + |
Specifies that the scan-all search strategy will be used. (more details...) |
† | b | c | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | ||||||||||||||||||||
M_SMART_SCAN + |
Specifies that the smart-scan search strategy will be used. (more details...) |
† | b | c | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s |
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.
For specifying the number of focus
positions at which to compare the focus indicator
|
|||||||||||||||||||||||||||||||||||||||
Combination value | Description
|
MIL system-specific tooltip (†) |
|||||||||||||||||||||||||||||||||||||
1 <= Value <= 255 |
Specifies the required number of focus positions. (more details...) |
† | 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:
For specifying that only the
focus indicator is calculated
|
|||||||||||||||||||||||||||||||||||||||
Value | Description
|
MIL system-specific tooltip (†) |
|||||||||||||||||||||||||||||||||||||
M_EVALUATE + |
Specifies to only calculate the focus indicator. (more details...) |
† | b | c | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s |
You can add one or more of the following values to the above-mentioned values to specify additional information about the mode of operation.
For specifying additional
information about the mode of operation
|
|||||||||||||||||||||||||||||||||||||||
Combination value | Description
|
MIL system-specific tooltip (†) |
|||||||||||||||||||||||||||||||||||||
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 | ||||||||||||||||||||
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 |
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.
Header | Include mil.h. |
Library | Use mil.lib; milim.lib. |
DLL | Requires mil.dll; milim.dll. |