|
| 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 | +
|
| 6 | + License Agreement |
| 7 | + For Open Source Computer Vision Library |
| 8 | + (3-clause BSD License) |
| 9 | +
|
| 10 | +Copyright (C) 2013, OpenCV Foundation, all rights reserved. |
| 11 | +Third party copyrights are property of their respective owners. |
| 12 | +
|
| 13 | +Redistribution and use in source and binary forms, with or without modification, |
| 14 | +are permitted provided that the following conditions are met: |
| 15 | +
|
| 16 | + * Redistributions of source code must retain the above copyright notice, |
| 17 | + this list of conditions and the following disclaimer. |
| 18 | +
|
| 19 | + * Redistributions in binary form must reproduce the above copyright notice, |
| 20 | + this list of conditions and the following disclaimer in the documentation |
| 21 | + and/or other materials provided with the distribution. |
| 22 | +
|
| 23 | + * Neither the names of the copyright holders nor the names of the contributors |
| 24 | + may be used to endorse or promote products derived from this software |
| 25 | + without specific prior written permission. |
| 26 | +
|
| 27 | +This software is provided by the copyright holders and contributors "as is" and |
| 28 | +any express or implied warranties, including, but not limited to, the implied |
| 29 | +warranties of merchantability and fitness for a particular purpose are |
| 30 | +disclaimed. In no event shall copyright holders or contributors be liable for |
| 31 | +any direct, indirect, incidental, special, exemplary, or consequential damages |
| 32 | +(including, but not limited to, procurement of substitute goods or services; |
| 33 | +loss of use, data, or profits; or business interruption) however caused |
| 34 | +and on any theory of liability, whether in contract, strict liability, |
| 35 | +or tort (including negligence or otherwise) arising in any way out of |
| 36 | +the use of this software, even if advised of the possibility of such damage. |
| 37 | +*/ |
| 38 | + |
| 39 | +#ifndef __OPENCV_DICTIONARY_HPP__ |
| 40 | +#define __OPENCV_DICTIONARY_HPP__ |
| 41 | + |
| 42 | +#include <opencv2/core.hpp> |
| 43 | + |
| 44 | +namespace cv { |
| 45 | +namespace aruco { |
| 46 | + |
| 47 | +//! @addtogroup aruco |
| 48 | +//! @{ |
| 49 | + |
| 50 | + |
| 51 | +/** |
| 52 | + * @brief Dictionary/Set of markers. It contains the inner codification |
| 53 | + * |
| 54 | + * bytesList contains the marker codewords where |
| 55 | + * - bytesList.rows is the dictionary size |
| 56 | + * - each marker is encoded using `nbytes = ceil(markerSize*markerSize/8.)` |
| 57 | + * - each row contains all 4 rotations of the marker, so its length is `4*nbytes` |
| 58 | + * |
| 59 | + * `bytesList.ptr(i)[k*nbytes + j]` is then the j-th byte of i-th marker, in its k-th rotation. |
| 60 | + */ |
| 61 | +class CV_EXPORTS_W Dictionary { |
| 62 | + |
| 63 | + public: |
| 64 | + CV_PROP_RW Mat bytesList; // marker code information |
| 65 | + CV_PROP_RW int markerSize; // number of bits per dimension |
| 66 | + CV_PROP_RW int maxCorrectionBits; // maximum number of bits that can be corrected |
| 67 | + |
| 68 | + |
| 69 | + /** |
| 70 | + */ |
| 71 | + Dictionary(const Mat &_bytesList = Mat(), int _markerSize = 0, int _maxcorr = 0); |
| 72 | + |
| 73 | + |
| 74 | + /** |
| 75 | + Dictionary(const Dictionary &_dictionary); |
| 76 | + */ |
| 77 | + |
| 78 | + |
| 79 | + /** |
| 80 | + */ |
| 81 | + Dictionary(const Ptr<Dictionary> &_dictionary); |
| 82 | + |
| 83 | + |
| 84 | + /** |
| 85 | + * @see generateCustomDictionary |
| 86 | + */ |
| 87 | + CV_WRAP_AS(create) static Ptr<Dictionary> create(int nMarkers, int markerSize, int randomSeed=0); |
| 88 | + |
| 89 | + |
| 90 | + /** |
| 91 | + * @see generateCustomDictionary |
| 92 | + */ |
| 93 | + CV_WRAP_AS(create_from) static Ptr<Dictionary> create(int nMarkers, int markerSize, |
| 94 | + const Ptr<Dictionary> &baseDictionary, int randomSeed=0); |
| 95 | + |
| 96 | + /** |
| 97 | + * @see getPredefinedDictionary |
| 98 | + */ |
| 99 | + CV_WRAP static Ptr<Dictionary> get(int dict); |
| 100 | + |
| 101 | + /** |
| 102 | + * @brief Given a matrix of bits. Returns whether if marker is identified or not. |
| 103 | + * It returns by reference the correct id (if any) and the correct rotation |
| 104 | + */ |
| 105 | + bool identify(const Mat &onlyBits, int &idx, int &rotation, double maxCorrectionRate) const; |
| 106 | + |
| 107 | + /** |
| 108 | + * @brief Returns the distance of the input bits to the specific id. If allRotations is true, |
| 109 | + * the four posible bits rotation are considered |
| 110 | + */ |
| 111 | + int getDistanceToId(InputArray bits, int id, bool allRotations = true) const; |
| 112 | + |
| 113 | + |
| 114 | + /** |
| 115 | + * @brief Draw a canonical marker image |
| 116 | + */ |
| 117 | + CV_WRAP void drawMarker(int id, int sidePixels, OutputArray _img, int borderBits = 1) const; |
| 118 | + |
| 119 | + |
| 120 | + /** |
| 121 | + * @brief Transform matrix of bits to list of bytes in the 4 rotations |
| 122 | + */ |
| 123 | + CV_WRAP static Mat getByteListFromBits(const Mat &bits); |
| 124 | + |
| 125 | + |
| 126 | + /** |
| 127 | + * @brief Transform list of bytes to matrix of bits |
| 128 | + */ |
| 129 | + CV_WRAP static Mat getBitsFromByteList(const Mat &byteList, int markerSize); |
| 130 | +}; |
| 131 | + |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | +/** |
| 136 | + * @brief Predefined markers dictionaries/sets |
| 137 | + * Each dictionary indicates the number of bits and the number of markers contained |
| 138 | + * - DICT_ARUCO_ORIGINAL: standard ArUco Library Markers. 1024 markers, 5x5 bits, 0 minimum |
| 139 | + distance |
| 140 | + */ |
| 141 | +enum PREDEFINED_DICTIONARY_NAME { |
| 142 | + DICT_4X4_50 = 0, |
| 143 | + DICT_4X4_100, |
| 144 | + DICT_4X4_250, |
| 145 | + DICT_4X4_1000, |
| 146 | + DICT_5X5_50, |
| 147 | + DICT_5X5_100, |
| 148 | + DICT_5X5_250, |
| 149 | + DICT_5X5_1000, |
| 150 | + DICT_6X6_50, |
| 151 | + DICT_6X6_100, |
| 152 | + DICT_6X6_250, |
| 153 | + DICT_6X6_1000, |
| 154 | + DICT_7X7_50, |
| 155 | + DICT_7X7_100, |
| 156 | + DICT_7X7_250, |
| 157 | + DICT_7X7_1000, |
| 158 | + DICT_ARUCO_ORIGINAL, |
| 159 | + DICT_APRILTAG_16h5, ///< 4x4 bits, minimum hamming distance between any two codes = 5, 30 codes |
| 160 | + DICT_APRILTAG_25h9, ///< 5x5 bits, minimum hamming distance between any two codes = 9, 35 codes |
| 161 | + DICT_APRILTAG_36h10, ///< 6x6 bits, minimum hamming distance between any two codes = 10, 2320 codes |
| 162 | + DICT_APRILTAG_36h11 ///< 6x6 bits, minimum hamming distance between any two codes = 11, 587 codes |
| 163 | +}; |
| 164 | + |
| 165 | + |
| 166 | +/** |
| 167 | + * @brief Returns one of the predefined dictionaries defined in PREDEFINED_DICTIONARY_NAME |
| 168 | + */ |
| 169 | +CV_EXPORTS Ptr<Dictionary> getPredefinedDictionary(PREDEFINED_DICTIONARY_NAME name); |
| 170 | + |
| 171 | + |
| 172 | +/** |
| 173 | + * @brief Returns one of the predefined dictionaries referenced by DICT_*. |
| 174 | + */ |
| 175 | +CV_EXPORTS_W Ptr<Dictionary> getPredefinedDictionary(int dict); |
| 176 | + |
| 177 | + |
| 178 | +/** |
| 179 | + * @see generateCustomDictionary |
| 180 | + */ |
| 181 | +CV_EXPORTS_AS(custom_dictionary) Ptr<Dictionary> generateCustomDictionary( |
| 182 | + int nMarkers, |
| 183 | + int markerSize, |
| 184 | + int randomSeed=0); |
| 185 | + |
| 186 | + |
| 187 | +/** |
| 188 | + * @brief Generates a new customizable marker dictionary |
| 189 | + * |
| 190 | + * @param nMarkers number of markers in the dictionary |
| 191 | + * @param markerSize number of bits per dimension of each markers |
| 192 | + * @param baseDictionary Include the markers in this dictionary at the beginning (optional) |
| 193 | + * @param randomSeed a user supplied seed for theRNG() |
| 194 | + * |
| 195 | + * This function creates a new dictionary composed by nMarkers markers and each markers composed |
| 196 | + * by markerSize x markerSize bits. If baseDictionary is provided, its markers are directly |
| 197 | + * included and the rest are generated based on them. If the size of baseDictionary is higher |
| 198 | + * than nMarkers, only the first nMarkers in baseDictionary are taken and no new marker is added. |
| 199 | + */ |
| 200 | +CV_EXPORTS_AS(custom_dictionary_from) Ptr<Dictionary> generateCustomDictionary( |
| 201 | + int nMarkers, |
| 202 | + int markerSize, |
| 203 | + const Ptr<Dictionary> &baseDictionary, |
| 204 | + int randomSeed=0); |
| 205 | + |
| 206 | + |
| 207 | + |
| 208 | +//! @} |
| 209 | +} |
| 210 | +} |
| 211 | + |
| 212 | +#endif |
0 commit comments