charuco.hpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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_CHARUCO_HPP
  5. #define OPENCV_CHARUCO_HPP
  6. #include <opencv2/core.hpp>
  7. #include <vector>
  8. #include <opencv2/aruco.hpp>
  9. #include <opencv2/objdetect/charuco_detector.hpp>
  10. #include <opencv2/aruco/aruco_calib.hpp>
  11. namespace cv {
  12. namespace aruco {
  13. //! @addtogroup aruco
  14. //! @{
  15. /**
  16. * @brief Interpolate position of ChArUco board corners
  17. * @param markerCorners vector of already detected markers corners. For each marker, its four
  18. * corners are provided, (e.g std::vector<std::vector<cv::Point2f> > ). For N detected markers, the
  19. * dimensions of this array should be Nx4. The order of the corners should be clockwise.
  20. * @param markerIds list of identifiers for each marker in corners
  21. * @param image input image necesary for corner refinement. Note that markers are not detected and
  22. * should be sent in corners and ids parameters.
  23. * @param board layout of ChArUco board.
  24. * @param charucoCorners interpolated chessboard corners
  25. * @param charucoIds interpolated chessboard corners identifiers
  26. * @param cameraMatrix optional 3x3 floating-point camera matrix
  27. * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$
  28. * @param distCoeffs optional vector of distortion coefficients
  29. * \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
  30. * @param minMarkers number of adjacent markers that must be detected to return a charuco corner
  31. *
  32. * This function receives the detected markers and returns the 2D position of the chessboard corners
  33. * from a ChArUco board using the detected Aruco markers. If camera parameters are provided,
  34. * the process is based in an approximated pose estimation, else it is based on local homography.
  35. * Only visible corners are returned. For each corner, its corresponding identifier is
  36. * also returned in charucoIds.
  37. * The function returns the number of interpolated corners.
  38. *
  39. * @deprecated Use CharucoDetector::detectBoard
  40. */
  41. CV_EXPORTS_W int interpolateCornersCharuco(InputArrayOfArrays markerCorners, InputArray markerIds,
  42. InputArray image, const Ptr<CharucoBoard> &board,
  43. OutputArray charucoCorners, OutputArray charucoIds,
  44. InputArray cameraMatrix = noArray(),
  45. InputArray distCoeffs = noArray(), int minMarkers = 2);
  46. /**
  47. * @brief Detect ChArUco Diamond markers
  48. *
  49. * @param image input image necessary for corner subpixel.
  50. * @param markerCorners list of detected marker corners from detectMarkers function.
  51. * @param markerIds list of marker ids in markerCorners.
  52. * @param squareMarkerLengthRate rate between square and marker length:
  53. * squareMarkerLengthRate = squareLength/markerLength. The real units are not necessary.
  54. * @param diamondCorners output list of detected diamond corners (4 corners per diamond). The order
  55. * is the same than in marker corners: top left, top right, bottom right and bottom left. Similar
  56. * format than the corners returned by detectMarkers (e.g std::vector<std::vector<cv::Point2f> > ).
  57. * @param diamondIds ids of the diamonds in diamondCorners. The id of each diamond is in fact of
  58. * type Vec4i, so each diamond has 4 ids, which are the ids of the aruco markers composing the
  59. * diamond.
  60. * @param cameraMatrix Optional camera calibration matrix.
  61. * @param distCoeffs Optional camera distortion coefficients.
  62. * @param dictionary dictionary of markers indicating the type of markers.
  63. *
  64. * This function detects Diamond markers from the previous detected ArUco markers. The diamonds
  65. * are returned in the diamondCorners and diamondIds parameters. If camera calibration parameters
  66. * are provided, the diamond search is based on reprojection. If not, diamond search is based on
  67. * homography. Homography is faster than reprojection, but less accurate.
  68. *
  69. * @deprecated Use CharucoDetector::detectDiamonds
  70. */
  71. CV_EXPORTS_W void detectCharucoDiamond(InputArray image, InputArrayOfArrays markerCorners,
  72. InputArray markerIds, float squareMarkerLengthRate,
  73. OutputArrayOfArrays diamondCorners, OutputArray diamondIds,
  74. InputArray cameraMatrix = noArray(),
  75. InputArray distCoeffs = noArray(),
  76. Ptr<Dictionary> dictionary = makePtr<Dictionary>
  77. (getPredefinedDictionary(PredefinedDictionaryType::DICT_4X4_50)));
  78. /**
  79. * @brief Draw a ChArUco Diamond marker
  80. *
  81. * @param dictionary dictionary of markers indicating the type of markers.
  82. * @param ids list of 4 ids for each ArUco marker in the ChArUco marker.
  83. * @param squareLength size of the chessboard squares in pixels.
  84. * @param markerLength size of the markers in pixels.
  85. * @param img output image with the marker. The size of this image will be
  86. * 3*squareLength + 2*marginSize,.
  87. * @param marginSize minimum margins (in pixels) of the marker in the output image
  88. * @param borderBits width of the marker borders.
  89. *
  90. * This function return the image of a ChArUco marker, ready to be printed.
  91. */
  92. CV_EXPORTS_W void drawCharucoDiamond(const Ptr<Dictionary> &dictionary, Vec4i ids, int squareLength,
  93. int markerLength, OutputArray img, int marginSize = 0,
  94. int borderBits = 1);
  95. //! @}
  96. }
  97. }
  98. #endif