| MIL 10 Reference
| Customize Help
| Save Settings

McalGrid



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

Available on Windows
Available on Linux

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
Calibrate your camera setup using a grid.
Syntax
void McalGrid(
MIL_ID CalibrationId, //in
MIL_ID SrcImageBufId, //in
MIL_DOUBLE GridOffsetX, //in
MIL_DOUBLE GridOffsetY, //in
MIL_DOUBLE GridOffsetZ, //in
MIL_INT RowNumber, //in
MIL_INT ColumnNumber, //in
MIL_DOUBLE RowSpacing, //in
MIL_DOUBLE ColumnSpacing, //in
MIL_INT64 Operation, //in
MIL_INT64 GridType //in
)
Description

This function uses an image of a user-defined grid of circles or squares and the world description of this grid to establish calibration points and calibrate your camera setup. The mapping is stored with the specified calibration context. The specified calibration context determines the calibration mode used.

MIL is distributed with four different calibration grids that you can print and use: ChessboardCalibrationGrid_15x16_Letter.pdf, ChessboardCalibrationGrid_18x22_Letter.pdf, CircleCalibrationGrid_15x16_Letter.pdf, CircleCalibrationGrid_18x22_Letter.pdf. These files are located in the Matrox Imaging\Images directory. Each file includes the world description of the grid.

Typically, you specify the world description of the grid in the absolute coordinate system. However, for 3D-based calibration modes (M_TSAI_BASED or M_3D_ROBOTICS), it is possible to use a grid that is not in the XY-plane (Z=0) of the absolute coordinate system. In this case, use the GridOffsetZ parameter to specify the height of the grid being used.

When working in M_3D_ROBOTICS calibration mode, you must call this function at least three times to accumulate data with different images and orientations (each time with M_ACCUMULATE) before calling this function a fourth time (with M_FULL_CALIBRATION and no image) to perform the full calibration. Before each data accumulation call, you must change the position and orientation of the tool holding the camera with respect to the robot base. More specifically, you must rotate the tool along at least two non-parallel axes. You must also use McalSetCoordinateSystem() to set the position of the tool coordinate system with respect to the robot base coordinate system before each of these calls. You must call McalGrid() with M_ACCUMULATE more than three times before performing a full calibration improves the accuracy of your calibration.

You can inquire about the pixel coordinates and associated real-world coordinates of each calibration point of one particular call using McalInquireSingle().

For 3D-based calibration modes, McalGrid() performs two types of calculations. It calculates the camera's internal attributes, and it calculates the orientation and distance between the camera and camera calibration plane. Initially, the latter is used to set the camera coordinate system. If you move the camera or the grid (not both), you can have McalGrid() recalculate only the orientation and distance between them. In this case, depending on what you moved, you can specify that McalGrid() displace either the camera coordinate system or the relative coordinate system, using M_DISPLACE_CAMERA_COORD or M_DISPLACE_RELATIVE_COORD, respectively. When using M_DISPLACE_RELATIVE_COORD, the camera calibration plane is considered to be the XY-plane of the relative coordinate system, regardless of the M_CALIBRATION_PLANE setting.

Also, for 3D-based calibration modes, a successful call to McalGrid() with M_FULL_CALIBRATION creates a rigid link between the camera coordinate system and the tool coordinate system. This link ensures that moving either the tool or the camera coordinate system will affect both. This link can be broken using McalControl() with M_LINK_TOOL_AND_CAMERA.

Note that the internal attributes calculated for the camera are not those of the physical camera, but those of the ideal pinhole-camera used to model the physical camera.

After calling McalGrid(), you can inquire about the success of the calibration using McalInquire() with M_CALIBRATION_STATUS. Also, you can inquire about the pixel coordinates and associated real-world coordinates of each calibration point using McalInquire() with M_CALIBRATION_IMAGE_POINTS_X, M_CALIBRATION_IMAGE_POINTS_Y, M_CALIBRATION_WORLD_POINTS_X, M_CALIBRATION_WORLD_POINTS_Y, and M_CALIBRATION_WORLD_POINTS_Z. These coordinates correspond to the center of circles in a circle grid or to points connecting four corners in a chessboard grid.

When the image of the calibration grid is rotated, for instance when the image of the grid has been taken by a second camera at a different angle, you might need to specify where the top-left corner of the real-world grid is in the rotated image. This is done using McalGrid() set to M_GRID_CORNER_HINT_X and M_GRID_CORNER_HINT_Y. Note that RowNumber and ColumnNumber specify the number of rows and columns of the calibration grid as it is in the world, and not as it appears in the rotated image.

For more information on performing camera calibration, see the Steps to performing a calibration section of Chapter 25: Calibrating your camera setup.

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 if there is complementary information.
Parameters
This function is not supported on the selected boards.
Parameters
CalibrationId

Specifies the identifier of the calibration context.

SrcImageBufId

Specifies the identifier of the image buffer containing the grid. It must be an 8- or 16-bit unsigned buffer, with 1 or 3 bands.

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.

Note that the source image used for calibration is automatically calibrated after a successful call to McalGrid() with M_FULL_CALIBRATION.

When performing a M_FULL_CALIBRATION operation in M_3D_ROBOTICS calibration mode, set this parameter to M_NULL.

GridOffsetX INQ

Specifies the X-position of the top-left circle of the calibration grid of circles or the top-left point connecting four squares in a chessboard grid. Specify its X-position in the calibration-plane coordinate system, in world-units.

When performing a M_FULL_CALIBRATION operation in M_3D_ROBOTICS calibration mode, set this parameter to M_NULL.

GridOffsetY INQ

Specifies the Y-position of the top-left circle of the calibration grid of circles or the top-left point connecting four squares in a chessboard grid. Specify its Y-position in the calibration-plane coordinate system in, world-units.

When performing a M_FULL_CALIBRATION operation in M_3D_ROBOTICS calibration mode, set this parameter to M_NULL.

GridOffsetZ INQ

Specifies the Z-position of the top-left circle of the calibration grid of circles or the top-left point connecting four squares in a chessboard grid. Specify its Z-position in the calibration-plane coordinate system in, world-units.

For 2D-based calibration modes, or when performing a M_FULL_CALIBRATION operation in M_3D_ROBOTICS calibration mode, set this parameter to M_NULL.

RowNumber INQ

Specifies the number of rows in the calibration grid. The minimum number of rows is 2 when GridType is set to M_CIRCLE_GRID and 3 when set to M_CHESSBOARD_GRID.

For M_UNIFORM_TRANSFORMATION, M_LINEAR_INTERPOLATION, and M_PERSPECTIVE_TRANSFORMATION calibration modes, the minimum number of grid points required is 4. For M_TSAI_BASED and M_3D_ROBOTICS calibration modes, you must provide a grid that contains at least 6 grid points, even though the minimum number of rows and the minimum number of columns are both 2. Accuracy increases with the number of points.

For 3D-based calibration contexts (M_TSAI_BASED and M_3D_ROBOTICS calibration modes), and performing a M_DISPLACE_CAMERA_COORD or M_DISPLACE_RELATIVE_COORD operation, the minimum number of grid points required is 4.

When performing a M_FULL_CALIBRATION operation in M_3D_ROBOTICS calibration mode, set this parameter to M_NULL.

Note that in the case of a rotated image of a rectangular calibration grid, you must specify the number of rows of the real-world grid and not the number of rows as it appears in the rotated image.

ColumnNumber INQ

Specifies the number of columns in the calibration grid. The minimum number of columns is 2 when GridType is set to M_CIRCLE_GRID and 3 when set to M_CHESSBOARD_GRID.

When performing a M_FULL_CALIBRATION operation in M_3D_ROBOTICS calibration mode, set this parameter to M_NULL.

Note that in the case of a rotated image of a rectangular calibration grid, you must specify the number of columns of the real-world grid and not the number of columns as it appears in the rotated image.

RowSpacing INQ

Specifies the number of world units between rows.

When performing a M_FULL_CALIBRATION operation in M_3D_ROBOTICS calibration mode, set this parameter to M_NULL.

ColumnSpacing INQ

Specifies the number of world units between columns.

When performing a M_FULL_CALIBRATION operation in M_3D_ROBOTICS calibration mode, set this parameter to M_NULL.

Operation

Specifies the calibration operation to perform. This parameter must be set to one of the following values:

function map For specifying the calibration operation
CollapseValue Description
Collapse M_DEFAULT

Same as M_FULL_CALIBRATION.

Collapse M_ACCUMULATE

Calculates only the position of the calibration points and stores them in the calibration context.

At least three calls to McalGrid() should be made with this operation before performing the full calibration with M_FULL_CALIBRATION. This operation is only supported for M_3D_ROBOTICS calibration.

(summarize)
Collapse M_DISPLACE_CAMERA_COORD

Calculates only the position and orientation between the camera and the camera calibration plane, and displaces the camera coordinate system accordingly. Note that besides the camera coordinate system, this also displaces the tool coordinate system (if still linked with M_LINK_TOOL_AND_CAMERA); no other coordinate system is affected. This calibration operation is only supported for 3D-based calibration contexts that are fully calibrated with M_FULL_CALIBRATION.

If the camera is moved to a new position but its internal attributes are already known by a previous full calibration, you can use this operation to allow for a faster calibration.

(summarize)
Collapse M_DISPLACE_RELATIVE_COORD

Calculates only the position and orientation between the camera and the camera calibration plane, and displaces the relative coordinate system accordingly. This calibration operation is only supported for 3D-based calibration contexts that are fully calibrated with M_FULL_CALIBRATION.

You can use this operation to move the relative coordinate system only and remain calibrated. This operation keeps the camera fixed with respect to the absolute coordinate system, and its intrinsic attributes unmodified. You can then obtain the position and orientation of the relative coordinate system with respect to any other coordinate system using McalGetCoordinateSystem(), and calculate the unknown position of an object in space.

When using this operation, the camera calibration plane is considered to be the relative coordinate system regardless of the M_CALIBRATION_PLANE setting.

(summarize)
Collapse M_FULL_CALIBRATION

Performs a full calibration. For 3D-based calibration contexts, this operation calculates the camera's internal attributes and the difference in position and orientation between the camera and the camera calibration plane. It then sets the camera coordinate system accordingly.

When working in M_TSAI_BASED calibration mode, the camera's optical axis should be at least 30 degrees away from the axis perpendicular to the camera calibration plane (also known as, angle of incidence). Otherwise, the calibration might fail.

(summarize)
GridType INQ

Specifies the type of grid used. This parameter must be set to one of the following values:

function map For specifying the type of grid
CollapseValue Description
Collapse M_DEFAULT

Same as M_CIRCLE_GRID.

Collapse M_CHESSBOARD_GRID +

Specifies a chessboard grid. The number of rows and columns represents the number of corners horizontally and vertically. A corner is the intersection of 4 cells, meaning that the corners on the perimeter do not count. Note that, for a chessboard grid type, the number of rows and the number of columns must be at least 3. The following is an example of a valid 4x4 chessboard grid.

(summarize)
Collapse M_CIRCLE_GRID +

Specifies a grid of circles. Note that, for a grid of circles, the number of rows and the numbers of columns must be at least 2. To create an accurate (subpixel) mapping, the image of the grid should meet the following guidelines (at the working resolution):

  • The radius of the grid's circles should range between 6 and 10 pixels.

  • The center-to-center distance between the grid's circles should range from 18 to 32 pixels (22 pixels recommended).

  • The minimum distance between the edges of the circles should be 6 pixels.

  • The grid should be large enough to cover the area of the image from which you want real-world results.

  • The grid must be on a single plane although it can be at a slant.

  • The image of the grid should have high contrast.

(summarize)
Combination constants for M_CHESSBOARD_GRID; M_CIRCLE_GRID.

You can add one of the following values to the above-mentioned values to set the orientation of the Y-axis.

These combination values are not supported if using M_UNIFORM_TRANSFORMATION calibration mode.

function map For specifying the orientation of the Y-axis INQ
CollapseCombination value Description
Collapse M_Y_AXIS_DOWN

Orients the positive Y-axis along the first column of circles in a grid of circles, or along square corners in a chessboard grid. The axis is oriented from the top-left to the bottom-left.

When no offset is specified, the origin is located at the center of the top-left circle.

This is the default value.

(summarize)
Collapse M_Y_AXIS_UP

Orients the positive Y-axis along the first column of circles in a grid of circles, or along square corners in a chessboard grid. The axis is oriented from the bottom-left to the top-left.

When no offset is specified, the origin is located in the center of the top-left circle.

(summarize)
Combination constant for M_CHESSBOARD_GRID; M_CIRCLE_GRID.

You can add the following value to the above-mentioned values to set the speed of calibration.

function map For increasing the speed of calibration
CollapseCombination value Description
Collapse M_FAST

Speeds up the time it takes to perform the calibration by using a faster calibration algorithm. Note that using a faster calibration algorithm can decrease the robustness and accuracy of the calibration.

When using M_FAST, memory consumption is reduced.

(summarize)
Compilation information
Header Include mil.h.
Library Use mil.lib; milcal.lib.
DLL Requires mil.dll; milcal.dll.
UNSIGNED PROC NONE DEFAULT ACCUMULATE DISPLACE CAMERA COORD DISPLACE RELATIVE COORD FULL CALIBRATION DEFAULT CHESSBOARD GRID CIRCLE GRID Y AXIS DOWN Y AXIS UP FAST