marker.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 #ifndef _Aruco_Marker_H
29 #define _Aruco_Marker_H
30 #include "exports.h"
31 #include <vector>
32 #include <iostream>
33 #include <cstdint>
34 #include <opencv2/core/core.hpp>
35 #include "cameraparameters.h"
36 using namespace std;
37 namespace aruco {
42 class ARUCO_EXPORTS Marker : public std::vector< cv::Point2f > {
43  public:
44  // id of the marker
45  int id;
46  // size of the markers sides in meters
47  float ssize;
48  // matrices of rotation and translation respect to the camera
49  cv::Mat Rvec, Tvec;
50 
53  Marker();
56  Marker(int id);
59  Marker(const Marker &M);
62  Marker(const std::vector< cv::Point2f > &corners, int _id = -1);
65  ~Marker() {}
68  bool isValid() const { return id != -1 && size() == 4; }
69 
72  void draw(cv::Mat &in, cv::Scalar color, int lineWidth = 1, bool writeId = true) const;
73 
79  void calculateExtrinsics(float markerSize, const CameraParameters &CP, bool setYPerpendicular = true) throw(cv::Exception);
86  void calculateExtrinsics(float markerSize, cv::Mat CameraMatrix, cv::Mat Distorsion = cv::Mat(), bool setYPerpendicular = true) throw(cv::Exception);
87 
91  void glGetModelViewMatrix(double modelview_matrix[16]) throw(cv::Exception);
92 
103  void OgreGetPoseParameters(double position[3], double orientation[4]) throw(cv::Exception);
104 
107  cv::Point2f getCenter() const;
110  float getPerimeter() const;
113  float getArea() const;
116  bool operator==(const Marker &m)const{return m.id==id;}
119  friend bool operator<(const Marker &M1, const Marker &M2) { return M1.id < M2.id; }
122  friend ostream &operator<<(ostream &str, const Marker &M) {
123  str << M.id << "=";
124  for (int i = 0; i < 4; i++)
125  str << "(" << M[i].x << "," << M[i].y << ") ";
126  str << "Txyz=";
127  for (int i = 0; i < 3; i++)
128  str << M.Tvec.ptr< float >(0)[i] << " ";
129  str << "Rxyz=";
130  for (int i = 0; i < 3; i++)
131  str << M.Rvec.ptr< float >(0)[i] << " ";
132 
133  return str;
134  }
135 
136 
137  //saves to a binary stream
138  void toStream(ostream &str)const;
139  //reads from a binary stream
140  void fromStream(istream &str);
141 
142  //returns the 3d points of a marker wrt its center
143  static vector<cv::Point3f> get3DPoints(float msize);
144  private:
145  void rotateXAxis(cv::Mat &rotation);
146 };
147 }
148 #endif
#define ARUCO_EXPORTS
Definition: exports.h:42
friend ostream & operator<<(ostream &str, const Marker &M)
Definition: marker.h:122
bool isValid() const
Definition: marker.h:68
cv::Mat Rvec
Definition: marker.h:49
bool operator==(const Marker &m) const
Definition: marker.h:116
TFSIMD_FORCE_INLINE const tfScalar & x() const
This class represents a marker. It is a vector of the fours corners ot the marker.
Definition: marker.h:42
Parameters of the camera.
float ssize
Definition: marker.h:47
cv::Mat Tvec
Definition: marker.h:49
friend bool operator<(const Marker &M1, const Marker &M2)
Definition: marker.h:119


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