aruco_board.hpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html
  4. #ifndef OPENCV_OBJDETECT_ARUCO_BOARD_HPP
  5. #define OPENCV_OBJDETECT_ARUCO_BOARD_HPP
  6. #include <opencv2/core.hpp>
  7. namespace cv {
  8. namespace aruco {
  9. //! @addtogroup objdetect_aruco
  10. //! @{
  11. class Dictionary;
  12. /** @brief Board of ArUco markers
  13. *
  14. * A board is a set of markers in the 3D space with a common coordinate system.
  15. * The common form of a board of marker is a planar (2D) board, however any 3D layout can be used.
  16. * A Board object is composed by:
  17. * - The object points of the marker corners, i.e. their coordinates respect to the board system.
  18. * - The dictionary which indicates the type of markers of the board
  19. * - The identifier of all the markers in the board.
  20. */
  21. class CV_EXPORTS_W_SIMPLE Board {
  22. public:
  23. /** @brief Common Board constructor
  24. *
  25. * @param objPoints array of object points of all the marker corners in the board
  26. * @param dictionary the dictionary of markers employed for this board
  27. * @param ids vector of the identifiers of the markers in the board
  28. */
  29. CV_WRAP Board(InputArrayOfArrays objPoints, const Dictionary& dictionary, InputArray ids);
  30. /** @brief return the Dictionary of markers employed for this board
  31. */
  32. CV_WRAP const Dictionary& getDictionary() const;
  33. /** @brief return array of object points of all the marker corners in the board.
  34. *
  35. * Each marker include its 4 corners in this order:
  36. * - objPoints[i][0] - left-top point of i-th marker
  37. * - objPoints[i][1] - right-top point of i-th marker
  38. * - objPoints[i][2] - right-bottom point of i-th marker
  39. * - objPoints[i][3] - left-bottom point of i-th marker
  40. *
  41. * Markers are placed in a certain order - row by row, left to right in every row. For M markers, the size is Mx4.
  42. */
  43. CV_WRAP const std::vector<std::vector<Point3f> >& getObjPoints() const;
  44. /** @brief vector of the identifiers of the markers in the board (should be the same size as objPoints)
  45. * @return vector of the identifiers of the markers
  46. */
  47. CV_WRAP const std::vector<int>& getIds() const;
  48. /** @brief get coordinate of the bottom right corner of the board, is set when calling the function create()
  49. */
  50. CV_WRAP const Point3f& getRightBottomCorner() const;
  51. /** @brief Given a board configuration and a set of detected markers, returns the corresponding
  52. * image points and object points, can be used in solvePnP()
  53. *
  54. * @param detectedCorners List of detected marker corners of the board.
  55. * For cv::Board and cv::GridBoard the method expects std::vector<std::vector<Point2f>> or std::vector<Mat> with Aruco marker corners.
  56. * For cv::CharucoBoard the method expects std::vector<Point2f> or Mat with ChAruco corners (chess board corners matched with Aruco markers).
  57. *
  58. * @param detectedIds List of identifiers for each marker or charuco corner.
  59. * For any Board class the method expects std::vector<int> or Mat.
  60. *
  61. * @param objPoints Vector of marker points in the board coordinate space.
  62. * For any Board class the method expects std::vector<cv::Point3f> objectPoints or cv::Mat
  63. *
  64. * @param imgPoints Vector of marker points in the image coordinate space.
  65. * For any Board class the method expects std::vector<cv::Point2f> objectPoints or cv::Mat
  66. *
  67. * @sa solvePnP
  68. */
  69. CV_WRAP void matchImagePoints(InputArrayOfArrays detectedCorners, InputArray detectedIds,
  70. OutputArray objPoints, OutputArray imgPoints) const;
  71. /** @brief Draw a planar board
  72. *
  73. * @param outSize size of the output image in pixels.
  74. * @param img output image with the board. The size of this image will be outSize
  75. * and the board will be on the center, keeping the board proportions.
  76. * @param marginSize minimum margins (in pixels) of the board in the output image
  77. * @param borderBits width of the marker borders.
  78. *
  79. * This function return the image of the board, ready to be printed.
  80. */
  81. CV_WRAP void generateImage(Size outSize, OutputArray img, int marginSize = 0, int borderBits = 1) const;
  82. CV_DEPRECATED_EXTERNAL // avoid using in C++ code, will be moved to "protected" (need to fix bindings first)
  83. Board();
  84. struct Impl;
  85. protected:
  86. Board(const Ptr<Impl>& impl);
  87. Ptr<Impl> impl;
  88. };
  89. /** @brief Planar board with grid arrangement of markers
  90. *
  91. * More common type of board. All markers are placed in the same plane in a grid arrangement.
  92. * The board image can be drawn using generateImage() method.
  93. */
  94. class CV_EXPORTS_W_SIMPLE GridBoard : public Board {
  95. public:
  96. /**
  97. * @brief GridBoard constructor
  98. *
  99. * @param size number of markers in x and y directions
  100. * @param markerLength marker side length (normally in meters)
  101. * @param markerSeparation separation between two markers (same unit as markerLength)
  102. * @param dictionary dictionary of markers indicating the type of markers
  103. * @param ids set of marker ids in dictionary to use on board.
  104. */
  105. CV_WRAP GridBoard(const Size& size, float markerLength, float markerSeparation,
  106. const Dictionary &dictionary, InputArray ids = noArray());
  107. CV_WRAP Size getGridSize() const;
  108. CV_WRAP float getMarkerLength() const;
  109. CV_WRAP float getMarkerSeparation() const;
  110. CV_DEPRECATED_EXTERNAL // avoid using in C++ code, will be moved to "protected" (need to fix bindings first)
  111. GridBoard();
  112. };
  113. /**
  114. * @brief ChArUco board is a planar chessboard where the markers are placed inside the white squares of a chessboard.
  115. *
  116. * The benefits of ChArUco boards is that they provide both, ArUco markers versatility and chessboard corner precision,
  117. * which is important for calibration and pose estimation. The board image can be drawn using generateImage() method.
  118. */
  119. class CV_EXPORTS_W_SIMPLE CharucoBoard : public Board {
  120. public:
  121. /** @brief CharucoBoard constructor
  122. *
  123. * @param size number of chessboard squares in x and y directions
  124. * @param squareLength squareLength chessboard square side length (normally in meters)
  125. * @param markerLength marker side length (same unit than squareLength)
  126. * @param dictionary dictionary of markers indicating the type of markers
  127. * @param ids array of id used markers
  128. * The first markers in the dictionary are used to fill the white chessboard squares.
  129. */
  130. CV_WRAP CharucoBoard(const Size& size, float squareLength, float markerLength,
  131. const Dictionary &dictionary, InputArray ids = noArray());
  132. /** @brief set legacy chessboard pattern.
  133. *
  134. * Legacy setting creates chessboard patterns starting with a white box in the upper left corner
  135. * if there is an even row count of chessboard boxes, otherwise it starts with a black box.
  136. * This setting ensures compatibility to patterns created with OpenCV versions prior OpenCV 4.6.0.
  137. * See https://github.com/opencv/opencv/issues/23152.
  138. *
  139. * Default value: false.
  140. */
  141. CV_WRAP void setLegacyPattern(bool legacyPattern);
  142. CV_WRAP bool getLegacyPattern() const;
  143. CV_WRAP Size getChessboardSize() const;
  144. CV_WRAP float getSquareLength() const;
  145. CV_WRAP float getMarkerLength() const;
  146. /** @brief get CharucoBoard::chessboardCorners
  147. */
  148. CV_WRAP std::vector<Point3f> getChessboardCorners() const;
  149. /** @brief get CharucoBoard::nearestMarkerIdx, for each charuco corner, nearest marker index in ids array
  150. */
  151. CV_PROP std::vector<std::vector<int> > getNearestMarkerIdx() const;
  152. /** @brief get CharucoBoard::nearestMarkerCorners, for each charuco corner, nearest marker corner id of each marker
  153. */
  154. CV_PROP std::vector<std::vector<int> > getNearestMarkerCorners() const;
  155. /** @brief check whether the ChArUco markers are collinear
  156. *
  157. * @param charucoIds list of identifiers for each corner in charucoCorners per frame.
  158. * @return bool value, 1 (true) if detected corners form a line, 0 (false) if they do not.
  159. * solvePnP, calibration functions will fail if the corners are collinear (true).
  160. *
  161. * The number of ids in charucoIDs should be <= the number of chessboard corners in the board.
  162. * This functions checks whether the charuco corners are on a straight line (returns true, if so), or not (false).
  163. * Axis parallel, as well as diagonal and other straight lines detected. Degenerate cases:
  164. * for number of charucoIDs <= 2,the function returns true.
  165. */
  166. CV_WRAP bool checkCharucoCornersCollinear(InputArray charucoIds) const;
  167. CV_DEPRECATED_EXTERNAL // avoid using in C++ code, will be moved to "protected" (need to fix bindings first)
  168. CharucoBoard();
  169. };
  170. //! @}
  171. }
  172. }
  173. #endif