Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef HIGHLYRELIABLEMARKERS_H
00030 #define HIGHLYRELIABLEMARKERS_H
00031
00032
00033 #include <vector>
00034 #include <math.h>
00035 #include <string>
00036 #include <opencv2/core/core.hpp>
00037 #include <opencv2/imgproc/imgproc.hpp>
00038 #include "exports.h"
00039
00040 #include <iostream>
00041
00042 namespace aruco {
00043
00049 class ARUCO_EXPORTS MarkerCode {
00050 public:
00054 MarkerCode(unsigned int n = 0);
00055
00059 MarkerCode(const MarkerCode &MC);
00060
00064 unsigned int getId(unsigned int rot = 0) const { return _ids[rot]; };
00065
00070 bool get(unsigned int pos, unsigned int rot = 0) const { return _bits[rot][pos]; }
00071
00075 const std::vector< bool > &getRotation(unsigned int rot) const { return _bits[rot]; };
00076
00085 void set(unsigned int pos, bool val, bool updateIds=true);
00086
00090 unsigned int size() const { return n() * n(); };
00091
00095 unsigned int n() const { return _n; };
00096
00101 unsigned int selfDistance(unsigned int &minRot) const;
00102
00107 unsigned int selfDistance() const {
00108 unsigned int minRot;
00109 return selfDistance(minRot);
00110 };
00111
00116 unsigned int distance(const MarkerCode &m, unsigned int &minRot) const;
00117
00122 unsigned int distance(const MarkerCode &m) const {
00123 unsigned int minRot;
00124 return distance(m, minRot);
00125 };
00126
00130 void fromString(std::string s);
00131
00135 std::string toString() const;
00136
00137
00142 cv::Mat getImg(unsigned int pixSize) const;
00143
00144 private:
00145 unsigned int _ids[4];
00146 std::vector< bool > _bits[4];
00147 unsigned int _n;
00148
00152 unsigned int hammingDistance(const std::vector< bool > &m1, const std::vector< bool > &m2) const;
00153 };
00154
00155
00161 class ARUCO_EXPORTS Dictionary : public std::vector< MarkerCode > {
00162 public:
00166 bool fromFile(std::string filename);
00167
00171 bool toFile(std::string filename);
00172
00178 unsigned int distance(const MarkerCode &m, unsigned int &minMarker, unsigned int &minRot);
00179
00184 unsigned int distance(const MarkerCode &m) {
00185 unsigned int minMarker, minRot;
00186 return distance(m, minMarker, minRot);
00187 }
00188
00192 unsigned int minimunDistance();
00193
00194 int tau0;
00195
00196 private:
00197
00198 template < class T > static std::string toStr(T num) {
00199 std::stringstream ss;
00200 ss << num;
00201 return ss.str();
00202 }
00203 };
00204
00205
00211 class ARUCO_EXPORTS HighlyReliableMarkers {
00212 public:
00217 class BalancedBinaryTree {
00218
00219 public:
00223 void loadDictionary(Dictionary *D);
00224
00228 bool findId(unsigned int id, unsigned int &orgPos);
00229
00230 private:
00231 std::vector< std::pair< unsigned int, unsigned int > > _orderD;
00232
00233
00234 std::vector< std::pair< int, int > > _binaryTree;
00235
00236
00237
00238 unsigned int _root;
00239 };
00240
00244
00245 static bool loadDictionary(Dictionary D, float correctionDistance = 1);
00246 static bool loadDictionary(std::string filename, float correctionDistance = 1);
00247 static Dictionary &getDictionary() { return _D; }
00248
00249
00255 static int detect(const cv::Mat &in, int &nRotations);
00256
00257
00258 private:
00259 static Dictionary _D;
00260 static BalancedBinaryTree _binaryTree;
00261
00262 static unsigned int _n;
00263 static unsigned int _ncellsBorder;
00264 static unsigned int _correctionDistance;
00265 static int _swidth;
00266
00267
00271 static bool checkBorders(cv::Mat grey);
00272
00276 static MarkerCode getMarkerCode(const cv::Mat &grey);
00277 };
00278
00279 }
00280
00281
00282 #endif // HIGHLYRELIABLEMARKERS_H