fractalmarkerset.cpp
Go to the documentation of this file.
2 #include <iostream>
3 #include <fstream>
4 
5 namespace aruco
6 {
7 
9 {
11  return loadPredefined(info);
12  else
13  return readFromFile(info);
14 }
15 
17 {
18  return loadPredefined(getTypeFromString(type));
19 }
20 
22 {
23  FractalMarkerSet fms;
24 
25  switch (type)
26  {
27  case FRACTAL_2L_6:
28  {
29  unsigned char _conf_2L_6[] = {
30  0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
31  0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xbf, 0x00, 0x00,
32  0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x80,
33  0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x80, 0xbf,
34  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xbf, 0x00, 0x00, 0x80, 0xbf, 0x00,
35  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,
36  0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01,
37  0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00,
38  0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
39  0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
40  0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,
41  0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
42  0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01,
43  0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00,
44  0x00, 0x00, 0xab, 0xaa, 0xaa, 0xbe, 0xab, 0xaa, 0xaa, 0x3e, 0x00, 0x00, 0x00,
45  0x00, 0xab, 0xaa, 0xaa, 0x3e, 0xab, 0xaa, 0xaa, 0x3e, 0x00, 0x00, 0x00, 0x00,
46  0xab, 0xaa, 0xaa, 0x3e, 0xab, 0xaa, 0xaa, 0xbe, 0x00, 0x00, 0x00, 0x00, 0xab,
47  0xaa, 0xaa, 0xbe, 0xab, 0xaa, 0xaa, 0xbe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
48  0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01,
49  0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
50  0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00
51  };
52  unsigned int _conf_2L_6_len = 272;
53 
54  std::stringstream stream;
55  stream.write((char *)_conf_2L_6, sizeof(unsigned char) * _conf_2L_6_len);
56  _fromStream(fms, stream);
57  }
58  break;
59  case FRACTAL_3L_6:
60  {
61  unsigned char _conf_3L_6[] = {
62  0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
63  0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xbf, 0x00, 0x00,
64  0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x80,
65  0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x80, 0xbf,
66  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xbf, 0x00, 0x00, 0x80, 0xbf, 0x00,
67  0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00,
68  0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00,
69  0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,
70  0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
71  0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01,
72  0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01,
73  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
74  0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,
75  0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,
76  0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01,
77  0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
78  0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
79  0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0xb7, 0x6d, 0xdb, 0xbe, 0xb7, 0x6d,
80  0xdb, 0x3e, 0x00, 0x00, 0x00, 0x00, 0xb7, 0x6d, 0xdb, 0x3e, 0xb7, 0x6d, 0xdb,
81  0x3e, 0x00, 0x00, 0x00, 0x00, 0xb7, 0x6d, 0xdb, 0x3e, 0xb7, 0x6d, 0xdb, 0xbe,
82  0x00, 0x00, 0x00, 0x00, 0xb7, 0x6d, 0xdb, 0xbe, 0xb7, 0x6d, 0xdb, 0xbe, 0x00,
83  0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00,
84  0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
85  0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
86  0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
87  0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00,
88  0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
89  0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01,
90  0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01,
91  0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00,
92  0x00, 0x00, 0x25, 0x49, 0x12, 0xbe, 0x25, 0x49, 0x12, 0x3e, 0x00, 0x00, 0x00,
93  0x00, 0x25, 0x49, 0x12, 0x3e, 0x25, 0x49, 0x12, 0x3e, 0x00, 0x00, 0x00, 0x00,
94  0x25, 0x49, 0x12, 0x3e, 0x25, 0x49, 0x12, 0xbe, 0x00, 0x00, 0x00, 0x00, 0x25,
95  0x49, 0x12, 0xbe, 0x25, 0x49, 0x12, 0xbe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
96  0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01,
97  0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
98  0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
99  };
100  unsigned int _conf_3L_6_len = 480;
101 
102  std::stringstream stream;
103  stream.write((char *)_conf_3L_6, sizeof(unsigned char) * _conf_3L_6_len);
104  _fromStream(fms, stream);
105  }
106  break;
107  case FRACTAL_4L_6:
108  {
109  unsigned char _conf_4L_6[] = {
110  0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
111  0x00, 0x00, 0x00, 0xa9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xbf, 0x00, 0x00,
112  0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x80,
113  0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x80, 0xbf,
114  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xbf, 0x00, 0x00, 0x80, 0xbf, 0x00,
115  0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00,
116  0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
117  0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
118  0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
119  0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
120  0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
121  0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
122  0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
123  0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
124  0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
125  0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
126  0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
127  0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01,
128  0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00,
129  0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0xef, 0xee, 0xee, 0xbe, 0xef, 0xee, 0xee,
130  0x3e, 0x00, 0x00, 0x00, 0x00, 0xef, 0xee, 0xee, 0x3e, 0xef, 0xee, 0xee, 0x3e,
131  0x00, 0x00, 0x00, 0x00, 0xef, 0xee, 0xee, 0x3e, 0xef, 0xee, 0xee, 0xbe, 0x00,
132  0x00, 0x00, 0x00, 0xef, 0xee, 0xee, 0xbe, 0xef, 0xee, 0xee, 0xbe, 0x00, 0x00,
133  0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
134  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01,
135  0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01,
136  0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00,
137  0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
138  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00,
139  0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,
140  0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
141  0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
142  0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01,
143  0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
144  0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00,
145  0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0xcd, 0xcc, 0x4c, 0xbe, 0xcd, 0xcc, 0x4c,
146  0x3e, 0x00, 0x00, 0x00, 0x00, 0xcd, 0xcc, 0x4c, 0x3e, 0xcd, 0xcc, 0x4c, 0x3e,
147  0x00, 0x00, 0x00, 0x00, 0xcd, 0xcc, 0x4c, 0x3e, 0xcd, 0xcc, 0x4c, 0xbe, 0x00,
148  0x00, 0x00, 0x00, 0xcd, 0xcc, 0x4c, 0xbe, 0xcd, 0xcc, 0x4c, 0xbe, 0x00, 0x00,
149  0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01,
150  0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01,
151  0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
152  0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01,
153  0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01,
154  0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01,
155  0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01,
156  0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
157  0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00,
158  0x00, 0x89, 0x88, 0x88, 0xbd, 0x89, 0x88, 0x88, 0x3d, 0x00, 0x00, 0x00, 0x00,
159  0x89, 0x88, 0x88, 0x3d, 0x89, 0x88, 0x88, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x89,
160  0x88, 0x88, 0x3d, 0x89, 0x88, 0x88, 0xbd, 0x00, 0x00, 0x00, 0x00, 0x89, 0x88,
161  0x88, 0xbd, 0x89, 0x88, 0x88, 0xbd, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
162  0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01,
163  0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00,
164  0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00
165  };
166  unsigned int _conf_4L_6_len = 713;
167 
168  std::stringstream stream;
169  stream.write((char *)_conf_4L_6, sizeof(unsigned char) * _conf_4L_6_len);
170  _fromStream(fms, stream);
171  }
172  break;
173  case FRACTAL_5L_6:
174  {
175  unsigned char _conf_5L_6[] = {
176  0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
177  0x00, 0x00, 0x00, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xbf, 0x00, 0x00,
178  0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x80,
179  0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x80, 0xbf,
180  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xbf, 0x00, 0x00, 0x80, 0xbf, 0x00,
181  0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00,
182  0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00,
183  0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01,
184  0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00,
185  0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
186  0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
187  0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
188  0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01,
189  0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01,
190  0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00,
191  0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xa9, 0x00, 0x00, 0x00, 0x4f, 0xec, 0xc4,
192  0xbe, 0x4f, 0xec, 0xc4, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x4f, 0xec, 0xc4, 0x3e,
193  0x4f, 0xec, 0xc4, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x4f, 0xec, 0xc4, 0x3e, 0x4f,
194  0xec, 0xc4, 0xbe, 0x00, 0x00, 0x00, 0x00, 0x4f, 0xec, 0xc4, 0xbe, 0x4f, 0xec,
195  0xc4, 0xbe, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
196  0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01,
197  0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,
198  0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
199  0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
200  0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
201  0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
202  0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
203  0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
204  0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
205  0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,
206  0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
207  0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01,
208  0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
209  0x00, 0x02, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x7d, 0xcb, 0x37, 0xbe,
210  0x7d, 0xcb, 0x37, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x7d, 0xcb, 0x37, 0x3e, 0x7d,
211  0xcb, 0x37, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x7d, 0xcb, 0x37, 0x3e, 0x7d, 0xcb,
212  0x37, 0xbe, 0x00, 0x00, 0x00, 0x00, 0x7d, 0xcb, 0x37, 0xbe, 0x7d, 0xcb, 0x37,
213  0xbe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
214  0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00,
215  0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
216  0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
217  0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
218  0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01,
219  0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
220  0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01,
221  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01,
222  0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01,
223  0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00,
224  0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
225  0x00, 0x03, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0xd9, 0x89, 0x9d, 0xbd,
226  0xd9, 0x89, 0x9d, 0x3d, 0x00, 0x00, 0x00, 0x00, 0xd9, 0x89, 0x9d, 0x3d, 0xd9,
227  0x89, 0x9d, 0x3d, 0x00, 0x00, 0x00, 0x00, 0xd9, 0x89, 0x9d, 0x3d, 0xd9, 0x89,
228  0x9d, 0xbd, 0x00, 0x00, 0x00, 0x00, 0xd9, 0x89, 0x9d, 0xbd, 0xd9, 0x89, 0x9d,
229  0xbd, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01,
230  0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00,
231  0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00,
232  0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
233  0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
234  0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01,
235  0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00,
236  0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00,
237  0x01, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
238  0x24, 0x00, 0x00, 0x00, 0x21, 0x0d, 0xd2, 0xbc, 0x21, 0x0d, 0xd2, 0x3c, 0x00,
239  0x00, 0x00, 0x00, 0x21, 0x0d, 0xd2, 0x3c, 0x21, 0x0d, 0xd2, 0x3c, 0x00, 0x00,
240  0x00, 0x00, 0x21, 0x0d, 0xd2, 0x3c, 0x21, 0x0d, 0xd2, 0xbc, 0x00, 0x00, 0x00,
241  0x00, 0x21, 0x0d, 0xd2, 0xbc, 0x21, 0x0d, 0xd2, 0xbc, 0x00, 0x00, 0x00, 0x00,
242  0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01,
243  0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00,
244  0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
245  0x00
246  };
247  unsigned int _conf_5L_6_len = 898;
248 
249  std::stringstream stream;
250  stream.write((char *)_conf_5L_6, sizeof(unsigned char) * _conf_5L_6_len);
251  _fromStream(fms, stream);
252  }
253  break;
254  case CUSTOM:
255  throw cv::Exception(-1, "CUSTOM type is only set by loading from file",
256  "FractalMarkerSet::loadPredefined", "fractalmarkerset.h", -1);
257  break;
258 
259  default:
260  throw cv::Exception(9001, "Invalid Dictionary type requested",
261  "Dictionary::loadPredefined", __FILE__, __LINE__);
262  }
263  return fms;
264 }
265 
267 {
268  return getTypeFromString(str) != CUSTOM;
269 }
270 
272 {
273  switch (t)
274  {
275  case FRACTAL_2L_6:
276  return "FRACTAL_2L_6";
277  case FRACTAL_3L_6:
278  return "FRACTAL_3L_6";
279  case FRACTAL_4L_6:
280  return "FRACTAL_4L_6";
281  case FRACTAL_5L_6:
282  return "FRACTAL_5L_6";
283  case CUSTOM:
284  return "CUSTOM";
285  };
286  return "Non valid CONF_TYPE";
287 }
288 
290 {
291  if (str == "FRACTAL_2L_6")
292  return FRACTAL_2L_6;
293  if (str == "FRACTAL_3L_6")
294  return FRACTAL_3L_6;
295  if (str == "FRACTAL_4L_6")
296  return FRACTAL_4L_6;
297  if (str == "FRACTAL_5L_6")
298  return FRACTAL_5L_6;
299  else
300  return CUSTOM;
301 }
302 
303 std::vector<std::string> FractalMarkerSet::getConfigurations()
304 {
305  return { "FRACTAL_2L_6", "FRACTAL_3L_6", "FRACTAL_4L_6", "FRACTAL_5L_6" };
306 }
307 
308 void FractalMarkerSet::_toStream(FractalMarkerSet &configuration, std::ostream &str)
309 {
310  str.write((char *)&configuration.mInfoType, sizeof(mInfoType));
311  str.write((char *)&configuration._nmarkers, sizeof(_nmarkers));
312  str.write((char *)&configuration._idExternal, sizeof(_idExternal));
313 
314  for (auto fractal : configuration.fractalMarkerCollection)
315  {
316  // ID
317  int id = fractal.first;
318  str.write((char *)&id, sizeof(id));
319  // NBITS
320  int nbits = fractal.second.nBits();
321  str.write((char *)&nbits, sizeof(nbits));
322  // CORNERS
323  std::vector<cv::Point3f> corners = fractal.second.points;
324  str.write((char *)&corners[0], sizeof(cv::Point3f) * 4);
325  // MAT
326  cv::Mat mat = fractal.second.mat();
327  str.write((char *)mat.data, mat.elemSize() * mat.total());
328  // SUBMARKERS
329  std::vector<int> sub = fractal.second.subMarkers();
330  int nsub = sub.size();
331  str.write((char *)&nsub, sizeof(nsub));
332  str.write((char *)&sub[0], sizeof(int) * nsub);
333  }
334 }
335 
336 void FractalMarkerSet::_fromStream(FractalMarkerSet &configuration, std::istream &str)
337 {
338  str.read((char *)&configuration.mInfoType, sizeof(mInfoType));
339  str.read((char *)&configuration._nmarkers, sizeof(_nmarkers));
340  str.read((char *)&configuration._idExternal, sizeof(_idExternal));
341 
342  for (int i = 0; i < configuration._nmarkers; i++)
343  {
344  // ID
345  int id;
346  str.read((char *)&id, sizeof(id));
347  // NBITS
348  int nbits;
349  str.read((char *)&nbits, sizeof(nbits));
350 
351  // CORNERS
352  std::vector<cv::Point3f> corners(4);
353  str.read((char *)&corners[0], sizeof(cv::Point3f) * 4);
354  // MAT
355  cv::Mat mat;
356  mat.create(sqrt(nbits), sqrt(nbits), CV_8UC1);
357  str.read((char *)mat.data, mat.elemSize() * mat.total());
358  // SUBMARKERS
359  int nsub;
360  str.read((char *)&nsub, sizeof(nsub));
361  std::vector<int> id_submarkers(nsub);
362  if (nsub > 0)
363  str.read((char *)&id_submarkers[0], sizeof(int) * nsub);
364 
365  FractalMarker fractalMarker = FractalMarker(id, mat, corners, id_submarkers);
366  configuration.nbits_fractalMarkerIDs[mat.total()].push_back(fractalMarker.id);
367  configuration.fractalMarkerCollection[fractalMarker.id] = fractalMarker;
368  }
369 
370  // Add subfractals
371  for (auto &id_marker : configuration.fractalMarkerCollection)
372  {
373  FractalMarker &marker = id_marker.second;
374  for (auto id : id_marker.second.subMarkers())
375  marker.addSubFractalMarker(configuration.fractalMarkerCollection[id]);
376  }
377 }
378 
379 void FractalMarkerSet::create(std::vector<std::pair<int, int>> regionsConfig, float pixSize)
380 {
381  if (pixSize == -1)
382  {
383  mInfoType = NORM;
384  pixSize = 1;
385  }
386  else
387  mInfoType = PIX;
388 
389  _nmarkers = regionsConfig.size();
390  _idExternal = 0;
391 
392  std::vector<int> submarkers;
393  submarkers.clear();
394  float pix = 0;
395  for (int n = regionsConfig.size() - 1; n >= 0; n--)
396  {
397  int nVal = regionsConfig[n].first;
398  int kVal = regionsConfig[n].second;
399 
400  cv::Mat mat = configureMat(nVal, kVal);
401 
402  pix = (nVal + 2) * pixSize;
403  std::vector<cv::Point3f> corners = { cv::Point3f(-pix / 2, pix / 2, 0.),
404  cv::Point3f(pix / 2, pix / 2, 0.),
405  cv::Point3f(pix / 2, -pix / 2, 0.),
406  cv::Point3f(-pix / 2, -pix / 2, 0.) };
407 
408  FractalMarker fractal = FractalMarker(n, mat, corners, submarkers);
409  fractalMarkerCollection[n] = fractal;
410  submarkers.clear();
411  submarkers.push_back(n);
412 
413 
414  float kValSup = regionsConfig[n - 1].second - 2;
415  float newP = (nVal + 2) / (kValSup);
416  pixSize = newP * pixSize;
417  }
418 
419  // Normalize corners. Fractal marker: (-1,1,0)(1,1,0)(1,-1,0)(-1,-1,0)
420  if (isNormalize())
421  {
422  for (auto &m : fractalMarkerCollection)
423  {
424  for (auto &c : m.second.points)
425  {
426  c.x /= pix / 2;
427  c.y /= pix / 2;
428  }
429  }
430  }
431 }
432 
433 cv::Mat FractalMarkerSet::configureMat(int nVal, int kVal, int maxIter)
434 {
435  // Pixels to configure (n-k region)
436  std::vector<cv::Point2i> pixels;
437  for (int y = 0; y < nVal; y++)
438  {
439  for (int x = 0; x < nVal; x++)
440  {
441  if ((x <= ((nVal - kVal) / 2) - 1 || x >= kVal + (nVal - kVal) / 2) ||
442  (y <= ((nVal - kVal) / 2) - 1 || y >= kVal + (nVal - kVal) / 2))
443  {
444  pixels.push_back(cv::Point2i(x, y));
445  }
446  }
447  }
448 
449  int dst_mkr = 0;
450  int dst_set = 0;
451 
452  cv::Mat m;
453  int markerIters = 0;
454  do
455  {
456  std::vector<cv::Point2i> conf_pixels = pixels;
457  m = cv::Mat::ones(nVal, nVal, CV_8UC1);
458 
459  // struct timespec ts;
460  // clock_gettime(CLOCK_MONOTONIC, &ts);
461  // srand((time_t)ts.tv_nsec);
462 
463  // Random delete half of pixels
464  int npix = conf_pixels.size() / 2;
465  for (int i = 0; i < npix; i++)
466  {
467  int idxSelected = rand() % conf_pixels.size();
468  conf_pixels.erase(conf_pixels.begin() + idxSelected);
469  }
470 
471  // Put the new configuration (0 selected pixels)
472  for (auto p : conf_pixels)
473  m.at<char>(p.y, p.x) = 0;
474 
475  // Check marker distance to itself
476  int new_dst_mkr = dstMarker(m);
477  if (new_dst_mkr > dst_mkr)
478  {
479  // Check marker distance to set
480  int new_dst_set = dstMarkerToFractalDict(m);
481  if (new_dst_set > dst_set)
482  {
483  dst_mkr = new_dst_mkr;
484  dst_set = new_dst_set;
485  }
486  }
487  } while (markerIters++ < maxIter);
488 
489  for (int y = ((nVal - kVal) / 2) + 1; y < kVal + (nVal - kVal) / 2 - 1; y++)
490  {
491  for (int x = ((nVal - kVal) / 2) + 1; x < kVal + (nVal - kVal) / 2 - 1; x++)
492  {
493  m.at<char>(y, x) = 0;
494  }
495  }
496 
497  return m;
498 }
499 
500 /*
501  * Calculate minimum distance between marker 'm' and the 4 rotations of each word in the dictionary
502  */
504 {
505  int HDist = m.cols * m.rows; // distancia maxima
506  int HDistTemp;
507 
508  for (auto marker : fractalMarkerCollection)
509  {
510  if (marker.second.nBits() == m.total())
511  {
512  HDistTemp = dstMarkerToMarker(marker.second.mat(), m);
513 
514  if (HDistTemp == 0)
515  return 0;
516  else if (HDistTemp < HDist)
517  HDist = HDistTemp;
518  }
519  }
520  return HDist;
521 }
522 
523 /*
524  * Calculate minimum distance between marker1 'm' and the 4 rotations of marker2 'm2'
525  */
526 auto rotate = [](const cv::Mat &m)
527 {
528  cv::Mat out;
529  m.copyTo(out);
530  for (int i = 0; i < m.rows; i++)
531  {
532  for (int j = 0; j < m.cols; j++)
533  {
534  out.at<char>(i, j) = m.at<char>(m.cols - j - 1, i);
535  }
536  }
537  return out;
538 };
539 
540 int FractalMarkerSet::dstMarker(const cv::Mat m)
541 {
542  int HDist = m.cols * m.rows; // maximum distance
543  int HDistTemp;
544 
545  cv::Mat rot;
546  m.copyTo(rot);
547 
548 
549  for (int i = 0; i < 3; i++)
550  {
551  cv::Mat diff;
552  rot = rotate(rot);
553  cv::compare(rot, m, diff, cv::CMP_NE);
554  HDistTemp = cv::countNonZero(diff);
555  if (HDistTemp < HDist)
556  HDist = HDistTemp;
557  }
558  return HDist;
559 }
560 
561 int FractalMarkerSet::dstMarkerToMarker(const cv::Mat m1, const cv::Mat m2)
562 {
563  int HDist = m2.cols * m2.rows; // maximum distance
564  int HDistTemp;
565 
566  for (int i = 0; i < 4; i++)
567  {
568  cv::Mat diff;
569  cv::compare(rotate(m2), m1, diff, cv::CMP_NE);
570  HDistTemp = cv::countNonZero(diff);
571  if (HDistTemp < HDist)
572  HDist = HDistTemp;
573  }
574 
575  return HDist;
576 }
577 
578 
580 {
581  cv::FileStorage fs;
582  try
583  {
584  fs.open(path, cv::FileStorage::READ);
585  }
586  catch (std::exception &ex)
587  {
588  throw cv::Exception(81818, "FractalMarkerSet::readFromFile",
589  ex.what() + std::string(" file=)") + path, __FILE__, __LINE__);
590  }
591 
592  FractalMarkerSet configuration;
593 
594  fs["mInfoType"] >> configuration.mInfoType;
595  fs["fractal_levels"] >> configuration._nmarkers;
596  fs["fractal_external_id"] >> configuration._idExternal;
597 
598  cv::FileNode markers = fs["markers"];
599  int i = 0;
600  for (cv::FileNodeIterator it = markers.begin(); it != markers.end(); ++it, i++)
601  {
602  int id = (*it)["id"];
603  std::vector<int> bits;
604 
605  std::vector<cv::Point3f> corners;
606  std::vector<int> submarkers_id;
607 
608  cv::FileNode bitsMarker = (*it)["bits"];
609  for (cv::FileNodeIterator itb = bitsMarker.begin(); itb != bitsMarker.end(); ++itb)
610  {
611  bits.push_back(*itb);
612  }
613  cv::Mat m = cv::Mat(sqrt(bits.size()), sqrt(bits.size()), CV_32SC1);
614  memcpy(m.data, bits.data(), bits.size() * sizeof(int));
615 
616  m.convertTo(m, CV_8UC1);
617 
618  cv::FileNode cornersFractal = (*it)["corners"];
619  for (cv::FileNodeIterator itp = cornersFractal.begin(); itp != cornersFractal.end(); ++itp)
620  {
621  std::vector<float> coordinates3d;
622  (*itp) >> coordinates3d;
623  if (coordinates3d.size() != 3)
624  throw cv::Exception(81818, "FractalMarkerSet::readFromFile",
625  "invalid file type 3", __FILE__, __LINE__);
626  cv::Point3f point(coordinates3d[0], coordinates3d[1], coordinates3d[2]);
627  corners.push_back(point);
628  }
629 
630  cv::FileNode submarkersID = (*it)["submarkers_id"];
631  for (cv::FileNodeIterator itm = submarkersID.begin(); itm != submarkersID.end(); ++itm)
632  {
633  submarkers_id.push_back((*itm));
634  }
635 
636  FractalMarker fractalMarker = FractalMarker(id, m, corners, submarkers_id);
637  configuration.nbits_fractalMarkerIDs[m.total()].push_back(fractalMarker.id);
638  configuration.fractalMarkerCollection[fractalMarker.id] = fractalMarker;
639  }
640 
641  // Add subfractals
642  for (auto &id_marker : configuration.fractalMarkerCollection)
643  {
644  FractalMarker &marker = id_marker.second;
645  for (auto id : id_marker.second.subMarkers())
646  marker.addSubFractalMarker(configuration.fractalMarkerCollection[id]);
647  }
648 
649  return configuration;
650 }
651 
652 void FractalMarkerSet::saveToFile(cv::FileStorage &fs)
653 {
654  fs << "codeid"
655  << "fractalmarkers";
656  fs << "mInfoType" << mInfoType;
657  fs << "fractal_levels" << _nmarkers;
658  fs << "fractal_external_id" << _idExternal;
659  fs << "markers"
660  << "[";
661  for (auto id_marker : fractalMarkerCollection)
662  {
663  FractalMarker marker = id_marker.second;
664 
665  fs << "{:"
666  << "id" << (int)id_marker.first;
667 
668  fs << "bits"
669  << "[:";
670  cv::Mat m = marker.mat();
671  for (int y = 0; y < m.cols; y++)
672  for (int x = 0; x < m.rows; x++)
673  if (m.at<char>(y, x) == 2)
674  fs << 0;
675  else
676  fs << m.at<char>(y, x);
677  fs << "]";
678 
679  fs << "corners"
680  << "[:";
681  for (auto corner : marker.points)
682  fs << corner;
683  fs << "]";
684 
685  fs << "submarkers_id"
686  << "[:";
687  for (auto idsub : marker.subMarkers())
688  fs << (int)idsub;
689  fs << "]";
690 
691  fs << "}";
692  }
693  fs << "]";
694 }
695 
696 bool FractalMarkerSet::isFractalMarker(cv::Mat &m, int nbits, int &markerid)
697 {
698  bool found = false;
699 
700  for (auto id : nbits_fractalMarkerIDs[nbits])
701  {
703 
704  // Apply mask to substract submarkers
705  cv::Mat m2;
706  m.copyTo(m2, fm.mask());
707 
708  // Code without submarkers == fractal marker?
709  if (cv::countNonZero(m2 != fm.mat()) == 0)
710  {
711  found = true;
712 
713  // Change new code!!
715  markerid = fm.id;
717 
718  break;
719  }
720  }
721 
722  return found;
723 }
724 
726 {
727  if (!(isExpressedInPixels() || isNormalize()))
728  throw cv::Exception(-1, "The FractalMarkers are not expressed in pixels",
729  "FractalMarkerSet::convertToMeters", __FILE__, __LINE__);
730 
731  FractalMarkerSet BInfo(*this);
733 
734  // now, get the size of a pixel, and change scale
735  float pixSizeM = fractalSizeM / float(BInfo.getFractalSize());
736 
737  for (size_t i = 0; i < BInfo.fractalMarkerCollection.size(); i++)
738  {
739  // Convert to meters the position fractal marker
740  for (int c = 0; c < 4; c++)
741  {
742  BInfo.fractalMarkerCollection[i][c] *= pixSizeM;
743  }
744  }
745  return BInfo;
746 }
747 
749 {
751  throw cv::Exception(-1, "The FractalMarkers are not expressed in pixels or meters",
752  "FractalMarkerSet::convertToMeters", __FILE__, __LINE__);
753 
754  FractalMarkerSet BInfo(*this);
756 
757  float currentHalfSize = BInfo.getFractalSize() / 2.f;
758 
759  for (size_t i = 0; i < BInfo.fractalMarkerCollection.size(); i++)
760  {
761  // Normalize the position fractal marker
762  for (size_t c = 0; c < 4; c++)
763  {
764  BInfo.fractalMarkerCollection[i][c] /= currentHalfSize;
765  }
766  }
767 
768  return BInfo;
769 }
770 
771 std::map<int, std::vector<cv::Point3f>> FractalMarkerSet::getInnerCorners()
772 {
773  std::map<int, std::vector<cv::Point3f>> id_innerCorners;
774 
775  for (auto id_fm : fractalMarkerCollection)
776  {
777  int id = id_fm.first;
778  FractalMarker fm = id_fm.second;
779 
780  for (auto ic : fm.getInnerCorners())
781  id_innerCorners[id].push_back(ic); // Conversion
782  }
783  return id_innerCorners;
784 }
785 
786 cv::Mat FractalMarkerSet::getFractalMarkerImage(int pixSize, bool border)
787 {
788  if (fractalMarkerCollection.size() < 1)
789  throw cv::Exception(9001, "There is not any fractal marker loaded",
790  "FractalMarkerSet::getFractalMarkerImage", __FILE__, __LINE__);
791 
792  // Smallest fractal marker
793  FractalMarker innerM = (--fractalMarkerCollection.end())->second;
794  float bitSize = innerM.getMarkerSize() / (pixSize * (sqrt(innerM.nBits()) + 2));
795 
797  float markerSize = externMarker.getMarkerSize() / bitSize;
798  float markerBitSize = markerSize / (sqrt(externMarker.nBits()) + 2);
799  cv::Mat img = cv::Mat::zeros(markerSize, markerSize, CV_8U);
800 
801  // Asign value pixels
802  cv::Mat m = externMarker.mat();
803 
804  for (int y = m.cols - 1; y >= 0; y--)
805  for (int x = m.cols - 1; x >= 0; x--)
806  {
807  if (m.at<uchar>(y, x) == 1)
808  {
809  cv::Range val1 = cv::Range((1 + y) * markerBitSize, (y + 2) * markerBitSize);
810  cv::Range val2 = cv::Range((1 + x) * markerBitSize, (x + 2) * markerBitSize);
811 
812  cv::Mat bit_pix = img(val1, val2);
813  bit_pix.setTo(cv::Scalar::all(255));
814  }
815  }
816 
817  for (auto idSubmarker : externMarker.subMarkers())
818  {
819  std::vector<int> idds;
820  idds.push_back(idSubmarker);
821  while (!idds.empty())
822  {
823  idSubmarker = idds.back();
824  idds.pop_back();
825 
826  FractalMarker submarker = fractalMarkerCollection[idSubmarker];
827 
828  cv::Mat m = submarker.mat();
829  cv::Point3f coord = submarker.points[0];
830 
831  float markerSize = submarker.getMarkerSize() / bitSize;
832  float markerBitSize = markerSize / (sqrt(submarker.nBits()) + 2);
833 
834  // Get position inside fractal marker
835  float offsetX = fabs(coord.x - externMarker.points[0].x) / bitSize;
836  float offsetY = fabs(coord.y - externMarker.points[0].y) / bitSize;
837 
838  // Asign value pixels
839  for (int y = m.cols - 1; y >= 0; y--)
840  for (int x = m.cols - 1; x >= 0; x--)
841  {
842  if (m.at<uchar>(y, x) == 1)
843  {
844  cv::Range val1 = cv::Range((1 + y) * markerBitSize + offsetY,
845  (2 + y) * markerBitSize + offsetY);
846  cv::Range val2 = cv::Range((1 + x) * markerBitSize + offsetX,
847  (2 + x) * markerBitSize + offsetX);
848 
849  cv::Mat bit_pix = img(val1, val2);
850  bit_pix.setTo(cv::Scalar::all(255));
851  }
852  }
853 
854  // Add submarkers to draw
855  for (auto idsm : submarker.subMarkers())
856  idds.push_back(idsm);
857  }
858  }
859 
860  if (border)
861  copyMakeBorder(img, img, markerBitSize, markerBitSize, markerBitSize, markerBitSize,
862  cv::BORDER_CONSTANT, cv::Scalar::all(255));
863 
864  return img;
865 }
866 }; // namespace aruco
aruco::FractalMarkerSet::_fromStream
static void _fromStream(FractalMarkerSet &configuration, std::istream &str)
Definition: fractalmarkerset.cpp:336
aruco::FractalMarkerSet::create
void create(std::vector< std::pair< int, int >> regionsConfig, float pixSize)
create
Definition: fractalmarkerset.cpp:379
aruco::FractalMarkerSet::saveToFile
void saveToFile(cv::FileStorage &fs)
Definition: fractalmarkerset.cpp:652
aruco::FractalMarker::subMarkers
std::vector< int > subMarkers()
Definition: fractalmarker.h:43
aruco::FractalMarkerSet::isNormalize
bool isNormalize() const
Definition: fractalmarkerset.h:96
aruco::FractalMarkerSet::METERS
@ METERS
Definition: fractalmarkerset.h:78
aruco::FractalMarkerSet::loadPredefined
static FractalMarkerSet loadPredefined(std::string info)
Definition: fractalmarkerset.cpp:16
aruco::FractalMarker::addSubFractalMarker
void addSubFractalMarker(FractalMarker submarker)
Definition: fractalmarker.cpp:24
aruco::FractalMarkerSet::FRACTAL_5L_6
@ FRACTAL_5L_6
Definition: fractalmarkerset.h:18
aruco::FractalMarkerSet::CUSTOM
@ CUSTOM
Definition: fractalmarkerset.h:19
aruco::Marker3DInfo::points
std::vector< cv::Point3f > points
Definition: markermap.h:36
aruco::FractalMarkerSet::CONF_TYPES
CONF_TYPES
Definition: fractalmarkerset.h:13
aruco::FractalMarkerSet::mInfoType
int mInfoType
Definition: fractalmarkerset.h:132
aruco::FractalMarkerSet::_idExternal
int _idExternal
Definition: fractalmarkerset.h:138
aruco::FractalMarkerSet::isPredefinedConfigurationString
static bool isPredefinedConfigurationString(std::string str)
Definition: fractalmarkerset.cpp:266
aruco::FractalMarker::mat
const cv::Mat mat() const
Definition: fractalmarker.h:25
aruco::FractalMarkerSet::normalize
FractalMarkerSet normalize()
Definition: fractalmarkerset.cpp:748
aruco::FractalMarkerSet::getTypeString
static std::string getTypeString(FractalMarkerSet::CONF_TYPES t)
Definition: fractalmarkerset.cpp:271
aruco::FractalMarker::nBits
int nBits()
Definition: fractalmarker.h:37
aruco::FractalMarkerSet::_nmarkers
int _nmarkers
Definition: fractalmarkerset.h:136
aruco::FractalMarker::mask
const cv::Mat mask() const
Definition: fractalmarker.h:31
aruco::FractalMarkerSet::dstMarkerToFractalDict
int dstMarkerToFractalDict(cv::Mat m)
Definition: fractalmarkerset.cpp:503
aruco::FractalMarkerSet::nbits_fractalMarkerIDs
std::map< int, std::vector< int > > nbits_fractalMarkerIDs
Definition: fractalmarkerset.h:72
aruco::FractalMarkerSet::configureMat
cv::Mat configureMat(int nVal, int kVal, int maxIter=10000)
configureMat
Definition: fractalmarkerset.cpp:433
aruco::Marker3DInfo::push_back
void push_back(const cv::Point3f &p)
Definition: markermap.h:63
aruco::FractalMarkerSet::NORM
@ NORM
Definition: fractalmarkerset.h:79
aruco::FractalMarkerSet::isExpressedInPixels
bool isExpressedInPixels() const
Definition: fractalmarkerset.h:90
aruco::FractalMarkerSet::getFractalSize
float getFractalSize() const
Definition: fractalmarkerset.h:110
aruco::FractalMarker::getInnerCorners
std::vector< cv::Point3f > getInnerCorners()
Definition: fractalmarker.h:49
aruco::FractalMarkerSet::dstMarker
int dstMarker(const cv::Mat m)
Definition: fractalmarkerset.cpp:540
aruco::FractalMarkerSet::convertToMeters
FractalMarkerSet convertToMeters(float fractalSize_meters)
Definition: fractalmarkerset.cpp:725
aruco::FractalMarkerSet::_toStream
static void _toStream(FractalMarkerSet &configuration, std::ostream &str)
Definition: fractalmarkerset.cpp:308
aruco::FractalMarkerSet::dstMarkerToMarker
int dstMarkerToMarker(const cv::Mat m1, const cv::Mat m2)
Definition: fractalmarkerset.cpp:561
aruco::FractalMarkerSet::FRACTAL_3L_6
@ FRACTAL_3L_6
Definition: fractalmarkerset.h:16
aruco::Marker3DInfo::id
int id
Definition: markermap.h:37
aruco::FractalMarkerSet::PIX
@ PIX
Definition: fractalmarkerset.h:77
aruco::FractalMarkerSet::getFractalMarkerImage
cv::Mat getFractalMarkerImage(int pixSize, bool border=false)
Definition: fractalmarkerset.cpp:786
aruco::Marker3DInfo::getMarkerSize
float getMarkerSize() const
Definition: markermap.h:47
aruco::FractalMarkerSet::fractalMarkerCollection
std::map< int, FractalMarker > fractalMarkerCollection
Definition: fractalmarkerset.h:70
aruco::FractalMarkerSet::load
static FractalMarkerSet load(std::string info)
Definition: fractalmarkerset.cpp:8
fractalmarkerset.h
aruco::FractalMarkerSet::isFractalMarker
bool isFractalMarker(cv::Mat &m, int nbits, int &id)
Definition: fractalmarkerset.cpp:696
aruco::FractalMarkerSet::getConfigurations
static std::vector< std::string > getConfigurations()
Definition: fractalmarkerset.cpp:303
aruco::FractalMarkerSet::FRACTAL_4L_6
@ FRACTAL_4L_6
Definition: fractalmarkerset.h:17
aruco
Definition: cameraparameters.h:24
aruco::FractalMarkerSet::isExpressedInMeters
bool isExpressedInMeters() const
Definition: fractalmarkerset.h:84
aruco::FractalMarkerSet
Definition: fractalmarkerset.h:10
aruco::FractalMarkerSet::FRACTAL_2L_6
@ FRACTAL_2L_6
Definition: fractalmarkerset.h:15
aruco::FractalMarker
Definition: fractalmarker.h:11
aruco::FractalMarkerSet::readFromFile
static FractalMarkerSet readFromFile(std::string path)
Definition: fractalmarkerset.cpp:579
aruco::FractalMarkerSet::getInnerCorners
std::map< int, std::vector< cv::Point3f > > getInnerCorners()
Definition: fractalmarkerset.cpp:771
aruco::rotate
auto rotate
Definition: fractalmarkerset.cpp:526
aruco::FractalMarkerSet::getTypeFromString
static CONF_TYPES getTypeFromString(std::string str)
Definition: fractalmarkerset.cpp:289


aruco
Author(s): Rafael Muñoz Salinas , Bence Magyar
autogenerated on Sat Sep 23 2023 02:26:45