marker.h
Go to the documentation of this file.
1 
17 #ifndef _Aruco_Marker_H
18 #define _Aruco_Marker_H
19 
20 #include "aruco_export.h"
21 
22 #include <opencv2/core/core.hpp>
23 
24 #include <cstdint>
25 #include <iostream>
26 #include <vector>
27 
28 namespace aruco
29 {
34 class CameraParameters;
35 class ARUCO_EXPORT Marker : public std::vector<cv::Point2f>
36 {
37 public:
38  // id of the marker
39  int id;
40  // size of the markers sides in meters
41  float ssize;
42  // matrices of rotation and translation respect to the camera
43  cv::Mat Rvec, Tvec;
44  // additional info about the dictionary
45  std::string dict_info;
46  // points of the contour
47  vector<cv::Point> contourPoints;
48 
51  Marker();
54  Marker(int id);
57  Marker(const Marker& M);
60  Marker(const std::vector<cv::Point2f>& corners, int _id = -1);
64  {
65  }
68  bool isValid() const
69  {
70  return id != -1 && size() == 4;
71  }
72 
73  bool isPoseValid() const
74  {
75  return !Rvec.empty() && !Tvec.empty();
76  }
79  void draw(cv::Mat& in, cv::Scalar color = cv::Scalar(0, 0, 255), int lineWidth = -1,
80  bool writeId = true, bool writeInfo = false) const;
81 
88  void calculateExtrinsics(float markerSize, const CameraParameters& CP,
89  bool setYPerpendicular = true);
99  void calculateExtrinsics(float markerSize, cv::Mat CameraMatrix,
100  cv::Mat Distorsion = cv::Mat(), cv::Mat Extrinsics = cv::Mat(),
101  bool setYPerpendicular = true, bool correctFisheye = false);
102 
106  void glGetModelViewMatrix(double modelview_matrix[16]);
107 
118  void OgreGetPoseParameters(double position[3], double orientation[4]);
119 
122  cv::Point2f getCenter() const;
125  float getPerimeter() const;
128  float getArea() const;
131  float getRadius() const;
134  bool operator==(const Marker& m) const
135  {
136  return m.id == id;
137  }
138 
139  void copyTo(Marker& m) const;
142  Marker& operator=(const Marker& m);
143 
146  friend bool operator<(const Marker& M1, const Marker& M2)
147  {
148  return M1.id < M2.id;
149  }
152  friend std::ostream& operator<<(std::ostream& str, const Marker& M)
153  {
154  str << M.id << "=";
155  for (int i = 0; i < 4; i++)
156  str << "(" << M[i].x << "," << M[i].y << ") ";
157  if (!M.Tvec.empty() && !M.Rvec.empty())
158  {
159  str << "Txyz=";
160  for (int i = 0; i < 3; i++)
161  str << M.Tvec.ptr<float>(0)[i] << " ";
162  str << "Rxyz=";
163  for (int i = 0; i < 3; i++)
164  str << M.Rvec.ptr<float>(0)[i] << " ";
165  }
166  return str;
167  }
168 
169 
170  // saves to a binary stream
171  void toStream(std::ostream& str) const;
172  // reads from a binary stream
173  void fromStream(std::istream& str);
174 
175  // returns the 3d points of a marker wrt its center
176  static vector<cv::Point3f> get3DPoints(float msize);
177  // returns the 3d points of this marker wrt its center
178  inline vector<cv::Point3f> get3DPoints() const
179  {
180  return get3DPoints(ssize);
181  }
182 
183  // returns the SE3 (4x4) transform matrix
184 
185  cv::Mat getTransformMatrix() const;
186 
187 private:
188  void rotateXAxis(cv::Mat& rotation);
189 };
190 } // namespace aruco
191 #endif
aruco::CameraParameters
Parameters of the camera.
Definition: cameraparameters.h:29
aruco::Marker::Rvec
cv::Mat Rvec
Definition: marker.h:43
aruco::Marker::isPoseValid
bool isPoseValid() const
Definition: marker.h:73
aruco::Marker::isValid
bool isValid() const
Definition: marker.h:68
aruco::Marker::id
int id
Definition: marker.h:39
aruco::Marker::operator<<
friend std::ostream & operator<<(std::ostream &str, const Marker &M)
Definition: marker.h:152
aruco::Marker::operator<
friend bool operator<(const Marker &M1, const Marker &M2)
Definition: marker.h:146
aruco_export.h
aruco::Marker
Definition: marker.h:35
aruco::Marker::operator==
bool operator==(const Marker &m) const
Definition: marker.h:134
aruco::Marker::~Marker
~Marker()
Definition: marker.h:63
aruco::Marker::contourPoints
vector< cv::Point > contourPoints
Definition: marker.h:47
ARUCO_EXPORT
#define ARUCO_EXPORT
Definition: aruco_export.h:30
aruco
Definition: cameraparameters.h:24
aruco::Marker::get3DPoints
vector< cv::Point3f > get3DPoints() const
Definition: marker.h:178
aruco::Marker::dict_info
std::string dict_info
Definition: marker.h:45
aruco::Marker::Tvec
cv::Mat Tvec
Definition: marker.h:43
aruco::Marker::ssize
float ssize
Definition: marker.h:41


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