diff --git a/doc/pattern_tools/gen_pattern.py b/doc/pattern_tools/gen_pattern.py index bec535baf6..f426bb11c5 100755 --- a/doc/pattern_tools/gen_pattern.py +++ b/doc/pattern_tools/gen_pattern.py @@ -186,6 +186,8 @@ class PatternMaker: yspacing = (self.height - self.rows * self.square_size) / 2.0 ch_ar_border = (self.square_size - self.aruco_marker_size)/2 + if ch_ar_border < side*0.7: + print("Marker border {} is less than 70% of ArUco pin size {}. Please increase --square_size or decrease --marker_size for stable board detection".format(ch_ar_border, int(side))) marker_id = 0 for y in range(0, self.rows): for x in range(0, self.cols): @@ -283,6 +285,9 @@ def main(): else: raise ValueError("The marker {},{} is outside the checkerboard".format(x, y)) + if p_type == "charuco_board" and aruco_marker_size >= square_size: + raise ValueError("ArUco markers size must be smaller than square size") + pm = PatternMaker(columns, rows, output, units, square_size, radius_rate, page_width, page_height, markers, aruco_marker_size, dict_file) # dict for easy lookup of pattern type mp = {"circles": pm.make_circles_pattern, "acircles": pm.make_acircles_pattern, diff --git a/modules/objdetect/src/aruco/aruco_board.cpp b/modules/objdetect/src/aruco/aruco_board.cpp index cf45a96450..3d4217e02a 100644 --- a/modules/objdetect/src/aruco/aruco_board.cpp +++ b/modules/objdetect/src/aruco/aruco_board.cpp @@ -3,6 +3,7 @@ // of this distribution and at http://opencv.org/license.html #include "../precomp.hpp" +#include #include "opencv2/objdetect/aruco_board.hpp" #include @@ -250,7 +251,11 @@ GridBoard::GridBoard() {} GridBoard::GridBoard(const Size& size, float markerLength, float markerSeparation, const Dictionary &dictionary, InputArray ids): Board(new GridBoardImpl(dictionary, size, markerLength, markerSeparation)) { - + float onePin = markerLength / ((float)(dictionary.markerSize+2)); + if (markerSeparation < onePin*.7f) { + CV_LOG_WARNING(NULL, "Marker border " << markerSeparation << " is less than 70% of ArUco pin size " + << onePin << ". Please increase markerSeparation or decrease markerLength for stable board detection"); + } size_t totalMarkers = (size_t) size.width*size.height; CV_Assert(ids.empty() || totalMarkers == ids.total()); vector > objPoints; @@ -541,7 +546,12 @@ CharucoBoard::CharucoBoard(const Size& size, float squareLength, float markerLen Board(new CharucoBoardImpl(dictionary, size, squareLength, markerLength)) { CV_Assert(size.width > 1 && size.height > 1 && markerLength > 0 && squareLength > markerLength); - + float onePin = markerLength / ((float)(dictionary.markerSize+2)); + float markerSeparation = (squareLength - markerLength)/2.f; + if (markerSeparation < onePin*.7f) { + CV_LOG_WARNING(NULL, "Marker border " << markerSeparation << " is less than 70% of ArUco pin size " + << onePin <<". Please increase markerSeparation or decrease markerLength for stable board detection"); + } ids.copyTo(impl->ids); static_pointer_cast(impl)->createCharucoBoard();