Skip to content

MATLAB MEX functions for estimating pose of ChArUco and ArUco boards from OpenCV

License

Notifications You must be signed in to change notification settings

jmehami1/mex_ChArUco_Pose

Repository files navigation

Contributors Forks Stargazers Issues MIT License reposize

LinkedIn portfolio

MATLAB MEX functions for ChArUco and ArUco Boards

Detected pose of ArUco board Detected pose of ChArUco board


Table of Contents


About

MATLAB MEX functions to estimate the pose of ArUco and ChArUco calibration boards which is implemented in C++ openCV.

CharucoPosEst.mex

The MATLAB MEX function for getting the pose of a ChArUco board from the native OpenCV implementation in C++. Link to relevant OpenCV documentation can be found here.

ArucoPixDect.mexa64

The MATLAB MEX function for getting the identified markers of a ArUco board in pixel coordinates from the native OpenCV implementation in C++. This does NOT estimate the pose of an ArUco board. The pose can be estimated using an implmentation of the Perspective-n-Point algorithms such as IPPE.

The MEX functions should be located in the bin directory with a .mexa64 file type (assuming if built on x64 Linux OS). There are included MATLAB test scripts to check if the functions work.

Please Note: The printed markers must have a surrounding white border in order to be detected

(back to top)

Requirements

  • MATLAB 2018a or higher (Tested with 2021b)
  • GCC 7.0 or higher (Tested with 7.5.0)
  • OpenCV 4.0 or higher

Building Mex Functions

Create a build directory inside current directory.

In a terminal pointing to build run the following:

cmake ..
make 

The built MEX functions can be found in the bin directory.

(back to top)

ChArUco Board

Run the MEX function in MATLAB as follows:

[rotMat, trans, found, imageOut, numDetectedMarkPts] = CharucoPosEst(image, intrinsicMatrix, distCoefCV, numOfCols, numOfRows, checkerSideLen, arucoSideLen);
Output Description
rotMat Estimated 3x3 rotation matrix of extrinsic pose or pose of the board w.r.t to the camera's coordinate frame.
trans Estimated 1x3 translation vector of extrinsic pose or pose of the board w.r.t to the camera's coordinate frame.
found true/false if the pose of the board could be estimated from the image
imageOut Copy of input image with drawn 3D axis, detected markers and their IDs
numDetectedMarkPts Number of detected marker points used to estimate pose

Check the test script for further information on how to use the function. Test image of 6x8 ChArUco board with 4x4 ArUco dictionary is shown below. Note that centre of board is covered to highlight advantages of ArUco marker board.

ChArUco pattern held up in front of camera


Detected Pose

Origin is located in the bottom-left corner of the bottom-left marker as shown. Note that the board in test image is not rigid so that is why the axis is off. The extrinsic pose of the camera, the pose of the board in the coordinate frame of the camera, is shown in the right image.

ChArUco pattern with estimated extrinsic pose 3D view of camera and ChArUco board


(back to top)

ArUco Board

This MEX function identifies the markers that are present in the passed in image and returns their IDs and pixel corner locations to MATLAB. It does NOT estimate the pose of the board, this will need to be done by an Perspective-n-Point algorithm in MATLAB.

Run the MEX function in MATLAB as follows:

[ids, markerCorner, imageOut] = ArucoPixDect(image);
Output Description
ids Detected marker IDs from image
markerCorner The pixel coordinates of the corners for each of the detected marker IDs
imageOut Copy of input image with drawn detected markers and their IDs, and any rejected markers

Check the test script for further information on how to use the function. Test image of a custom 5x8 ArUco board with 4x4 ArUco dictionary is shown below. Note that the missing markers are not included as apart of the setup of the board.

Custom ArUco pattern held up in front of camera


(back to top)

Detected Marker and Pose

The MEX function detects the markers of the board that are present in the image. The detected markers can be identified using their marker ID as shown on the left image below. In order to estimate the pose to board, we need the corners of the detected marker as shown on the right image below.

ArUco pattern with detected marker IDs Detected marker corner pixels

The estimated extrinsic is shown below. The origin of the board is located in the bottom-left corner of the bottom-left marker. Note that the board in the test image is not rigid so that is why the axis is slightly off. The extrinsic pose of the camera, the pose of the board in the coordinate frame of the camera, is shown in the right image.

ArUco pattern with estimated extrinsic pose 3D view of camera and ArUco board

The extrinsic (or the pose of the board w.r.t. the camera's coordinate frame) is found using the extrinsics function built into MATLAB's computer vision toolbox. Note that this function is not robust as it estimates the pose in a linear manner using SVD. Use IPPE instead which estimates the extrinsic through optimisation of reprojection error. The function ArucoPosEst uses the IPPE library to estimate the extrinsic of the ArUco board as follows:

[rotMat, trans, found, imgOut, worldPts] = ArucoPosEst(img, markerCornerCell, cameraParams, doUndistortion);

TODO

  • Complete the ArUco board pose estimation using PnP algorithm built into OpenCV

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Jasprabhjit Mehami

Email: [email protected]

(back to top)

Acknowledgments

(back to top)

About

MATLAB MEX functions for estimating pose of ChArUco and ArUco boards from OpenCV

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published