Skip to content

Commit 3a41fd6

Browse files
author
AleksandrPanov
committed
move april module
create aruco_utils.hpp move Board, GridBoard, CharucoBoard to board.hpp/board.cpp refactoring _getSingleMarkerObjectPoints() refactoring _extractBits() refactoring _findMarkerContours() fix _copyVector2Output() in detectMarkers() move testCharucoCornersCollinear() to board.hpp/board.cpp move poseEstimate()/calibAruco() to aruco_calib_pose.hpp reduce include files move detectMarkers() to class ArucoDetector move refineDetectedMarkers() to class ArucoDetector add C API wrapper to detectMarkers(), refineDetectedMarkers() update tests and samples to class API add py tests: test_aruco_detector, test_aruco_detector_refine refactoring, fix docs add java tests: testArucoIssue3133, testArucoDetector add readWriteParameter(), update readParameter() implemented cv::Algorithm - read/write, added read/write to RefineParameters, added write to DetectorParameters merge PatternPos/EstimateParameters after rebase remove empty docstring for private function fixes fixes license
1 parent 9d0a451 commit 3a41fd6

39 files changed

+3347
-3550
lines changed

modules/aruco/include/opencv2/aruco.hpp

Lines changed: 15 additions & 664 deletions
Large diffs are not rendered by default.

modules/aruco/include/opencv2/aruco/aruco_calib_pose.hpp

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

0 commit comments

Comments
 (0)