|
| 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_ARUCO_BOARD_HPP__ |
| 5 | +#define __OPENCV_ARUCO_BOARD_HPP__ |
| 6 | + |
| 7 | +#include <opencv2/core.hpp> |
| 8 | +#include <vector> |
| 9 | + |
| 10 | +namespace cv { |
| 11 | +namespace aruco { |
| 12 | +//! @addtogroup aruco |
| 13 | +//! @{ |
| 14 | + |
| 15 | +class Dictionary; |
| 16 | + |
| 17 | +/** |
| 18 | + * @brief Board of markers |
| 19 | + * |
| 20 | + * A board is a set of markers in the 3D space with a common coordinate system. |
| 21 | + * The common form of a board of marker is a planar (2D) board, however any 3D layout can be used. |
| 22 | + * A Board object is composed by: |
| 23 | + * - The object points of the marker corners, i.e. their coordinates respect to the board system. |
| 24 | + * - The dictionary which indicates the type of markers of the board |
| 25 | + * - The identifier of all the markers in the board. |
| 26 | + */ |
| 27 | +class CV_EXPORTS_W Board { |
| 28 | +public: |
| 29 | + CV_WRAP Board(); |
| 30 | + |
| 31 | + /** @brief Provide way to create Board by passing necessary data. Specially needed in Python. |
| 32 | + * @param objPoints array of object points of all the marker corners in the board |
| 33 | + * @param dictionary the dictionary of markers employed for this board |
| 34 | + * @param ids vector of the identifiers of the markers in the board |
| 35 | + */ |
| 36 | + CV_WRAP static Ptr<Board> create(InputArrayOfArrays objPoints, const Ptr<Dictionary> &dictionary, InputArray ids); |
| 37 | + |
| 38 | + /** @brief Set ids vector |
| 39 | + * @param ids vector of the identifiers of the markers in the board (should be the same size |
| 40 | + * as objPoints) |
| 41 | + * |
| 42 | + * Recommended way to set ids vector, which will fail if the size of ids does not match size |
| 43 | + * of objPoints. |
| 44 | + */ |
| 45 | + CV_WRAP void setIds(InputArray ids); |
| 46 | + |
| 47 | + /** @brief change id for ids[index] |
| 48 | + * @param index - element index in ids |
| 49 | + * @param newId - new value for ids[index], should be less than Dictionary size |
| 50 | + */ |
| 51 | + CV_WRAP void changeId(int index, int newId); |
| 52 | + /** @brief return ids |
| 53 | + */ |
| 54 | + CV_WRAP const std::vector<int>& getIds() const; |
| 55 | + |
| 56 | + /** @brief set dictionary |
| 57 | + */ |
| 58 | + CV_WRAP void setDictionary(const Ptr<Dictionary> &dictionary); |
| 59 | + |
| 60 | + /** @brief return dictionary |
| 61 | + */ |
| 62 | + CV_WRAP Ptr<Dictionary> getDictionary() const; |
| 63 | + |
| 64 | + /** @brief set objPoints |
| 65 | + */ |
| 66 | + CV_WRAP void setObjPoints(const std::vector<std::vector<Point3f> > &objPoints); |
| 67 | + |
| 68 | + /** @brief get objPoints |
| 69 | + */ |
| 70 | + CV_WRAP const std::vector<std::vector<Point3f> >& getObjPoints() const; |
| 71 | + |
| 72 | + /** @brief get rightBottomBorder |
| 73 | + */ |
| 74 | + CV_WRAP const Point3f& getRightBottomBorder() const; |
| 75 | + |
| 76 | +protected: |
| 77 | + /** @brief array of object points of all the marker corners in the board each marker include its 4 corners in this order: |
| 78 | + * - objPoints[i][0] - left-top point of i-th marker |
| 79 | + * - objPoints[i][1] - right-top point of i-th marker |
| 80 | + * - objPoints[i][2] - right-bottom point of i-th marker |
| 81 | + * - objPoints[i][3] - left-bottom point of i-th marker |
| 82 | + * |
| 83 | + * Markers are placed in a certain order - row by row, left to right in every row. |
| 84 | + * For M markers, the size is Mx4. |
| 85 | + */ |
| 86 | + CV_PROP std::vector<std::vector<Point3f> > objPoints; |
| 87 | + |
| 88 | + /// the dictionary of markers employed for this board |
| 89 | + CV_PROP Ptr<Dictionary> dictionary; |
| 90 | + |
| 91 | + /// coordinate of the bottom right corner of the board, is set when calling the function create() |
| 92 | + CV_PROP Point3f rightBottomBorder; |
| 93 | + |
| 94 | + /** @brief vector of the identifiers of the markers in the board (same size than objPoints) |
| 95 | + * The identifiers refers to the board dictionary |
| 96 | + */ |
| 97 | + CV_PROP_RW std::vector<int> ids; |
| 98 | +}; |
| 99 | + |
| 100 | +/** |
| 101 | + * @brief Draw a planar board |
| 102 | + * @sa drawPlanarBoard |
| 103 | + * |
| 104 | + * @param board layout of the board that will be drawn. The board should be planar, |
| 105 | + * z coordinate is ignored |
| 106 | + * @param outSize size of the output image in pixels. |
| 107 | + * @param img output image with the board. The size of this image will be outSize |
| 108 | + * and the board will be on the center, keeping the board proportions. |
| 109 | + * @param marginSize minimum margins (in pixels) of the board in the output image |
| 110 | + * @param borderBits width of the marker borders. |
| 111 | + * |
| 112 | + * This function return the image of a planar board, ready to be printed. It assumes |
| 113 | + * the Board layout specified is planar by ignoring the z coordinates of the object points. |
| 114 | + */ |
| 115 | +CV_EXPORTS_W void drawPlanarBoard(const Ptr<Board> &board, Size outSize, OutputArray img, |
| 116 | + int marginSize = 0, int borderBits = 1); |
| 117 | + |
| 118 | +/** |
| 119 | + * @brief Planar board with grid arrangement of markers |
| 120 | + * More common type of board. All markers are placed in the same plane in a grid arrangement. |
| 121 | + * The board can be drawn using drawPlanarBoard() function (@sa drawPlanarBoard) |
| 122 | + */ |
| 123 | + |
| 124 | +class CV_EXPORTS_W GridBoard : public Board { |
| 125 | +public: |
| 126 | + CV_WRAP GridBoard(); |
| 127 | + /** |
| 128 | + * @brief Draw a GridBoard |
| 129 | + * |
| 130 | + * @param outSize size of the output image in pixels. |
| 131 | + * @param img output image with the board. The size of this image will be outSize |
| 132 | + * and the board will be on the center, keeping the board proportions. |
| 133 | + * @param marginSize minimum margins (in pixels) of the board in the output image |
| 134 | + * @param borderBits width of the marker borders. |
| 135 | + * |
| 136 | + * This function return the image of the GridBoard, ready to be printed. |
| 137 | + */ |
| 138 | + CV_WRAP void draw(Size outSize, OutputArray img, int marginSize = 0, int borderBits = 1); |
| 139 | + |
| 140 | + /** |
| 141 | + * @brief Create a GridBoard object |
| 142 | + * |
| 143 | + * @param markersX number of markers in X direction |
| 144 | + * @param markersY number of markers in Y direction |
| 145 | + * @param markerLength marker side length (normally in meters) |
| 146 | + * @param markerSeparation separation between two markers (same unit as markerLength) |
| 147 | + * @param dictionary dictionary of markers indicating the type of markers |
| 148 | + * @param firstMarker id of first marker in dictionary to use on board. |
| 149 | + * @return the output GridBoard object |
| 150 | + * |
| 151 | + * This functions creates a GridBoard object given the number of markers in each direction and |
| 152 | + * the marker size and marker separation. |
| 153 | + */ |
| 154 | + CV_WRAP static Ptr<GridBoard> create(int markersX, int markersY, float markerLength, float markerSeparation, |
| 155 | + const Ptr<Dictionary> &dictionary, int firstMarker = 0); |
| 156 | + |
| 157 | + CV_WRAP Size getGridSize() const; |
| 158 | + CV_WRAP float getMarkerLength() const; |
| 159 | + CV_WRAP float getMarkerSeparation() const; |
| 160 | + |
| 161 | +protected: |
| 162 | + struct GridImpl; |
| 163 | + Ptr<GridImpl> gridImpl; |
| 164 | + friend class CharucoBoard; |
| 165 | +}; |
| 166 | + |
| 167 | +/** |
| 168 | + * @brief ChArUco board |
| 169 | + * Specific class for ChArUco boards. A ChArUco board is a planar board where the markers are placed |
| 170 | + * inside the white squares of a chessboard. The benefits of ChArUco boards is that they provide |
| 171 | + * both, ArUco markers versatility and chessboard corner precision, which is important for |
| 172 | + * calibration and pose estimation. |
| 173 | + * This class also allows the easy creation and drawing of ChArUco boards. |
| 174 | + */ |
| 175 | +class CV_EXPORTS_W CharucoBoard : public Board { |
| 176 | +public: |
| 177 | + CV_WRAP CharucoBoard(); |
| 178 | + |
| 179 | + // vector of chessboard 3D corners precalculated |
| 180 | + CV_PROP std::vector<Point3f> chessboardCorners; |
| 181 | + |
| 182 | + // for each charuco corner, nearest marker id and nearest marker corner id of each marker |
| 183 | + CV_PROP std::vector<std::vector<int> > nearestMarkerIdx; |
| 184 | + CV_PROP std::vector<std::vector<int> > nearestMarkerCorners; |
| 185 | + |
| 186 | + /** @brief Draw a ChArUco board |
| 187 | + * |
| 188 | + * @param outSize size of the output image in pixels. |
| 189 | + * @param img output image with the board. The size of this image will be outSize |
| 190 | + * and the board will be on the center, keeping the board proportions. |
| 191 | + * @param marginSize minimum margins (in pixels) of the board in the output image |
| 192 | + * @param borderBits width of the marker borders. |
| 193 | + * |
| 194 | + * This function return the image of the ChArUco board, ready to be printed. |
| 195 | + */ |
| 196 | + CV_WRAP void draw(Size outSize, OutputArray img, int marginSize = 0, int borderBits = 1); |
| 197 | + |
| 198 | + |
| 199 | + /** @brief Create a CharucoBoard object |
| 200 | + * @param squaresX number of chessboard squares in X direction |
| 201 | + * @param squaresY number of chessboard squares in Y direction |
| 202 | + * @param squareLength chessboard square side length (normally in meters) |
| 203 | + * @param markerLength marker side length (same unit than squareLength) |
| 204 | + * @param dictionary dictionary of markers indicating the type of markers. |
| 205 | + * The first markers in the dictionary are used to fill the white chessboard squares. |
| 206 | + * @return the output CharucoBoard object |
| 207 | + * |
| 208 | + * This functions creates a CharucoBoard object given the number of squares in each direction |
| 209 | + * and the size of the markers and chessboard squares. |
| 210 | + */ |
| 211 | + CV_WRAP static Ptr<CharucoBoard> create(int squaresX, int squaresY, float squareLength, |
| 212 | + float markerLength, const Ptr<Dictionary> &dictionary); |
| 213 | + |
| 214 | + CV_WRAP Size getChessboardSize() const; |
| 215 | + CV_WRAP float getSquareLength() const; |
| 216 | + CV_WRAP float getMarkerLength() const; |
| 217 | + |
| 218 | +protected: |
| 219 | + struct CharucoImpl; |
| 220 | + Ptr<CharucoImpl> charucoImpl; |
| 221 | +}; |
| 222 | + |
| 223 | +/** |
| 224 | + * @brief test whether the ChArUco markers are collinear |
| 225 | + * |
| 226 | + * @param board layout of ChArUco board. |
| 227 | + * @param charucoIds list of identifiers for each corner in charucoCorners per frame. |
| 228 | + * @return bool value, 1 (true) if detected corners form a line, 0 (false) if they do not. |
| 229 | + * solvePnP, calibration functions will fail if the corners are collinear (true). |
| 230 | + * |
| 231 | + * The number of ids in charucoIDs should be <= the number of chessboard corners in the board. |
| 232 | + * This functions checks whether the charuco corners are on a straight line (returns true, if so), or not (false). |
| 233 | + * Axis parallel, as well as diagonal and other straight lines detected. Degenerate cases: |
| 234 | + * for number of charucoIDs <= 2,the function returns true. |
| 235 | + */ |
| 236 | +CV_EXPORTS_W bool testCharucoCornersCollinear(const Ptr<CharucoBoard> &board, InputArray charucoIds); |
| 237 | + |
| 238 | +//! @} |
| 239 | + |
| 240 | +} |
| 241 | +} |
| 242 | + |
| 243 | +#endif |
0 commit comments