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 #include "markerlabeler.h"
40 #include <iostream>
41 
42 namespace aruco {
43 namespace hrm{
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:
213 
214 
220 
221  public:
225  void loadDictionary(Dictionary *D);
226 
230  bool findId(unsigned int id, unsigned int &orgPos);
231 
232  private:
233  std::vector< std::pair< unsigned int, unsigned int > > _orderD; // dictionary sorted by id,
234  // first element is the id,
235  // second element is the position in original D
236  std::vector< std::pair< int, int > > _binaryTree; // binary tree itself (as a vector), each element is a node of the tree
237  // first element indicate the position in _binaryTree of the lower child
238  // second element is the position in _binaryTree of the higher child
239  // -1 value indicates no lower or higher child
240  unsigned int _root; // position in _binaryTree of the root node of the tree
241  };
242 
246  // correctionDistance [0,1] 0: totalmente restrictivo, 1 mas flexible
247  static bool loadDictionary(Dictionary D, float correctionDistance = 1);
248  static bool loadDictionary(std::string filename, float correctionDistance = 1);
249  static Dictionary &getDictionary() { return _D; }
250 
251 
257  int detect(const cv::Mat &in, int &nRotations);
258 
259  int getBestInputSize(){return (_D[0].n() + 2) * 8;}
260 
261  private:
262  static Dictionary _D; // loaded dictionary
264  // marker dimension, marker dimension with borders, maximunCorrectionDistance
265  static unsigned int _n;
266  static unsigned int _ncellsBorder;
267  static unsigned int _correctionDistance;
268  static int _swidth; // cell size in the canonical image
269 
270 
274  static bool checkBorders(cv::Mat grey);
275 
279  static MarkerCode getMarkerCode(const cv::Mat &grey);
280 };
281 
282 }
283 
284 }
285 #endif // HIGHLYRELIABLEMARKERS_H
unsigned int getId(unsigned int rot=0) const
const std::vector< bool > & getRotation(unsigned int rot) const
#define ARUCO_EXPORTS
Definition: exports.h:42
filename
unsigned int distance(const MarkerCode &m) const
XmlRpcServer s
TFSIMD_FORCE_INLINE tfScalar distance(const Vector3 &v) const
Base class of labelers. A labelers receive a square of the image and determines if it has a valid mar...
Definition: markerlabeler.h:39
unsigned int distance(const MarkerCode &m)
unsigned int size() const
unsigned int n() const
static BalancedBinaryTree _binaryTree
int getBestInputSize()
getBestInputSize if desired, you can set the desired input size to the detect function ...
static std::string toStr(T num)
unsigned int selfDistance() const
std::vector< std::pair< unsigned int, unsigned int > > _orderD
bitset< 64 > fromString(std::string str)
Definition: mset2dict.cpp:12


tuw_aruco
Author(s): Lukas Pfeifhofer
autogenerated on Mon Jun 10 2019 15:40:50