markermap.h
Go to the documentation of this file.
1 
17 #ifndef _Aruco_MarkerMap_h
18 #define _Aruco_MarkerMap_h
19 
20 #include "aruco_export.h"
21 #include "marker.h"
22 
23 #include <opencv2/core/core.hpp>
24 
25 #include <string>
26 #include <vector>
27 
28 namespace aruco
29 {
34 {
35 public:
36  std::vector<cv::Point3f> points;
37  int id; // maker id
38 
39  Marker3DInfo();
40  Marker3DInfo(int _id);
41  inline bool operator==(const Marker3DInfo& MI)
42  {
43  return id == MI.id;
44  }
45 
46  // returns the distance of the marker side
47  inline float getMarkerSize() const
48  {
49  return static_cast<float>(cv::norm(points[0] - points[1]));
50  }
51  inline cv::Point3f at(size_t idx) const
52  {
53  return points.at(idx);
54  }
55  inline cv::Point3f& operator[](size_t idx)
56  {
57  return points[idx];
58  }
59  inline const cv::Point3f& operator[](size_t idx) const
60  {
61  return points[idx];
62  }
63  inline void push_back(const cv::Point3f& p)
64  {
65  points.push_back(p);
66  }
67  inline size_t size() const
68  {
69  return points.size();
70  }
71 
72 public:
73  inline void toStream(std::ostream& str)
74  {
75  str << id << " " << size() << " ";
76  for (size_t i = 0; i < size(); i++)
77  str << at(i).x << " " << at(i).y << " " << at(i).z << " ";
78  }
79  inline void fromStream(std::istream& str)
80  {
81  int s;
82  str >> id >> s;
83  points.resize(s);
84  for (size_t i = 0; i < size(); i++)
85  str >> points[i].x >> points[i].y >> points[i].z;
86  }
87 };
88 
111 class ARUCO_EXPORT MarkerMap : public std::vector<Marker3DInfo>
112 {
113 public:
116  MarkerMap();
117 
121  MarkerMap(std::string filePath);
122 
125  bool isExpressedInMeters() const
126  {
127  return mInfoType == METERS;
128  }
131  bool isExpressedInPixels() const
132  {
133  return mInfoType == PIX;
134  }
137  MarkerMap convertToMeters(float markerSize) const;
138  // simple way of knowing which elements detected in an image are from this markermap
139  // returns the indices of the elements in the vector 'markers' that belong to this set
140  // Example: The set has the elements with ids 10,21,31,41,92
141  // The input vector has the markers with ids 10,88,9,12,41
142  // function returns {0,4}, because element 0 (10) of the vector belongs to the set, and
143  // also element 4 (41) belongs to the set
144  std::vector<int> getIndices(const vector<Marker>& markers) const;
145 
148  const Marker3DInfo& getMarker3DInfo(int id) const;
149 
152  int getIndexOfMarkerId(int id) const;
155  void getIdList(vector<int>& ids, bool append = true) const;
156 
160  cv::Mat getImage(float METER2PIX = 0) const;
161 
164  void saveToFile(std::string sfile);
167  void readFromFile(std::string sfile);
168 
169  // calculates the camera location w.r.t. the map using the information provided
170  // returns the <rvec,tvec>
171  std::pair<cv::Mat, cv::Mat> calculateExtrinsics(const std::vector<aruco::Marker>& markers,
172  float markerSize, cv::Mat CameraMatrix,
173  cv::Mat Distorsion);
174 
175  // returns string indicating the dictionary
176  inline std::string getDictionary() const
177  {
178  return dictionary;
179  }
180 
182  {
183  NONE = -1,
184  PIX = 0,
185  METERS = 1
186  }; // indicates if the data in MakersInfo is expressed in meters or in pixels so as to do conversion internally
187  // returns string indicating the dictionary
188  void setDictionary(std::string d)
189  {
190  dictionary = d;
191  }
192 
193  // variable indicates if the data in MakersInfo is expressed in meters or in pixels so
194  // as to do conversion internally
196 
197 private:
198  // dictionary it belongs to (if any)
199  std::string dictionary;
200 
201 private:
204  void saveToFile(cv::FileStorage& fs);
207  void readFromFile(cv::FileStorage& fs);
208 
209 public:
210  void toStream(std::ostream& str);
211  void fromStream(std::istream& str);
212 };
213 } // namespace aruco
214 
215 #endif
aruco::Marker3DInfo::operator[]
const cv::Point3f & operator[](size_t idx) const
Definition: markermap.h:59
aruco::MarkerMap
This class defines a set of markers whose locations are attached to a common reference system,...
Definition: markermap.h:111
aruco::Marker3DInfo::at
cv::Point3f at(size_t idx) const
Definition: markermap.h:51
aruco::Marker3DInfo::points
std::vector< cv::Point3f > points
Definition: markermap.h:36
aruco::Marker3DInfo::operator[]
cv::Point3f & operator[](size_t idx)
Definition: markermap.h:55
aruco::MarkerMap::setDictionary
void setDictionary(std::string d)
Definition: markermap.h:188
marker.h
aruco::MarkerMap::isExpressedInPixels
bool isExpressedInPixels() const
Definition: markermap.h:131
aruco::Marker3DInfo::fromStream
void fromStream(std::istream &str)
Definition: markermap.h:79
aruco::Marker3DInfo::toStream
void toStream(std::ostream &str)
Definition: markermap.h:73
aruco::Marker3DInfo::size
size_t size() const
Definition: markermap.h:67
aruco_export.h
aruco::Marker3DInfo::push_back
void push_back(const cv::Point3f &p)
Definition: markermap.h:63
d
d
aruco::Marker3DInfo::operator==
bool operator==(const Marker3DInfo &MI)
Definition: markermap.h:41
aruco::MarkerMap::Marker3DInfoType
Marker3DInfoType
Definition: markermap.h:181
aruco::Marker3DInfo::id
int id
Definition: markermap.h:37
aruco::Marker3DInfo::getMarkerSize
float getMarkerSize() const
Definition: markermap.h:47
ARUCO_EXPORT
#define ARUCO_EXPORT
Definition: aruco_export.h:30
aruco::MarkerMap::mInfoType
int mInfoType
Definition: markermap.h:195
aruco
Definition: cameraparameters.h:24
aruco::MarkerMap::isExpressedInMeters
bool isExpressedInMeters() const
Definition: markermap.h:125
aruco::MarkerMap::dictionary
std::string dictionary
Definition: markermap.h:199
aruco::MarkerMap::getDictionary
std::string getDictionary() const
Definition: markermap.h:176
aruco::Marker3DInfo
Definition: markermap.h:33


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