OpenCV
4.10.0
Open Source Computer Vision
|
Prev Tutorial: Detection of ChArUco Boards
Next Tutorial: Calibration with ArUco and ChArUco
A ChArUco diamond marker (or simply diamond marker) is a chessboard composed by 3x3 squares and 4 ArUco markers inside the white squares. It is similar to a ChArUco board in appearance, however they are conceptually different.
In both, ChArUco board and Diamond markers, their detection is based on the previous detected ArUco markers. In the ChArUco case, the used markers are selected by directly looking their identifiers. This means that if a marker (included in the board) is found on a image, it will be automatically assumed to belong to the board. Furthermore, if a marker board is found more than once in the image, it will produce an ambiguity since the system wont be able to know which one should be used for the Board.
On the other hand, the detection of Diamond marker is not based on the identifiers. Instead, their detection is based on the relative position of the markers. As a consequence, marker identifiers can be repeated in the same diamond or among different diamonds, and they can be detected simultaneously without ambiguity. However, due to the complexity of finding marker based on their relative position, the diamond markers are limited to a size of 3x3 squares and 4 markers.
As in a single ArUco marker, each Diamond marker is composed by 4 corners and a identifier. The four corners correspond to the 4 chessboard corners in the marker and the identifier is actually an array of 4 numbers, which are the identifiers of the four ArUco markers inside the diamond.
Diamond markers are useful in those scenarios where repeated markers should be allowed. For instance:
detect_diamonds.cpp
file inside the samples folder of the module.Furthermore, as its corners are chessboard corners, they can be used for accurate pose estimation.
The diamond functionalities are included in <opencv2/objdetect/charuco_detector.hpp>
The image of a diamond marker can be easily created using the cv::aruco::CharucoBoard::generateImage()
function. For instance:
This will create a diamond marker image with a square size of 200 pixels and a marker size of 120 pixels. The marker ids are given in the second parameter as a cv::Vec4i
object. The order of the marker ids in the diamond layout are the same as in a standard ChArUco board, i.e. top, left, right and bottom.
The image produced will be:
A full working example is included in the create_diamond.cpp
inside the samples/cpp/tutorial_code/objectDetection/
.
The samples create_diamond.cpp
now take input via commandline via the cv::CommandLineParser
. For this file the example parameters will look like:
As in most cases, the detection of diamond markers requires a previous detection of ArUco markers. After detecting markers, diamond are detected using the cv::aruco::CharucoDetector::detectDiamonds()
function:
The cv::aruco::CharucoDetector::detectDiamonds()
function receives the original image and the previous detected marker corners and ids. If markerCorners and markerIds are empty, the function will detect aruco markers and ids. The input image is necessary to perform subpixel refinement in the ChArUco corners. It also receives the rate between the square size and the marker sizes which is required for both, detecting the diamond from the relative positions of the markers and interpolating the ChArUco corners.
The function returns the detected diamonds in two parameters. The first parameter, diamondCorners
, is an array containing all the four corners of each detected diamond. Its format is similar to the detected corners by the cv::aruco::ArucoDetector::detectMarkers()
function and, for each diamond, the corners are represented in the same order than in the ArUco markers, i.e. clockwise order starting with the top-left corner. The second returned parameter, diamondIds
, contains all the ids of the returned diamond corners in diamondCorners
. Each id is actually an array of 4 integers that can be represented with cv::Vec4i
.
The detected diamond can be visualized using the function cv::aruco::drawDetectedDiamonds()
which simply receives the image and the diamond corners and ids:
The result is the same that the one produced by cv::aruco::drawDetectedMarkers()
, but printing the four ids of the diamond:
A full working example is included in the detect_diamonds.cpp
inside the samples/cpp/tutorial_code/objectDetection/
.
The samples detect_diamonds.cpp
now take input via commandline via the cv::CommandLineParser
. For this file the example parameters will look like:
Since a ChArUco diamond is represented by its four corners, its pose can be estimated in the same way than in a single ArUco marker, i.e. using the cv::solvePnP()
function. For instance:
The function will obtain the rotation and translation vector for each of the diamond marker and store them in rvecs
and tvecs
. Note that the diamond corners are a chessboard square corners and thus, the square length has to be provided for pose estimation, and not the marker length. Camera calibration parameters are also required.
Finally, an axis can be drawn to check the estimated pose is correct using drawFrameAxes()
:
The coordinate system of the diamond pose will be in the center of the marker with the Z axis pointing out, as in a simple ArUco marker pose estimation.
Sample video:
Also ChArUco diamond pose can be estimated as ChArUco board:
A full working example is included in the detect_diamonds.cpp
inside the samples/cpp/tutorial_code/objectDetection/
.
The samples detect_diamonds.cpp
now take input via commandline via the cv::CommandLineParser
. For this file the example parameters will look like: