highlyreliablemarkers.h
Go to the documentation of this file.
1 /*****************************
2 Copyright 2011 Rafael Muñoz Salinas. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without modification, are
5 permitted provided that the following conditions are met:
6 
7  1. Redistributions of source code must retain the above copyright notice, this list of
8  conditions and the following disclaimer.
9 
10  2. Redistributions in binary form must reproduce the above copyright notice, this list
11  of conditions and the following disclaimer in the documentation and/or other materials
12  provided with the distribution.
13 
14 THIS SOFTWARE IS PROVIDED BY Rafael Muñoz Salinas ''AS IS'' AND ANY EXPRESS OR IMPLIED
15 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Rafael Muñoz Salinas OR
17 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 
24 The views and conclusions contained in the software and documentation are those of the
25 authors and should not be interpreted as representing official policies, either expressed
26 or implied, of Rafael Muñoz Salinas.
27 ********************************/
28 
29 #ifndef HIGHLYRELIABLEMARKERS_H
30 #define HIGHLYRELIABLEMARKERS_H
31 
32 
33 #include <vector>
34 #include <math.h>
35 #include <string>
36 #include <opencv2/core/core.hpp>
37 #include <opencv2/imgproc/imgproc.hpp>
38 #include "exports.h"
39 
40 #include <iostream>
41 
42 namespace aruco {
43 
50  public:
54  MarkerCode(unsigned int n = 0);
55 
59  MarkerCode(const MarkerCode &MC);
60 
64  unsigned int getId(unsigned int rot = 0) const { return _ids[rot]; };
65 
70  bool get(unsigned int pos, unsigned int rot = 0) const { return _bits[rot][pos]; }
71 
75  const std::vector< bool > &getRotation(unsigned int rot) const { return _bits[rot]; };
76 
85  void set(unsigned int pos, bool val, bool updateIds=true);
86 
90  unsigned int size() const { return n() * n(); };
91 
95  unsigned int n() const { return _n; };
96 
101  unsigned int selfDistance(unsigned int &minRot) const;
102 
107  unsigned int selfDistance() const {
108  unsigned int minRot;
109  return selfDistance(minRot);
110  };
111 
116  unsigned int distance(const MarkerCode &m, unsigned int &minRot) const;
117 
122  unsigned int distance(const MarkerCode &m) const {
123  unsigned int minRot;
124  return distance(m, minRot);
125  };
126 
130  void fromString(std::string s);
131 
135  std::string toString() const;
136 
137 
142  cv::Mat getImg(unsigned int pixSize) const;
143 
144  private:
145  unsigned int _ids[4]; // ids in the four rotations
146  std::vector< bool > _bits[4]; // bit strings in the four rotations
147  unsigned int _n; // marker dimension
148 
152  unsigned int hammingDistance(const std::vector< bool > &m1, const std::vector< bool > &m2) const;
153 };
154 
155 
161 class ARUCO_EXPORTS Dictionary : public std::vector< MarkerCode > {
162  public:
166  bool fromFile(std::string filename);
167 
171  bool toFile(std::string filename);
172 
178  unsigned int distance(const MarkerCode &m, unsigned int &minMarker, unsigned int &minRot);
179 
184  unsigned int distance(const MarkerCode &m) {
185  unsigned int minMarker, minRot;
186  return distance(m, minMarker, minRot);
187  }
188 
192  unsigned int minimunDistance();
193 
194  int tau0;
195 
196  private:
197  // convert to string
198  template < class T > static std::string toStr(T num) {
199  std::stringstream ss;
200  ss << num;
201  return ss.str();
202  }
203 };
204 
205 
212  public:
218 
219  public:
223  void loadDictionary(Dictionary *D);
224 
228  bool findId(unsigned int id, unsigned int &orgPos);
229 
230  private:
231  std::vector< std::pair< unsigned int, unsigned int > > _orderD; // dictionary sorted by id,
232  // first element is the id,
233  // second element is the position in original D
234  std::vector< std::pair< int, int > > _binaryTree; // binary tree itself (as a vector), each element is a node of the tree
235  // first element indicate the position in _binaryTree of the lower child
236  // second element is the position in _binaryTree of the higher child
237  // -1 value indicates no lower or higher child
238  unsigned int _root; // position in _binaryTree of the root node of the tree
239  };
240 
244  // correctionDistance [0,1] 0: totalmente restrictivo, 1 mas flexible
245  static bool loadDictionary(Dictionary D, float correctionDistance = 1);
246  static bool loadDictionary(std::string filename, float correctionDistance = 1);
247  static Dictionary &getDictionary() { return _D; }
248 
249 
255  static int detect(const cv::Mat &in, int &nRotations);
256 
257 
258  private:
259  static Dictionary _D; // loaded dictionary
261  // marker dimension, marker dimension with borders, maximunCorrectionDistance
262  static unsigned int _n;
263  static unsigned int _ncellsBorder;
264  static unsigned int _correctionDistance;
265  static int _swidth; // cell size in the canonical image
266 
267 
271  static bool checkBorders(cv::Mat grey);
272 
276  static MarkerCode getMarkerCode(const cv::Mat &grey);
277 };
278 
279 }
280 
281 
282 #endif // HIGHLYRELIABLEMARKERS_H
unsigned int size() const
#define ARUCO_EXPORTS
Definition: exports.h:42
unsigned int selfDistance() const
static std::string toStr(T num)
XmlRpcServer s
unsigned int distance(const MarkerCode &m)
const std::vector< bool > & getRotation(unsigned int rot) const
static Dictionary & getDictionary()
unsigned int getId(unsigned int rot=0) const
unsigned int n() const
static unsigned int _correctionDistance
static BalancedBinaryTree _binaryTree
std::vector< std::pair< unsigned int, unsigned int > > _orderD
std::vector< std::pair< int, int > > _binaryTree
unsigned int distance(const MarkerCode &m) const


asr_aruco_marker_recognition
Author(s): Allgeyer Tobias, Meißner Pascal, Qattan Mohamad
autogenerated on Mon Jun 10 2019 12:40:21