Skip to content

Commit 89988cf

Browse files
Alexander Panovhakaboom
Alexander Panov
authored andcommitted
Merge pull request opencv#3256 from AleksandrPanov:fix_aruco_axes_docs
fix axes and docs * fix axes docs, tutorial and add estimateParameters, change estimateParameters in test * update docs, add singlemarkersaxes2.jpg * fix docs
1 parent e2d8d4e commit 89988cf

File tree

4 files changed

+69
-10
lines changed

4 files changed

+69
-10
lines changed

modules/aruco/include/opencv2/aruco.hpp

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ the use of this software, even if advised of the possibility of such damage.
4040
#define __OPENCV_ARUCO_HPP__
4141

4242
#include <opencv2/core.hpp>
43+
#include <opencv2/calib3d.hpp>
4344
#include <vector>
4445
#include "opencv2/aruco/dictionary.hpp"
4546

@@ -243,7 +244,55 @@ struct CV_EXPORTS_W DetectorParameters {
243244
CV_EXPORTS_W void detectMarkers(InputArray image, const Ptr<Dictionary> &dictionary, OutputArrayOfArrays corners,
244245
OutputArray ids, const Ptr<DetectorParameters> &parameters = DetectorParameters::create(),
245246
OutputArrayOfArrays rejectedImgPoints = noArray());
247+
/** @brief
248+
* rvec/tvec define the right handed coordinate system of the marker.
249+
* PatternPos defines center this system and axes direction.
250+
* Axis X (red color) - first coordinate, axis Y (green color) - second coordinate,
251+
* axis Z (blue color) - third coordinate.
252+
* @sa estimatePoseSingleMarkers(), @ref tutorial_aruco_detection
253+
*/
254+
enum PatternPos {
255+
/** @brief The marker coordinate system is centered on the middle of the marker.
256+
* The coordinates of the four corners (CCW order) of the marker in its own coordinate system are:
257+
* (-markerLength/2, markerLength/2, 0), (markerLength/2, markerLength/2, 0),
258+
* (markerLength/2, -markerLength/2, 0), (-markerLength/2, -markerLength/2, 0).
259+
*
260+
* These pattern points define this coordinate system:
261+
* ![Image with axes drawn](images/singlemarkersaxes.jpg)
262+
*/
263+
CCW_center,
264+
/** @brief The marker coordinate system is centered on the top-left corner of the marker.
265+
* The coordinates of the four corners (CW order) of the marker in its own coordinate system are:
266+
* (0, 0, 0), (markerLength, 0, 0),
267+
* (markerLength, markerLength, 0), (0, markerLength, 0).
268+
*
269+
* These pattern points define this coordinate system:
270+
* ![Image with axes drawn](images/singlemarkersaxes2.jpg)
271+
*/
272+
CW_top_left_corner
273+
};
274+
275+
/** @brief
276+
* Pose estimation parameters
277+
* @param pattern Defines center this system and axes direction (default PatternPos::CCW_center).
278+
* @param useExtrinsicGuess Parameter used for SOLVEPNP_ITERATIVE. If true (1), the function uses the provided
279+
* rvec and tvec values as initial approximations of the rotation and translation vectors, respectively, and further
280+
* optimizes them (default false).
281+
* @param solvePnPMethod Method for solving a PnP problem: see @ref calib3d_solvePnP_flags (default SOLVEPNP_ITERATIVE).
282+
* @sa PatternPos, solvePnP(), @ref tutorial_aruco_detection
283+
*/
284+
struct CV_EXPORTS_W EstimateParameters {
285+
CV_PROP_RW PatternPos pattern;
286+
CV_PROP_RW bool useExtrinsicGuess;
287+
CV_PROP_RW SolvePnPMethod solvePnPMethod;
288+
289+
EstimateParameters(): pattern(CCW_center), useExtrinsicGuess(false),
290+
solvePnPMethod(SOLVEPNP_ITERATIVE) {}
246291

292+
CV_WRAP static Ptr<EstimateParameters> create() {
293+
return makePtr<EstimateParameters>();
294+
}
295+
};
247296

248297

249298
/**
@@ -264,21 +313,28 @@ CV_EXPORTS_W void detectMarkers(InputArray image, const Ptr<Dictionary> &diction
264313
* @param tvecs array of output translation vectors (e.g. std::vector<cv::Vec3d>).
265314
* Each element in tvecs corresponds to the specific marker in imgPoints.
266315
* @param _objPoints array of object points of all the marker corners
316+
* @param estimateParameters set the origin of coordinate system and the coordinates of the four corners of the marker
317+
* (default estimateParameters.pattern = PatternPos::CCW_center, estimateParameters.useExtrinsicGuess = false,
318+
* estimateParameters.solvePnPMethod = SOLVEPNP_ITERATIVE).
267319
*
268320
* This function receives the detected markers and returns their pose estimation respect to
269321
* the camera individually. So for each marker, one rotation and translation vector is returned.
270322
* The returned transformation is the one that transforms points from each marker coordinate system
271323
* to the camera coordinate system.
272-
* The marker corrdinate system is centered on the middle of the marker, with the Z axis
273-
* perpendicular to the marker plane.
274-
* The coordinates of the four corners of the marker in its own coordinate system are:
275-
* (0, 0, 0), (markerLength, 0, 0),
276-
* (markerLength, markerLength, 0), (0, markerLength, 0)
324+
* The marker coordinate system is centered on the middle (by default) or on the top-left corner of the marker,
325+
* with the Z axis perpendicular to the marker plane.
326+
* estimateParameters defines the coordinates of the four corners of the marker in its own coordinate system (by default) are:
327+
* (-markerLength/2, markerLength/2, 0), (markerLength/2, markerLength/2, 0),
328+
* (markerLength/2, -markerLength/2, 0), (-markerLength/2, -markerLength/2, 0)
277329
* @sa use cv::drawFrameAxes to get world coordinate system axis for object points
330+
* @sa @ref tutorial_aruco_detection
331+
* @sa EstimateParameters
332+
* @sa PatternPos
278333
*/
279334
CV_EXPORTS_W void estimatePoseSingleMarkers(InputArrayOfArrays corners, float markerLength,
280335
InputArray cameraMatrix, InputArray distCoeffs,
281-
OutputArray rvecs, OutputArray tvecs, OutputArray _objPoints = noArray());
336+
OutputArray rvecs, OutputArray tvecs, OutputArray _objPoints = noArray(),
337+
Ptr<EstimateParameters> estimateParameters = EstimateParameters::create());
282338

283339

284340

modules/aruco/test/test_charucodetection.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,12 @@ void CV_CharucoDiamondDetection::run(int) {
439439
}
440440
}
441441

442+
Ptr<aruco::EstimateParameters> estimateParameters = aruco::EstimateParameters::create();
443+
estimateParameters->pattern = aruco::CW_top_left_corner;
442444
// estimate diamond pose
443445
vector< Vec3d > estimatedRvec, estimatedTvec;
444-
aruco::estimatePoseSingleMarkers(diamondCorners, squareLength, cameraMatrix,
445-
distCoeffs, estimatedRvec, estimatedTvec);
446+
aruco::estimatePoseSingleMarkers(diamondCorners, squareLength, cameraMatrix, distCoeffs, estimatedRvec,
447+
estimatedTvec, noArray(), estimateParameters);
446448

447449
// check result
448450
vector< Point2f > projectedDiamondCornersPose;
Loading

modules/aruco/tutorials/aruco_detection/aruco_detection.markdown

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,9 @@ translation vectors of the estimated poses will be in the same unit
286286
- The output parameters `rvecs` and `tvecs` are the rotation and translation vectors respectively, for each of the markers
287287
in `markerCorners`.
288288

289-
The marker coordinate system that is assumed by this function is placed at the center of the marker
290-
with the Z axis pointing out, as in the following image. Axis-color correspondences are X: red, Y: green, Z: blue. Note the axis directions of the rotated markers in this image.
289+
The marker coordinate system that is assumed by this function is placed in the center (by default) or
290+
in the top left corner of the marker with the Z axis pointing out, as in the following image.
291+
Axis-color correspondences are X: red, Y: green, Z: blue. Note the axis directions of the rotated markers in this image.
291292

292293
![Image with axes drawn](images/singlemarkersaxes.jpg)
293294

0 commit comments

Comments
 (0)