aruco.hpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. /*
  2. By downloading, copying, installing or using the software you agree to this
  3. license. If you do not agree to this license, do not download, install,
  4. copy or use the software.
  5. License Agreement
  6. For Open Source Computer Vision Library
  7. (3-clause BSD License)
  8. Copyright (C) 2013, OpenCV Foundation, all rights reserved.
  9. Third party copyrights are property of their respective owners.
  10. Redistribution and use in source and binary forms, with or without modification,
  11. are permitted provided that the following conditions are met:
  12. * Redistributions of source code must retain the above copyright notice,
  13. this list of conditions and the following disclaimer.
  14. * Redistributions in binary form must reproduce the above copyright notice,
  15. this list of conditions and the following disclaimer in the documentation
  16. and/or other materials provided with the distribution.
  17. * Neither the names of the copyright holders nor the names of the contributors
  18. may be used to endorse or promote products derived from this software
  19. without specific prior written permission.
  20. This software is provided by the copyright holders and contributors "as is" and
  21. any express or implied warranties, including, but not limited to, the implied
  22. warranties of merchantability and fitness for a particular purpose are
  23. disclaimed. In no event shall copyright holders or contributors be liable for
  24. any direct, indirect, incidental, special, exemplary, or consequential damages
  25. (including, but not limited to, procurement of substitute goods or services;
  26. loss of use, data, or profits; or business interruption) however caused
  27. and on any theory of liability, whether in contract, strict liability,
  28. or tort (including negligence or otherwise) arising in any way out of
  29. the use of this software, even if advised of the possibility of such damage.
  30. */
  31. #ifndef __OPENCV_ARUCO_HPP__
  32. #define __OPENCV_ARUCO_HPP__
  33. #include <opencv2/core.hpp>
  34. #include <vector>
  35. #include "opencv2/aruco/dictionary.hpp"
  36. /**
  37. * @defgroup aruco ArUco Marker Detection
  38. * This module is dedicated to square fiducial markers (also known as Augmented Reality Markers)
  39. * These markers are useful for easy, fast and robust camera pose estimation.ç
  40. *
  41. * The main functionalities are:
  42. * - Detection of markers in a image
  43. * - Pose estimation from a single marker or from a board/set of markers
  44. * - Detection of ChArUco board for high subpixel accuracy
  45. * - Camera calibration from both, ArUco boards and ChArUco boards.
  46. * - Detection of ChArUco diamond markers
  47. * The samples directory includes easy examples of how to use the module.
  48. *
  49. * The implementation is based on the ArUco Library by R. Muñoz-Salinas and S. Garrido-Jurado.
  50. *
  51. * @sa S. Garrido-Jurado, R. Muñoz-Salinas, F. J. Madrid-Cuevas, and M. J. Marín-Jiménez. 2014.
  52. * "Automatic generation and detection of highly reliable fiducial markers under occlusion".
  53. * Pattern Recogn. 47, 6 (June 2014), 2280-2292. DOI=10.1016/j.patcog.2014.01.005
  54. *
  55. * @sa http://www.uco.es/investiga/grupos/ava/node/26
  56. *
  57. * This module has been originally developed by Sergio Garrido-Jurado as a project
  58. * for Google Summer of Code 2015 (GSoC 15).
  59. *
  60. *
  61. */
  62. namespace cv {
  63. namespace aruco {
  64. //! @addtogroup aruco
  65. //! @{
  66. enum CornerRefineMethod{
  67. CORNER_REFINE_NONE, // default corners
  68. CORNER_REFINE_SUBPIX, // refine the corners using subpix
  69. CORNER_REFINE_CONTOUR // refine the corners using the contour-points
  70. };
  71. /**
  72. * @brief Parameters for the detectMarker process:
  73. * - adaptiveThreshWinSizeMin: minimum window size for adaptive thresholding before finding
  74. * contours (default 3).
  75. * - adaptiveThreshWinSizeMax: maximum window size for adaptive thresholding before finding
  76. * contours (default 23).
  77. * - adaptiveThreshWinSizeStep: increments from adaptiveThreshWinSizeMin to adaptiveThreshWinSizeMax
  78. * during the thresholding (default 10).
  79. * - adaptiveThreshConstant: constant for adaptive thresholding before finding contours (default 7)
  80. * - minMarkerPerimeterRate: determine minimum perimeter for marker contour to be detected. This
  81. * is defined as a rate respect to the maximum dimension of the input image (default 0.03).
  82. * - maxMarkerPerimeterRate: determine maximum perimeter for marker contour to be detected. This
  83. * is defined as a rate respect to the maximum dimension of the input image (default 4.0).
  84. * - polygonalApproxAccuracyRate: minimum accuracy during the polygonal approximation process to
  85. * determine which contours are squares.
  86. * - minCornerDistanceRate: minimum distance between corners for detected markers relative to its
  87. * perimeter (default 0.05)
  88. * - minDistanceToBorder: minimum distance of any corner to the image border for detected markers
  89. * (in pixels) (default 3)
  90. * - minMarkerDistanceRate: minimum mean distance beetween two marker corners to be considered
  91. * similar, so that the smaller one is removed. The rate is relative to the smaller perimeter
  92. * of the two markers (default 0.05).
  93. * - cornerRefinementMethod: corner refinement method. (CORNER_REFINE_NONE, no refinement.
  94. * CORNER_REFINE_SUBPIX, do subpixel refinement. CORNER_REFINE_CONTOUR use contour-Points)
  95. * - cornerRefinementWinSize: window size for the corner refinement process (in pixels) (default 5).
  96. * - cornerRefinementMaxIterations: maximum number of iterations for stop criteria of the corner
  97. * refinement process (default 30).
  98. * - cornerRefinementMinAccuracy: minimum error for the stop cristeria of the corner refinement
  99. * process (default: 0.1)
  100. * - markerBorderBits: number of bits of the marker border, i.e. marker border width (default 1).
  101. * - perpectiveRemovePixelPerCell: number of bits (per dimension) for each cell of the marker
  102. * when removing the perspective (default 8).
  103. * - perspectiveRemoveIgnoredMarginPerCell: width of the margin of pixels on each cell not
  104. * considered for the determination of the cell bit. Represents the rate respect to the total
  105. * size of the cell, i.e. perpectiveRemovePixelPerCell (default 0.13)
  106. * - maxErroneousBitsInBorderRate: maximum number of accepted erroneous bits in the border (i.e.
  107. * number of allowed white bits in the border). Represented as a rate respect to the total
  108. * number of bits per marker (default 0.35).
  109. * - minOtsuStdDev: minimun standard deviation in pixels values during the decodification step to
  110. * apply Otsu thresholding (otherwise, all the bits are set to 0 or 1 depending on mean higher
  111. * than 128 or not) (default 5.0)
  112. * - errorCorrectionRate error correction rate respect to the maximun error correction capability
  113. * for each dictionary. (default 0.6).
  114. */
  115. struct CV_EXPORTS_W DetectorParameters {
  116. DetectorParameters();
  117. CV_WRAP static Ptr<DetectorParameters> create();
  118. CV_PROP_RW int adaptiveThreshWinSizeMin;
  119. CV_PROP_RW int adaptiveThreshWinSizeMax;
  120. CV_PROP_RW int adaptiveThreshWinSizeStep;
  121. CV_PROP_RW double adaptiveThreshConstant;
  122. CV_PROP_RW double minMarkerPerimeterRate;
  123. CV_PROP_RW double maxMarkerPerimeterRate;
  124. CV_PROP_RW double polygonalApproxAccuracyRate;
  125. CV_PROP_RW double minCornerDistanceRate;
  126. CV_PROP_RW int minDistanceToBorder;
  127. CV_PROP_RW double minMarkerDistanceRate;
  128. CV_PROP_RW int cornerRefinementMethod;
  129. CV_PROP_RW int cornerRefinementWinSize;
  130. CV_PROP_RW int cornerRefinementMaxIterations;
  131. CV_PROP_RW double cornerRefinementMinAccuracy;
  132. CV_PROP_RW int markerBorderBits;
  133. CV_PROP_RW int perspectiveRemovePixelPerCell;
  134. CV_PROP_RW double perspectiveRemoveIgnoredMarginPerCell;
  135. CV_PROP_RW double maxErroneousBitsInBorderRate;
  136. CV_PROP_RW double minOtsuStdDev;
  137. CV_PROP_RW double errorCorrectionRate;
  138. };
  139. /**
  140. * @brief Basic marker detection
  141. *
  142. * @param image input image
  143. * @param dictionary indicates the type of markers that will be searched
  144. * @param corners vector of detected marker corners. For each marker, its four corners
  145. * are provided, (e.g std::vector<std::vector<cv::Point2f> > ). For N detected markers,
  146. * the dimensions of this array is Nx4. The order of the corners is clockwise.
  147. * @param ids vector of identifiers of the detected markers. The identifier is of type int
  148. * (e.g. std::vector<int>). For N detected markers, the size of ids is also N.
  149. * The identifiers have the same order than the markers in the imgPoints array.
  150. * @param parameters marker detection parameters
  151. * @param rejectedImgPoints contains the imgPoints of those squares whose inner code has not a
  152. * correct codification. Useful for debugging purposes.
  153. * @param cameraMatrix optional input 3x3 floating-point camera matrix
  154. * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$
  155. * @param distCoeff optional vector of distortion coefficients
  156. * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements
  157. *
  158. * Performs marker detection in the input image. Only markers included in the specific dictionary
  159. * are searched. For each detected marker, it returns the 2D position of its corner in the image
  160. * and its corresponding identifier.
  161. * Note that this function does not perform pose estimation.
  162. * @sa estimatePoseSingleMarkers, estimatePoseBoard
  163. *
  164. */
  165. CV_EXPORTS_W void detectMarkers(InputArray image, const Ptr<Dictionary> &dictionary, OutputArrayOfArrays corners,
  166. OutputArray ids, const Ptr<DetectorParameters> &parameters = DetectorParameters::create(),
  167. OutputArrayOfArrays rejectedImgPoints = noArray(), InputArray cameraMatrix= noArray(), InputArray distCoeff= noArray());
  168. /**
  169. * @brief Pose estimation for single markers
  170. *
  171. * @param corners vector of already detected markers corners. For each marker, its four corners
  172. * are provided, (e.g std::vector<std::vector<cv::Point2f> > ). For N detected markers,
  173. * the dimensions of this array should be Nx4. The order of the corners should be clockwise.
  174. * @sa detectMarkers
  175. * @param markerLength the length of the markers' side. The returning translation vectors will
  176. * be in the same unit. Normally, unit is meters.
  177. * @param cameraMatrix input 3x3 floating-point camera matrix
  178. * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$
  179. * @param distCoeffs vector of distortion coefficients
  180. * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements
  181. * @param rvecs array of output rotation vectors (@sa Rodrigues) (e.g. std::vector<cv::Vec3d>).
  182. * Each element in rvecs corresponds to the specific marker in imgPoints.
  183. * @param tvecs array of output translation vectors (e.g. std::vector<cv::Vec3d>).
  184. * Each element in tvecs corresponds to the specific marker in imgPoints.
  185. * @param _objPoints array of object points of all the marker corners
  186. *
  187. * This function receives the detected markers and returns their pose estimation respect to
  188. * the camera individually. So for each marker, one rotation and translation vector is returned.
  189. * The returned transformation is the one that transforms points from each marker coordinate system
  190. * to the camera coordinate system.
  191. * The marker corrdinate system is centered on the middle of the marker, with the Z axis
  192. * perpendicular to the marker plane.
  193. * The coordinates of the four corners of the marker in its own coordinate system are:
  194. * (-markerLength/2, markerLength/2, 0), (markerLength/2, markerLength/2, 0),
  195. * (markerLength/2, -markerLength/2, 0), (-markerLength/2, -markerLength/2, 0)
  196. */
  197. CV_EXPORTS_W void estimatePoseSingleMarkers(InputArrayOfArrays corners, float markerLength,
  198. InputArray cameraMatrix, InputArray distCoeffs,
  199. OutputArray rvecs, OutputArray tvecs, OutputArray _objPoints = noArray());
  200. /**
  201. * @brief Board of markers
  202. *
  203. * A board is a set of markers in the 3D space with a common cordinate system.
  204. * The common form of a board of marker is a planar (2D) board, however any 3D layout can be used.
  205. * A Board object is composed by:
  206. * - The object points of the marker corners, i.e. their coordinates respect to the board system.
  207. * - The dictionary which indicates the type of markers of the board
  208. * - The identifier of all the markers in the board.
  209. */
  210. class CV_EXPORTS_W Board {
  211. public:
  212. /**
  213. * @brief Provide way to create Board by passing nessesary data. Specially needed in Python.
  214. *
  215. * @param objPoints array of object points of all the marker corners in the board
  216. * @param dictionary the dictionary of markers employed for this board
  217. * @param ids vector of the identifiers of the markers in the board
  218. *
  219. */
  220. CV_WRAP static Ptr<Board> create(InputArrayOfArrays objPoints, const Ptr<Dictionary> &dictionary, InputArray ids);
  221. /// array of object points of all the marker corners in the board
  222. /// each marker include its 4 corners in CCW order. For M markers, the size is Mx4.
  223. CV_PROP std::vector< std::vector< Point3f > > objPoints;
  224. /// the dictionary of markers employed for this board
  225. CV_PROP Ptr<Dictionary> dictionary;
  226. /// vector of the identifiers of the markers in the board (same size than objPoints)
  227. /// The identifiers refers to the board dictionary
  228. CV_PROP std::vector< int > ids;
  229. };
  230. /**
  231. * @brief Planar board with grid arrangement of markers
  232. * More common type of board. All markers are placed in the same plane in a grid arrangment.
  233. * The board can be drawn using drawPlanarBoard() function (@sa drawPlanarBoard)
  234. */
  235. class CV_EXPORTS_W GridBoard : public Board {
  236. public:
  237. /**
  238. * @brief Draw a GridBoard
  239. *
  240. * @param outSize size of the output image in pixels.
  241. * @param img output image with the board. The size of this image will be outSize
  242. * and the board will be on the center, keeping the board proportions.
  243. * @param marginSize minimum margins (in pixels) of the board in the output image
  244. * @param borderBits width of the marker borders.
  245. *
  246. * This function return the image of the GridBoard, ready to be printed.
  247. */
  248. CV_WRAP void draw(Size outSize, OutputArray img, int marginSize = 0, int borderBits = 1);
  249. /**
  250. * @brief Create a GridBoard object
  251. *
  252. * @param markersX number of markers in X direction
  253. * @param markersY number of markers in Y direction
  254. * @param markerLength marker side length (normally in meters)
  255. * @param markerSeparation separation between two markers (same unit as markerLength)
  256. * @param dictionary dictionary of markers indicating the type of markers
  257. * @param firstMarker id of first marker in dictionary to use on board.
  258. * @return the output GridBoard object
  259. *
  260. * This functions creates a GridBoard object given the number of markers in each direction and
  261. * the marker size and marker separation.
  262. */
  263. CV_WRAP static Ptr<GridBoard> create(int markersX, int markersY, float markerLength,
  264. float markerSeparation, const Ptr<Dictionary> &dictionary, int firstMarker = 0);
  265. /**
  266. *
  267. */
  268. CV_WRAP Size getGridSize() const { return Size(_markersX, _markersY); }
  269. /**
  270. *
  271. */
  272. CV_WRAP float getMarkerLength() const { return _markerLength; }
  273. /**
  274. *
  275. */
  276. CV_WRAP float getMarkerSeparation() const { return _markerSeparation; }
  277. private:
  278. // number of markers in X and Y directions
  279. int _markersX, _markersY;
  280. // marker side lenght (normally in meters)
  281. float _markerLength;
  282. // separation between markers in the grid
  283. float _markerSeparation;
  284. };
  285. /**
  286. * @brief Pose estimation for a board of markers
  287. *
  288. * @param corners vector of already detected markers corners. For each marker, its four corners
  289. * are provided, (e.g std::vector<std::vector<cv::Point2f> > ). For N detected markers, the
  290. * dimensions of this array should be Nx4. The order of the corners should be clockwise.
  291. * @param ids list of identifiers for each marker in corners
  292. * @param board layout of markers in the board. The layout is composed by the marker identifiers
  293. * and the positions of each marker corner in the board reference system.
  294. * @param cameraMatrix input 3x3 floating-point camera matrix
  295. * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$
  296. * @param distCoeffs vector of distortion coefficients
  297. * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements
  298. * @param rvec Output vector (e.g. cv::Mat) corresponding to the rotation vector of the board
  299. * (see cv::Rodrigues). Used as initial guess if not empty.
  300. * @param tvec Output vector (e.g. cv::Mat) corresponding to the translation vector of the board.
  301. * @param useExtrinsicGuess defines whether initial guess for \b rvec and \b tvec will be used or not.
  302. * Used as initial guess if not empty.
  303. *
  304. * This function receives the detected markers and returns the pose of a marker board composed
  305. * by those markers.
  306. * A Board of marker has a single world coordinate system which is defined by the board layout.
  307. * The returned transformation is the one that transforms points from the board coordinate system
  308. * to the camera coordinate system.
  309. * Input markers that are not included in the board layout are ignored.
  310. * The function returns the number of markers from the input employed for the board pose estimation.
  311. * Note that returning a 0 means the pose has not been estimated.
  312. */
  313. CV_EXPORTS_W int estimatePoseBoard(InputArrayOfArrays corners, InputArray ids, const Ptr<Board> &board,
  314. InputArray cameraMatrix, InputArray distCoeffs, OutputArray rvec,
  315. OutputArray tvec, bool useExtrinsicGuess = false);
  316. /**
  317. * @brief Refind not detected markers based on the already detected and the board layout
  318. *
  319. * @param image input image
  320. * @param board layout of markers in the board.
  321. * @param detectedCorners vector of already detected marker corners.
  322. * @param detectedIds vector of already detected marker identifiers.
  323. * @param rejectedCorners vector of rejected candidates during the marker detection process.
  324. * @param cameraMatrix optional input 3x3 floating-point camera matrix
  325. * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$
  326. * @param distCoeffs optional vector of distortion coefficients
  327. * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements
  328. * @param minRepDistance minimum distance between the corners of the rejected candidate and the
  329. * reprojected marker in order to consider it as a correspondence.
  330. * @param errorCorrectionRate rate of allowed erroneous bits respect to the error correction
  331. * capability of the used dictionary. -1 ignores the error correction step.
  332. * @param checkAllOrders Consider the four posible corner orders in the rejectedCorners array.
  333. * If it set to false, only the provided corner order is considered (default true).
  334. * @param recoveredIdxs Optional array to returns the indexes of the recovered candidates in the
  335. * original rejectedCorners array.
  336. * @param parameters marker detection parameters
  337. *
  338. * This function tries to find markers that were not detected in the basic detecMarkers function.
  339. * First, based on the current detected marker and the board layout, the function interpolates
  340. * the position of the missing markers. Then it tries to find correspondence between the reprojected
  341. * markers and the rejected candidates based on the minRepDistance and errorCorrectionRate
  342. * parameters.
  343. * If camera parameters and distortion coefficients are provided, missing markers are reprojected
  344. * using projectPoint function. If not, missing marker projections are interpolated using global
  345. * homography, and all the marker corners in the board must have the same Z coordinate.
  346. */
  347. CV_EXPORTS_W void refineDetectedMarkers(
  348. InputArray image,const Ptr<Board> &board, InputOutputArrayOfArrays detectedCorners,
  349. InputOutputArray detectedIds, InputOutputArrayOfArrays rejectedCorners,
  350. InputArray cameraMatrix = noArray(), InputArray distCoeffs = noArray(),
  351. float minRepDistance = 10.f, float errorCorrectionRate = 3.f, bool checkAllOrders = true,
  352. OutputArray recoveredIdxs = noArray(), const Ptr<DetectorParameters> &parameters = DetectorParameters::create());
  353. /**
  354. * @brief Draw detected markers in image
  355. *
  356. * @param image input/output image. It must have 1 or 3 channels. The number of channels is not
  357. * altered.
  358. * @param corners positions of marker corners on input image.
  359. * (e.g std::vector<std::vector<cv::Point2f> > ). For N detected markers, the dimensions of
  360. * this array should be Nx4. The order of the corners should be clockwise.
  361. * @param ids vector of identifiers for markers in markersCorners .
  362. * Optional, if not provided, ids are not painted.
  363. * @param borderColor color of marker borders. Rest of colors (text color and first corner color)
  364. * are calculated based on this one to improve visualization.
  365. *
  366. * Given an array of detected marker corners and its corresponding ids, this functions draws
  367. * the markers in the image. The marker borders are painted and the markers identifiers if provided.
  368. * Useful for debugging purposes.
  369. */
  370. CV_EXPORTS_W void drawDetectedMarkers(InputOutputArray image, InputArrayOfArrays corners,
  371. InputArray ids = noArray(),
  372. Scalar borderColor = Scalar(0, 255, 0));
  373. /**
  374. * @brief Draw coordinate system axis from pose estimation
  375. *
  376. * @param image input/output image. It must have 1 or 3 channels. The number of channels is not
  377. * altered.
  378. * @param cameraMatrix input 3x3 floating-point camera matrix
  379. * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$
  380. * @param distCoeffs vector of distortion coefficients
  381. * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements
  382. * @param rvec rotation vector of the coordinate system that will be drawn. (@sa Rodrigues).
  383. * @param tvec translation vector of the coordinate system that will be drawn.
  384. * @param length length of the painted axis in the same unit than tvec (usually in meters)
  385. *
  386. * Given the pose estimation of a marker or board, this function draws the axis of the world
  387. * coordinate system, i.e. the system centered on the marker/board. Useful for debugging purposes.
  388. */
  389. CV_EXPORTS_W void drawAxis(InputOutputArray image, InputArray cameraMatrix, InputArray distCoeffs,
  390. InputArray rvec, InputArray tvec, float length);
  391. /**
  392. * @brief Draw a canonical marker image
  393. *
  394. * @param dictionary dictionary of markers indicating the type of markers
  395. * @param id identifier of the marker that will be returned. It has to be a valid id
  396. * in the specified dictionary.
  397. * @param sidePixels size of the image in pixels
  398. * @param img output image with the marker
  399. * @param borderBits width of the marker border.
  400. *
  401. * This function returns a marker image in its canonical form (i.e. ready to be printed)
  402. */
  403. CV_EXPORTS_W void drawMarker(const Ptr<Dictionary> &dictionary, int id, int sidePixels, OutputArray img,
  404. int borderBits = 1);
  405. /**
  406. * @brief Draw a planar board
  407. * @sa _drawPlanarBoardImpl
  408. *
  409. * @param board layout of the board that will be drawn. The board should be planar,
  410. * z coordinate is ignored
  411. * @param outSize size of the output image in pixels.
  412. * @param img output image with the board. The size of this image will be outSize
  413. * and the board will be on the center, keeping the board proportions.
  414. * @param marginSize minimum margins (in pixels) of the board in the output image
  415. * @param borderBits width of the marker borders.
  416. *
  417. * This function return the image of a planar board, ready to be printed. It assumes
  418. * the Board layout specified is planar by ignoring the z coordinates of the object points.
  419. */
  420. CV_EXPORTS_W void drawPlanarBoard(const Ptr<Board> &board, Size outSize, OutputArray img,
  421. int marginSize = 0, int borderBits = 1);
  422. /**
  423. * @brief Implementation of drawPlanarBoard that accepts a raw Board pointer.
  424. */
  425. void _drawPlanarBoardImpl(Board *board, Size outSize, OutputArray img,
  426. int marginSize = 0, int borderBits = 1);
  427. /**
  428. * @brief Calibrate a camera using aruco markers
  429. *
  430. * @param corners vector of detected marker corners in all frames.
  431. * The corners should have the same format returned by detectMarkers (see #detectMarkers).
  432. * @param ids list of identifiers for each marker in corners
  433. * @param counter number of markers in each frame so that corners and ids can be split
  434. * @param board Marker Board layout
  435. * @param imageSize Size of the image used only to initialize the intrinsic camera matrix.
  436. * @param cameraMatrix Output 3x3 floating-point camera matrix
  437. * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . If CV\_CALIB\_USE\_INTRINSIC\_GUESS
  438. * and/or CV_CALIB_FIX_ASPECT_RATIO are specified, some or all of fx, fy, cx, cy must be
  439. * initialized before calling the function.
  440. * @param distCoeffs Output vector of distortion coefficients
  441. * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements
  442. * @param rvecs Output vector of rotation vectors (see Rodrigues ) estimated for each board view
  443. * (e.g. std::vector<cv::Mat>>). That is, each k-th rotation vector together with the corresponding
  444. * k-th translation vector (see the next output parameter description) brings the board pattern
  445. * from the model coordinate space (in which object points are specified) to the world coordinate
  446. * space, that is, a real position of the board pattern in the k-th pattern view (k=0.. *M* -1).
  447. * @param tvecs Output vector of translation vectors estimated for each pattern view.
  448. * @param stdDeviationsIntrinsics Output vector of standard deviations estimated for intrinsic parameters.
  449. * Order of deviations values:
  450. * \f$(f_x, f_y, c_x, c_y, k_1, k_2, p_1, p_2, k_3, k_4, k_5, k_6 , s_1, s_2, s_3,
  451. * s_4, \tau_x, \tau_y)\f$ If one of parameters is not estimated, it's deviation is equals to zero.
  452. * @param stdDeviationsExtrinsics Output vector of standard deviations estimated for extrinsic parameters.
  453. * Order of deviations values: \f$(R_1, T_1, \dotsc , R_M, T_M)\f$ where M is number of pattern views,
  454. * \f$R_i, T_i\f$ are concatenated 1x3 vectors.
  455. * @param perViewErrors Output vector of average re-projection errors estimated for each pattern view.
  456. * @param flags flags Different flags for the calibration process (see #calibrateCamera for details).
  457. * @param criteria Termination criteria for the iterative optimization algorithm.
  458. *
  459. * This function calibrates a camera using an Aruco Board. The function receives a list of
  460. * detected markers from several views of the Board. The process is similar to the chessboard
  461. * calibration in calibrateCamera(). The function returns the final re-projection error.
  462. */
  463. CV_EXPORTS_AS(calibrateCameraArucoExtended) double calibrateCameraAruco(
  464. InputArrayOfArrays corners, InputArray ids, InputArray counter, const Ptr<Board> &board,
  465. Size imageSize, InputOutputArray cameraMatrix, InputOutputArray distCoeffs,
  466. OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs,
  467. OutputArray stdDeviationsIntrinsics, OutputArray stdDeviationsExtrinsics,
  468. OutputArray perViewErrors, int flags = 0,
  469. TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON));
  470. /** @brief It's the same function as #calibrateCameraAruco but without calibration error estimation.
  471. */
  472. CV_EXPORTS_W double calibrateCameraAruco(
  473. InputArrayOfArrays corners, InputArray ids, InputArray counter, const Ptr<Board> &board,
  474. Size imageSize, InputOutputArray cameraMatrix, InputOutputArray distCoeffs,
  475. OutputArrayOfArrays rvecs = noArray(), OutputArrayOfArrays tvecs = noArray(), int flags = 0,
  476. TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON));
  477. /**
  478. * @brief Given a board configuration and a set of detected markers, returns the corresponding
  479. * image points and object points to call solvePnP
  480. *
  481. * @param board Marker board layout.
  482. * @param detectedCorners List of detected marker corners of the board.
  483. * @param detectedIds List of identifiers for each marker.
  484. * @param objPoints Vector of vectors of board marker points in the board coordinate space.
  485. * @param imgPoints Vector of vectors of the projections of board marker corner points.
  486. */
  487. CV_EXPORTS_W void getBoardObjectAndImagePoints(const Ptr<Board> &board, InputArrayOfArrays detectedCorners,
  488. InputArray detectedIds, OutputArray objPoints, OutputArray imgPoints);
  489. //! @}
  490. }
  491. }
  492. #endif