Merge branch 4.x
@@ -2,8 +2,7 @@ Detection of ArUco boards {#tutorial_aruco_board_detection}
|
||||
=========================
|
||||
|
||||
@prev_tutorial{tutorial_aruco_detection}
|
||||
@next_tutorial{tutorial_barcode_detect_and_decode}
|
||||
|
||||
@next_tutorial{tutorial_charuco_detection}
|
||||
|
||||
| | |
|
||||
| -: | :- |
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
Calibration with ArUco and ChArUco {#tutorial_aruco_calibration}
|
||||
==================================
|
||||
|
||||
@prev_tutorial{tutorial_charuco_diamond_detection}
|
||||
@next_tutorial{tutorial_aruco_faq}
|
||||
|
||||
The ArUco module can also be used to calibrate a camera. Camera calibration consists in obtaining the
|
||||
camera intrinsic parameters and distortion coefficients. This parameters remain fixed unless the camera
|
||||
optic is modified, thus camera calibration only need to be done once.
|
||||
|
||||
Camera calibration is usually performed using the OpenCV `cv::calibrateCamera()` function. This function
|
||||
requires some correspondences between environment points and their projection in the camera image from
|
||||
different viewpoints. In general, these correspondences are obtained from the corners of chessboard
|
||||
patterns. See `cv::calibrateCamera()` function documentation or the OpenCV calibration tutorial for
|
||||
more detailed information.
|
||||
|
||||
Using the ArUco module, calibration can be performed based on ArUco markers corners or ChArUco corners.
|
||||
Calibrating using ArUco is much more versatile than using traditional chessboard patterns, since it
|
||||
allows occlusions or partial views.
|
||||
|
||||
As it can be stated, calibration can be done using both, marker corners or ChArUco corners. However,
|
||||
it is highly recommended using the ChArUco corners approach since the provided corners are much
|
||||
more accurate in comparison to the marker corners. Calibration using a standard Board should only be
|
||||
employed in those scenarios where the ChArUco boards cannot be employed because of any kind of restriction.
|
||||
|
||||
Calibration with ChArUco Boards
|
||||
-------------------------------
|
||||
|
||||
To calibrate using a ChArUco board, it is necessary to detect the board from different viewpoints, in the
|
||||
same way that the standard calibration does with the traditional chessboard pattern. However, due to the
|
||||
benefits of using ChArUco, occlusions and partial views are allowed, and not all the corners need to be
|
||||
visible in all the viewpoints.
|
||||
|
||||

|
||||
|
||||
The example of using `cv::calibrateCamera()` for cv::aruco::CharucoBoard:
|
||||
|
||||
@snippet samples/cpp/tutorial_code/objectDetection/calibrate_camera_charuco.cpp CalibrationWithCharucoBoard1
|
||||
@snippet samples/cpp/tutorial_code/objectDetection/calibrate_camera_charuco.cpp CalibrationWithCharucoBoard2
|
||||
@snippet samples/cpp/tutorial_code/objectDetection/calibrate_camera_charuco.cpp CalibrationWithCharucoBoard3
|
||||
|
||||
The ChArUco corners and ChArUco identifiers captured on each viewpoint are stored in the vectors
|
||||
`allCharucoCorners` and `allCharucoIds`, one element per viewpoint.
|
||||
|
||||
The `calibrateCamera()` function will fill the `cameraMatrix` and `distCoeffs` arrays with the
|
||||
camera calibration parameters. It will return the reprojection error obtained from the calibration.
|
||||
The elements in `rvecs` and `tvecs` will be filled with the estimated pose of the camera
|
||||
(respect to the ChArUco board) in each of the viewpoints.
|
||||
|
||||
Finally, the `calibrationFlags` parameter determines some of the options for the calibration.
|
||||
|
||||
A full working example is included in the `calibrate_camera_charuco.cpp` inside the
|
||||
`samples/cpp/tutorial_code/objectDetection` folder.
|
||||
|
||||
The samples now take input via commandline via the `cv::CommandLineParser`. For this file the example
|
||||
parameters will look like:
|
||||
@code{.cpp}
|
||||
"camera_calib.txt" -w=5 -h=7 -sl=0.04 -ml=0.02 -d=10
|
||||
-v=path/img_%02d.jpg
|
||||
@endcode
|
||||
|
||||
The camera calibration parameters from `opencv/samples/cpp/tutorial_code/objectDetection/tutorial_camera_charuco.yml`
|
||||
were obtained by the `img_00.jpg-img_03.jpg` placed from this
|
||||
[folder](https://github.com/opencv/opencv_contrib/tree/4.6.0/modules/aruco/tutorials/aruco_calibration/images).
|
||||
|
||||
Calibration with ArUco Boards
|
||||
-----------------------------
|
||||
|
||||
As it has been stated, it is recommended the use of ChAruco boards instead of ArUco boards for camera
|
||||
calibration, since ChArUco corners are more accurate than marker corners. However, in some special cases
|
||||
it must be required to use calibration based on ArUco boards. As in the previous case, it requires
|
||||
the detections of an ArUco board from different viewpoints.
|
||||
|
||||

|
||||
|
||||
The example of using `cv::calibrateCamera()` for cv::aruco::GridBoard:
|
||||
|
||||
@snippet samples/cpp/tutorial_code/objectDetection/calibrate_camera.cpp CalibrationWithArucoBoard1
|
||||
@snippet samples/cpp/tutorial_code/objectDetection/calibrate_camera.cpp CalibrationWithArucoBoard2
|
||||
@snippet samples/cpp/tutorial_code/objectDetection/calibrate_camera.cpp CalibrationWithArucoBoard3
|
||||
|
||||
A full working example is included in the `calibrate_camera.cpp` inside the `samples/cpp/tutorial_code/objectDetection` folder.
|
||||
|
||||
The samples now take input via commandline via the `cv::CommandLineParser`. For this file the example
|
||||
parameters will look like:
|
||||
@code{.cpp}
|
||||
"camera_calib.txt" -w=5 -h=7 -l=100 -s=10 -d=10 -v=path/aruco_videos_or_images
|
||||
@endcode
|
||||
|
After Width: | Height: | Size: 86 KiB |
|
After Width: | Height: | Size: 75 KiB |
@@ -0,0 +1,191 @@
|
||||
Aruco module FAQ {#tutorial_aruco_faq}
|
||||
================
|
||||
|
||||
@prev_tutorial{tutorial_aruco_calibration}
|
||||
@next_tutorial{tutorial_barcode_detect_and_decode}
|
||||
|
||||
This is a compilation of questions that can be useful for those that want to use the aruco module.
|
||||
|
||||
- I only want to label some objects, what should I use?
|
||||
|
||||
In this case, you only need single ArUco markers. You can place one or several markers with different
|
||||
ids in each of the object you want to identify.
|
||||
|
||||
|
||||
- Which algorithm is used for marker detection?
|
||||
|
||||
The aruco module is based on the original ArUco library. A full description of the detection process
|
||||
can be found in:
|
||||
|
||||
> S. Garrido-Jurado, R. Muñoz-Salinas, F. J. Madrid-Cuevas, and M. J. Marín-Jiménez. 2014.
|
||||
> "Automatic generation and detection of highly reliable fiducial markers under occlusion".
|
||||
> Pattern Recogn. 47, 6 (June 2014), 2280-2292. DOI=10.1016/j.patcog.2014.01.005
|
||||
|
||||
|
||||
- My markers are not being detected correctly, what can I do?
|
||||
|
||||
There can be many factors that avoid the correct detection of markers. You probably need to adjust
|
||||
some of the parameters in the `cv::aruco::DetectorParameters` object. The first thing you can do is
|
||||
checking if your markers are returned as rejected candidates by the `cv::aruco::ArucoDetector::detectMarkers()`
|
||||
function. Depending on this, you should try to modify different parameters.
|
||||
|
||||
If you are using a ArUco board, you can also try the `cv::aruco::ArucoDetector::refineDetectedMarkers()` function.
|
||||
If you are [using big markers](https://github.com/opencv/opencv_contrib/issues/2811) (400x400 pixels and more), try
|
||||
increasing `cv::aruco::DetectorParameters::adaptiveThreshWinSizeMax` value.
|
||||
Also avoid [narrow borders around the ArUco marker](https://github.com/opencv/opencv_contrib/issues/2492)
|
||||
(5% or less of the marker perimeter, adjusted by `cv::aruco::DetectorParameters::minMarkerDistanceRate`)
|
||||
around markers.
|
||||
|
||||
|
||||
- What are the benefits of ArUco boards? What are the drawbacks?
|
||||
|
||||
Using a board of markers you can obtain the camera pose from a set of markers, instead of a single one.
|
||||
This way, the detection is able to handle occlusion of partial views of the Board, since only one
|
||||
marker is necessary to obtain the pose.
|
||||
|
||||
Furthermore, as in most cases you are using more corners for pose estimation, it will be more
|
||||
accurate than using a single marker.
|
||||
|
||||
The main drawback is that a Board is not as versatile as a single marker.
|
||||
|
||||
|
||||
|
||||
- What are the benefits of ChArUco boards over ArUco boards? And the drawbacks?
|
||||
|
||||
ChArUco boards combines chessboards with ArUco boards. Thanks to this, the corners provided by
|
||||
ChArUco boards are more accurate than those provided by ArUco Boards (or single markers).
|
||||
|
||||
The main drawback is that ChArUco boards are not as versatile as ArUco board. For instance,
|
||||
a ChArUco board is a planar board with a specific marker layout while the ArUco boards can have
|
||||
any layout, even in 3d. Furthermore, the markers in the ChArUco board are usually smaller and
|
||||
more difficult to detect.
|
||||
|
||||
|
||||
- I do not need pose estimation, should I use ChArUco boards?
|
||||
|
||||
No. The main goal of ChArUco boards is provide high accurate corners for pose estimation or camera
|
||||
calibration.
|
||||
|
||||
|
||||
- Should all the markers in an ArUco board be placed in the same plane?
|
||||
|
||||
No, the marker corners in a ArUco board can be placed anywhere in its 3d coordinate system.
|
||||
|
||||
|
||||
- Should all the markers in an ChArUco board be placed in the same plane?
|
||||
|
||||
Yes, all the markers in a ChArUco board need to be in the same plane and their layout is fixed by
|
||||
the chessboard shape.
|
||||
|
||||
|
||||
- What is the difference between a `cv::aruco::Board` object and a `cv::aruco::GridBoard` object?
|
||||
|
||||
The `cv::aruco::GridBoard` class is a specific type of board that inherits from `cv::aruco::Board` class.
|
||||
A `cv::aruco::GridBoard` object is a board whose markers are placed in the same plane and in a grid layout.
|
||||
|
||||
|
||||
- What are Diamond markers?
|
||||
|
||||
Diamond markers are very similar to a ChArUco board of 3x3 squares. However, contrary to ChArUco boards,
|
||||
the detection of diamonds is based on the relative position of the markers.
|
||||
They are useful when you want to provide a conceptual meaning to any (or all) of the markers in
|
||||
the diamond. An example is using one of the marker to provide the diamond scale.
|
||||
|
||||
|
||||
- Do I need to detect marker before board detection, ChArUco board detection or Diamond detection?
|
||||
|
||||
Yes, the detection of single markers is a basic tool in the aruco module. It is done using the
|
||||
`cv::aruco::DetectorParameters::detectMarkers()` function. The rest of functionalities receives
|
||||
a list of detected markers from this function.
|
||||
|
||||
|
||||
- I want to calibrate my camera, can I use this module?
|
||||
|
||||
Yes, the aruco module provides functionalities to calibrate the camera using both, ArUco boards and
|
||||
ChArUco boards.
|
||||
|
||||
|
||||
- Should I calibrate using a ChArUco board or an ArUco board?
|
||||
|
||||
It is highly recommended the calibration using ChArUco board due to the high accuracy.
|
||||
|
||||
|
||||
- Should I use a predefined dictionary or generate my own dictionary?
|
||||
|
||||
In general, it is easier to use one of the predefined dictionaries. However, if you need a bigger
|
||||
dictionary (in terms of number of markers or number of bits) you should generate your own dictionary.
|
||||
Dictionary generation is also useful if you want to maximize the inter-marker distance to achieve
|
||||
a better error correction during the identification step.
|
||||
|
||||
- I am generating my own dictionary but it takes too long
|
||||
|
||||
Dictionary generation should only be done once at the beginning of your application and it should take
|
||||
some seconds. If you are generating the dictionary on each iteration of your detection loop, you are
|
||||
doing it wrong.
|
||||
|
||||
Furthermore, it is recommendable to save the dictionary to a file with `cv::aruco::Dictionary::writeDictionary()`
|
||||
and read it with `cv::aruco::Dictionary::readDictionary()` on every execution, so you don't need
|
||||
to generate it.
|
||||
|
||||
|
||||
- I would like to use some markers of the original ArUco library that I have already printed, can I use them?
|
||||
|
||||
Yes, one of the predefined dictionary is `cv::aruco::DICT_ARUCO_ORIGINAL`, which detects the marker
|
||||
of the original ArUco library with the same identifiers.
|
||||
|
||||
|
||||
- Can I use the Board configuration file of the original ArUco library in this module?
|
||||
|
||||
Not directly, you will need to adapt the information of the ArUco file to the aruco module Board format.
|
||||
|
||||
|
||||
- Can I use this module to detect the markers of other libraries based on binary fiducial markers?
|
||||
|
||||
Probably yes, however you will need to port the dictionary of the original library to the aruco module format.
|
||||
|
||||
|
||||
- Do I need to store the Dictionary information in a file so I can use it in different executions?
|
||||
|
||||
If you are using one of the predefined dictionaries, it is not necessary. Otherwise, it is recommendable
|
||||
that you save it to file.
|
||||
|
||||
|
||||
- Do I need to store the Board information in a file so I can use it in different executions?
|
||||
|
||||
If you are using a `cv::aruco::GridBoard` or a `cv::aruco::CharucoBoard` you only need to store
|
||||
the board measurements that are provided to the `cv::aruco::GridBoard::GridBoard()` constructor or
|
||||
in or `cv::aruco::CharucoBoard` constructor. If you manually modify the marker ids of the boards,
|
||||
or if you use a different type of board, you should save your board object to file.
|
||||
|
||||
- Does the aruco module provide functions to save the Dictionary or Board to file?
|
||||
|
||||
You can use `cv::aruco::Dictionary::writeDictionary()` and `cv::aruco::Dictionary::readDictionary()`
|
||||
for `cv::aruco::Dictionary`. The data member of board classes are public and can be easily stored.
|
||||
|
||||
|
||||
- Alright, but how can I render a 3d model to create an augmented reality application?
|
||||
|
||||
To do so, you will need to use an external rendering engine library, such as OpenGL. The aruco module
|
||||
only provides the functionality to obtain the camera pose, i.e. the rotation and traslation vectors,
|
||||
which is necessary to create the augmented reality effect. However, you will need to adapt the rotation
|
||||
and traslation vectors from the OpenCV format to the format accepted by your 3d rendering library.
|
||||
The original ArUco library contains examples of how to do it for OpenGL and Ogre3D.
|
||||
|
||||
|
||||
- I have use this module in my research work, how can I cite it?
|
||||
|
||||
You can cite the original ArUco library:
|
||||
|
||||
> S. Garrido-Jurado, R. Muñoz-Salinas, F. J. Madrid-Cuevas, and M. J. Marín-Jiménez. 2014.
|
||||
> "Automatic generation and detection of highly reliable fiducial markers under occlusion".
|
||||
> Pattern Recogn. 47, 6 (June 2014), 2280-2292. DOI=10.1016/j.patcog.2014.01.005
|
||||
|
||||
- Pose estimation markers are not being detected correctly, what can I do?
|
||||
|
||||
It is important to remark that the estimation of the pose using only 4 coplanar points is subject to ambiguity.
|
||||
In general, the ambiguity can be solved, if the camera is near to the marker.
|
||||
However, as the marker becomes small, the errors in the corner estimation grows and ambiguity comes
|
||||
as a problem. Try increasing the size of the marker you're using, and you can also try non-symmetrical
|
||||
(aruco_dict_utils.cpp) markers to avoid collisions. Use multiple markers (ArUco/ChArUco/Diamonds boards)
|
||||
and pose estimation with solvePnP() with the `cv::SOLVEPNP_IPPE_SQUARE` option.
|
||||
More in [this issue](https://github.com/opencv/opencv/issues/8813).
|
||||
@@ -3,7 +3,7 @@ Barcode Recognition {#tutorial_barcode_detect_and_decode}
|
||||
|
||||
@tableofcontents
|
||||
|
||||
@prev_tutorial{tutorial_aruco_board_detection}
|
||||
@prev_tutorial{tutorial_aruco_faq}
|
||||
|
||||
| | |
|
||||
| -: | :- |
|
||||
|
||||
@@ -0,0 +1,265 @@
|
||||
Detection of ChArUco Boards {#tutorial_charuco_detection}
|
||||
===========================
|
||||
|
||||
@prev_tutorial{tutorial_aruco_board_detection}
|
||||
@next_tutorial{tutorial_charuco_diamond_detection}
|
||||
|
||||
ArUco markers and boards are very useful due to their fast detection and their versatility.
|
||||
However, one of the problems of ArUco markers is that the accuracy of their corner positions is not
|
||||
too high, even after applying subpixel refinement.
|
||||
|
||||
On the contrary, the corners of chessboard patterns can be refined more accurately since each corner
|
||||
is surrounded by two black squares. However, finding a chessboard pattern is not as versatile as
|
||||
finding an ArUco board: it has to be completely visible and occlusions are not permitted.
|
||||
|
||||
A ChArUco board tries to combine the benefits of these two approaches:
|
||||
|
||||

|
||||
|
||||
The ArUco part is used to interpolate the position of the chessboard corners, so that it has the
|
||||
versatility of marker boards, since it allows occlusions or partial views. Moreover, since the
|
||||
interpolated corners belong to a chessboard, they are very accurate in terms of subpixel accuracy.
|
||||
|
||||
When high precision is necessary, such as in camera calibration, Charuco boards are a better option
|
||||
than standard ArUco boards.
|
||||
|
||||
Goal
|
||||
----
|
||||
|
||||
In this tutorial you will learn:
|
||||
|
||||
- How to create a charuco board ?
|
||||
- How to detect the charuco corners without performing camera calibration ?
|
||||
- How to detect the charuco corners with camera calibration and pose estimation ?
|
||||
|
||||
Source code
|
||||
-----------
|
||||
|
||||
You can find this code in `samples/cpp/tutorial_code/objectDetection/detect_board_charuco.cpp`
|
||||
|
||||
Here's a sample code of how to achieve all the stuff enumerated at the goal list.
|
||||
|
||||
@snippet samples/cpp/tutorial_code/objectDetection/detect_board_charuco.cpp charuco_detect_board_full_sample
|
||||
|
||||
ChArUco Board Creation
|
||||
----------------------
|
||||
|
||||
The aruco module provides the `cv::aruco::CharucoBoard` class that represents a Charuco Board and
|
||||
which inherits from the `cv::aruco::Board` class.
|
||||
|
||||
This class, as the rest of ChArUco functionalities, are defined in:
|
||||
|
||||
@snippet samples/cpp/tutorial_code/objectDetection/detect_board_charuco.cpp charucohdr
|
||||
|
||||
To define a `cv::aruco::CharucoBoard`, it is necessary:
|
||||
|
||||
- Number of chessboard squares in X and Y directions.
|
||||
- Length of square side.
|
||||
- Length of marker side.
|
||||
- The dictionary of the markers.
|
||||
- Ids of all the markers.
|
||||
|
||||
As for the `cv::aruco::GridBoard` objects, the aruco module provides to create `cv::aruco::CharucoBoard`
|
||||
easily. This object can be easily created from these parameters using the `cv::aruco::CharucoBoard`
|
||||
constructor:
|
||||
|
||||
@snippet samples/cpp/tutorial_code/objectDetection/create_board_charuco.cpp create_charucoBoard
|
||||
|
||||
- The first parameter is the number of squares in X and Y direction respectively.
|
||||
- The second and third parameters are the length of the squares and the markers respectively. They can
|
||||
be provided in any unit, having in mind that the estimated pose for this board would be measured
|
||||
in the same units (usually meters are used).
|
||||
- Finally, the dictionary of the markers is provided.
|
||||
|
||||
The ids of each of the markers are assigned by default in ascending order and starting on 0, like in
|
||||
`cv::aruco::GridBoard` constructor. This can be easily customized by accessing to the ids vector
|
||||
through `board.ids`, like in the `cv::aruco::Board` parent class.
|
||||
|
||||
Once we have our `cv::aruco::CharucoBoard` object, we can create an image to print it. There are
|
||||
two ways to do this:
|
||||
1. By using the script `doc/patter_tools/gen_pattern.py `, see @subpage tutorial_camera_calibration_pattern.
|
||||
2. By using the function `cv::aruco::CharucoBoard::generateImage()`.
|
||||
|
||||
The function `cv::aruco::CharucoBoard::generateImage()` is provided in cv::aruco::CharucoBoard class
|
||||
and can be called by using the following code:
|
||||
@snippet samples/cpp/tutorial_code/objectDetection/create_board_charuco.cpp generate_charucoBoard
|
||||
|
||||
- The first parameter is the size of the output image in pixels. If this is not proportional
|
||||
to the board dimensions, it will be centered on the image.
|
||||
- The second parameter is the output image with the charuco board.
|
||||
- The third parameter is the (optional) margin in pixels, so none of the markers are touching the
|
||||
image border.
|
||||
- Finally, the size of the marker border, similarly to `cv::aruco::generateImageMarker()` function.
|
||||
The default value is 1.
|
||||
|
||||
The output image will be something like this:
|
||||
|
||||

|
||||
|
||||
A full working example is included in the `create_board_charuco.cpp` inside the `samples/cpp/tutorial_code/objectDetection/`.
|
||||
|
||||
The samples `create_board_charuco.cpp` now take input via commandline via the `cv::CommandLineParser`.
|
||||
For this file the example
|
||||
parameters will look like:
|
||||
@code{.cpp}
|
||||
"_output_path_/chboard.png" -w=5 -h=7 -sl=100 -ml=60 -d=10
|
||||
@endcode
|
||||
|
||||
|
||||
ChArUco Board Detection
|
||||
-----------------------
|
||||
|
||||
When you detect a ChArUco board, what you are actually detecting is each of the chessboard corners
|
||||
of the board.
|
||||
|
||||
Each corner on a ChArUco board has a unique identifier (id) assigned. These ids go from 0 to the total
|
||||
number of corners in the board.
|
||||
The steps of charuco board detection can be broken down to the following steps:
|
||||
|
||||
- **Taking input Image**
|
||||
|
||||
@snippet samples/cpp/tutorial_code/objectDetection/detect_board_charuco.cpp inputImg
|
||||
|
||||
The original image where the markers are to be detected. The image is necessary to perform subpixel
|
||||
refinement in the ChArUco corners.
|
||||
|
||||
- **Reading the camera calibration Parameters(only for detection with camera calibration)**
|
||||
|
||||
@snippet samples/cpp/tutorial_code/objectDetection/aruco_samples_utility.hpp camDistCoeffs
|
||||
|
||||
The parameters of `readCameraParameters` are:
|
||||
- The first parameter is the path to the camera intrinsic matrix and distortion coefficients.
|
||||
- The second and third parameters are cameraMatrix and distCoeffs.
|
||||
|
||||
This function takes these parameters as input and returns a boolean value of whether the camera
|
||||
calibration parameters are valid or not. For detection of charuco corners without calibration,
|
||||
this step is not required.
|
||||
|
||||
- **Detecting the markers and interpolation of charuco corners from markers**
|
||||
|
||||
The detection of the ChArUco corners is based on the previous detected markers.
|
||||
So that, first markers are detected, and then ChArUco corners are interpolated from markers.
|
||||
The method that detect the ChArUco corners is `cv::aruco::CharucoDetector::detectBoard()`.
|
||||
|
||||
@snippet samples/cpp/tutorial_code/objectDetection/detect_board_charuco.cpp interpolateCornersCharuco
|
||||
|
||||
The parameters of detectBoard are:
|
||||
- `image` - Input image.
|
||||
- `charucoCorners` - output list of image positions of the detected corners.
|
||||
- `charucoIds` - output ids for each of the detected corners in `charucoCorners`.
|
||||
- `markerCorners` - input/output vector of detected marker corners.
|
||||
- `markerIds` - input/output vector of identifiers of the detected markers
|
||||
|
||||
If markerCorners and markerIds are empty, the function will detect aruco markers and ids.
|
||||
|
||||
If calibration parameters are provided, the ChArUco corners are interpolated by, first, estimating
|
||||
a rough pose from the ArUco markers and, then, reprojecting the ChArUco corners back to the image.
|
||||
|
||||
On the other hand, if calibration parameters are not provided, the ChArUco corners are interpolated
|
||||
by calculating the corresponding homography between the ChArUco plane and the ChArUco image projection.
|
||||
|
||||
The main problem of using homography is that the interpolation is more sensible to image distortion.
|
||||
Actually, the homography is only performed using the closest markers of each ChArUco corner to reduce
|
||||
the effect of distortion.
|
||||
|
||||
When detecting markers for ChArUco boards, and specially when using homography, it is recommended to
|
||||
disable the corner refinement of markers. The reason of this is that, due to the proximity of the
|
||||
chessboard squares, the subpixel process can produce important deviations in the corner positions and
|
||||
these deviations are propagated to the ChArUco corner interpolation, producing poor results.
|
||||
|
||||
@note To avoid deviations, the margin between chessboard square and aruco marker should be greater
|
||||
than 70% of one marker module.
|
||||
|
||||
Furthermore, only those corners whose two surrounding markers have be found are returned. If any of
|
||||
the two surrounding markers has not been detected, this usually means that there is some occlusion
|
||||
or the image quality is not good in that zone. In any case, it is preferable not to consider that
|
||||
corner, since what we want is to be sure that the interpolated ChArUco corners are very accurate.
|
||||
|
||||
After the ChArUco corners have been interpolated, a subpixel refinement is performed.
|
||||
|
||||
Once we have interpolated the ChArUco corners, we would probably want to draw them to see if their
|
||||
detections are correct. This can be easily done using the `cv::aruco::drawDetectedCornersCharuco()`
|
||||
function:
|
||||
|
||||
@snippet samples/cpp/tutorial_code/objectDetection/detect_board_charuco.cpp drawDetectedCornersCharuco
|
||||
|
||||
- `imageCopy` is the image where the corners will be drawn (it will normally be the same image where
|
||||
the corners were detected).
|
||||
- The `outputImage` will be a clone of `inputImage` with the corners drawn.
|
||||
- `charucoCorners` and `charucoIds` are the detected Charuco corners from the `cv::aruco::CharucoDetector::detectBoard()`
|
||||
function.
|
||||
- Finally, the last parameter is the (optional) color we want to draw the corners with, of type `cv::Scalar`.
|
||||
|
||||
For this image:
|
||||
|
||||

|
||||
|
||||
The result will be:
|
||||
|
||||

|
||||
|
||||
In the presence of occlusion. like in the following image, although some corners are clearly visible,
|
||||
not all their surrounding markers have been detected due occlusion and, thus, they are not interpolated:
|
||||
|
||||

|
||||
|
||||
Sample video:
|
||||
|
||||
@youtube{Nj44m_N_9FY}
|
||||
|
||||
A full working example is included in the `detect_board_charuco.cpp` inside the
|
||||
`samples/cpp/tutorial_code/objectDetection/`.
|
||||
|
||||
The samples `detect_board_charuco.cpp` now take input via commandline via the `cv::CommandLineParser`.
|
||||
For this file the example parameters will look like:
|
||||
@code{.cpp}
|
||||
-w=5 -h=7 -sl=0.04 -ml=0.02 -d=10 -v=/path_to_opencv/opencv/doc/tutorials/objdetect/charuco_detection/images/choriginal.jpg
|
||||
@endcode
|
||||
|
||||
ChArUco Pose Estimation
|
||||
-----------------------
|
||||
|
||||
The final goal of the ChArUco boards is finding corners very accurately for a high precision calibration
|
||||
or pose estimation.
|
||||
|
||||
The aruco module provides a function to perform ChArUco pose estimation easily. As in the
|
||||
`cv::aruco::GridBoard`, the coordinate system of the `cv::aruco::CharucoBoard` is placed in
|
||||
the board plane with the Z axis pointing in, and centered in the bottom left corner of the board.
|
||||
|
||||
@note After OpenCV 4.6.0, there was an incompatible change in the coordinate systems of the boards,
|
||||
now the coordinate systems are placed in the boards plane with the Z axis pointing in the plane
|
||||
(previously the axis pointed out the plane).
|
||||
`objPoints` in CW order correspond to the Z-axis pointing in the plane.
|
||||
`objPoints` in CCW order correspond to the Z-axis pointing out the plane.
|
||||
See PR https://github.com/opencv/opencv_contrib/pull/3174
|
||||
|
||||
|
||||
To perform pose estimation for charuco boards, you should use `cv::aruco::CharucoBoard::matchImagePoints()`
|
||||
and `cv::solvePnP()`:
|
||||
|
||||
@snippet samples/cpp/tutorial_code/objectDetection/detect_board_charuco.cpp poseCharuco
|
||||
|
||||
- The `charucoCorners` and `charucoIds` parameters are the detected charuco corners from the
|
||||
`cv::aruco::CharucoDetector::detectBoard()` function.
|
||||
- The `cameraMatrix` and `distCoeffs` are the camera calibration parameters which are necessary
|
||||
for pose estimation.
|
||||
- Finally, the `rvec` and `tvec` parameters are the output pose of the Charuco Board.
|
||||
- `cv::solvePnP()` returns true if the pose was correctly estimated and false otherwise.
|
||||
The main reason of failing is that there are not enough corners for pose estimation or
|
||||
they are in the same line.
|
||||
|
||||
The axis can be drawn using `cv::drawFrameAxes()` to check the pose is correctly estimated.
|
||||
The result would be: (X:red, Y:green, Z:blue)
|
||||
|
||||

|
||||
|
||||
A full working example is included in the `detect_board_charuco.cpp` inside the
|
||||
`samples/cpp/tutorial_code/objectDetection/`.
|
||||
|
||||
The samples `detect_board_charuco.cpp` now take input via commandline via the `cv::CommandLineParser`.
|
||||
For this file the example parameters will look like:
|
||||
@code{.cpp}
|
||||
-w=5 -h=7 -sl=0.04 -ml=0.02 -d=10
|
||||
-v=/path_to_opencv/opencv/doc/tutorials/objdetect/charuco_detection/images/choriginal.jpg
|
||||
-c=/path_to_opencv/opencv/samples/cpp/tutorial_code/objectDetection/tutorial_camera_charuco.yml
|
||||
@endcode
|
||||
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 94 KiB |
|
After Width: | Height: | Size: 93 KiB |
|
After Width: | Height: | Size: 87 KiB |
|
After Width: | Height: | Size: 112 KiB |
|
After Width: | Height: | Size: 115 KiB |
@@ -0,0 +1,143 @@
|
||||
Detection of Diamond Markers {#tutorial_charuco_diamond_detection}
|
||||
==============================
|
||||
|
||||
@prev_tutorial{tutorial_charuco_detection}
|
||||
@next_tutorial{tutorial_aruco_calibration}
|
||||
|
||||
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:
|
||||
|
||||
- To increase the number of identifiers of single markers by using diamond marker for labeling. They would allow
|
||||
up to N^4 different ids, being N the number of markers in the used dictionary.
|
||||
|
||||
- Give to each of the four markers a conceptual meaning. For instance, one of the four marker ids could be
|
||||
used to indicate the scale of the marker (i.e. the size of the square), so that the same diamond can be found
|
||||
in the environment with different sizes just by changing one of the four markers and the user does not need
|
||||
to manually indicate the scale of each of them. This case is included in the `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>`
|
||||
|
||||
|
||||
ChArUco Diamond Creation
|
||||
------
|
||||
|
||||
The image of a diamond marker can be easily created using the `cv::aruco::CharucoBoard::generateImage()` function.
|
||||
For instance:
|
||||
|
||||
@snippet samples/cpp/tutorial_code/objectDetection/create_diamond.cpp generate_diamond
|
||||
|
||||
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:
|
||||
@code{.cpp}
|
||||
"_path_/mydiamond.png" -sl=200 -ml=120 -d=10 -ids=0,1,2,3
|
||||
@endcode
|
||||
|
||||
ChArUco Diamond Detection
|
||||
------
|
||||
|
||||
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:
|
||||
|
||||
@snippet samples/cpp/tutorial_code/objectDetection/detect_diamonds.cpp detect_diamonds
|
||||
|
||||
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:
|
||||
|
||||
@snippet samples/cpp/tutorial_code/objectDetection/detect_diamonds.cpp draw_diamonds
|
||||
|
||||
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:
|
||||
@code{.cpp}
|
||||
-dp=path_to_opencv/opencv/samples/cpp/tutorial_code/objectDetection/detector_params.yml -sl=0.4 -ml=0.25 -refine=3
|
||||
-v=path_to_opencv/opencv/doc/tutorials/objdetect/charuco_diamond_detection/images/diamondmarkers.jpg
|
||||
-cd=path_to_opencv/opencv/samples/cpp/tutorial_code/objectDetection/tutorial_dict.yml
|
||||
@endcode
|
||||
|
||||
ChArUco Diamond Pose Estimation
|
||||
------
|
||||
|
||||
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:
|
||||
|
||||
@snippet samples/cpp/tutorial_code/objectDetection/detect_diamonds.cpp diamond_pose_estimation
|
||||
@snippet samples/cpp/tutorial_code/objectDetection/detect_diamonds.cpp draw_diamond_pose_estimation
|
||||
|
||||
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:
|
||||
|
||||
@youtube{OqKpBnglH7k}
|
||||
|
||||
Also ChArUco diamond pose can be estimated as ChArUco board:
|
||||
@snippet samples/cpp/tutorial_code/objectDetection/detect_diamonds.cpp diamond_pose_estimation_as_charuco
|
||||
|
||||
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:
|
||||
@code{.cpp}
|
||||
-dp=path_to_opencv/opencv/samples/cpp/tutorial_code/objectDetection/detector_params.yml -sl=0.4 -ml=0.25 -refine=3
|
||||
-v=path_to_opencv/opencv/doc/tutorials/objdetect/charuco_diamond_detection/images/diamondmarkers.jpg
|
||||
-cd=path_to_opencv/opencv/samples/cpp/tutorial_code/objectDetection/tutorial_dict.yml
|
||||
-c=path_to_opencv/opencv/samples/cpp/tutorial_code/objectDetection/tutorial_camera_params.yml
|
||||
@endcode
|
||||
|
After Width: | Height: | Size: 66 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 55 KiB |
|
After Width: | Height: | Size: 58 KiB |
@@ -3,4 +3,8 @@ Object Detection (objdetect module) {#tutorial_table_of_content_objdetect}
|
||||
|
||||
- @subpage tutorial_aruco_detection
|
||||
- @subpage tutorial_aruco_board_detection
|
||||
- @subpage tutorial_charuco_detection
|
||||
- @subpage tutorial_charuco_diamond_detection
|
||||
- @subpage tutorial_aruco_calibration
|
||||
- @subpage tutorial_aruco_faq
|
||||
- @subpage tutorial_barcode_detect_and_decode
|
||||
|
||||