markermap.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_MarkerMap_h
29 #define _Aruco_MarkerMap_h
30 #include <opencv2/core/core.hpp>
31 #include <string>
32 #include <vector>
33 #include "exports.h"
34 #include "marker.h"
35 using namespace std;
36 namespace aruco {
40 struct ARUCO_EXPORTS Marker3DInfo : public vector< cv::Point3f > {
42  Marker3DInfo(int _id) { id = _id; }
43  bool operator==(const Marker3DInfo &MI) {return id==MI.id;}
44  int id; // maker id
45 
46  //returns the distance of the marker side
47  float getMarkerSize()const{return cv::norm(at(0)-at(1));}
48 public:
49  void toStream(std::ostream &str){str<<id<<" "<<size()<<" ";for(size_t i=0;i<size();i++) str<<at(i).x<<" "<<at(i).y<<" "<<at(i).z<<" ";}
50  void fromStream(std::istream &str){int s;str>>id>>s;resize(s);for(size_t i=0;i<size();i++) str>>at(i).x>>at(i).y>>at(i).z;}
51 
52 };
53 
71 class ARUCO_EXPORTS MarkerMap : public vector< Marker3DInfo > {
72 
73 
74 public:
75 
78  MarkerMap();
79 
83  MarkerMap(string filePath) throw(cv::Exception);
84 
87  bool isExpressedInMeters() const { return mInfoType == METERS; }
90  bool isExpressedInPixels() const { return mInfoType == PIX; }
93  MarkerMap convertToMeters( float markerSize)throw (cv::Exception);
94  //simple way of knowing which elements detected in an image are from this markermap
95  //returns the indices of the elements in the vector 'markers' that belong to this set
96  //Example: The set has the elements with ids 10,21,31,41,92
97  //The input vector has the markers with ids 10,88,9,12,41
98  //function returns {0,4}, because element 0 (10) of the vector belongs to the set, and also element 4 (41) belongs to the set
99  std::vector<int> getIndices(vector<aruco::Marker> &markers);
100 
103  const Marker3DInfo &getMarker3DInfo(int id) const throw(cv::Exception);
104 
107  int getIndexOfMarkerId(int id) const;
110  void getIdList(vector< int > &ids, bool append = true) const;
111 
112 
115  cv::Mat getImage(float METER2PIX=0)const throw (cv::Exception);
116 
117 
120  void saveToFile(string sfile) throw(cv::Exception);
123  void readFromFile(string sfile) throw(cv::Exception);
124 
125 
126 
127  //calculates the camera location w.r.t. the map using the information provided
128  //returns the <rvec,tvec>
129  pair<cv::Mat,cv::Mat> calculateExtrinsics(const std::vector<aruco::Marker> &markers ,float markerSize, cv::Mat CameraMatrix, cv::Mat Distorsion ) throw(cv::Exception);
130 
131  //returns string indicating the dictionary
132  std::string getDictionary()const{return dictionary;}
133 
134 
136  NONE = -1,
137  PIX = 0,
138  METERS = 1
139  }; // indicates if the data in MakersInfo is expressed in meters or in pixels so as to do conversion internally
140  //returns string indicating the dictionary
141  void setDictionary(std::string d){dictionary=d;}
142 
143 
144  // variable indicates if the data in MakersInfo is expressed in meters or in pixels so as to do conversion internally
146 private:
147  //dictionary it belongs to (if any)
148  std::string dictionary;
149 
150 
151 private:
154  void saveToFile(cv::FileStorage &fs) throw(cv::Exception);
157  void readFromFile(cv::FileStorage &fs) throw(cv::Exception);
158 public:
159  void toStream(std::ostream &str);
160  void fromStream(std::istream &str);
161 };
162 
163 }
164 
165 #endif
#define ARUCO_EXPORTS
Definition: exports.h:42
void toStream(std::ostream &str)
Definition: markermap.h:49
NONE
bool isExpressedInPixels() const
Definition: markermap.h:90
bool isExpressedInMeters() const
Definition: markermap.h:87
XmlRpcServer s
std::string dictionary
Definition: markermap.h:148
bool operator==(const Marker3DInfo &MI)
Definition: markermap.h:43
std::string getDictionary() const
Definition: markermap.h:132
Marker3DInfo(int _id)
Definition: markermap.h:42
ROSCPP_DECL std::string append(const std::string &left, const std::string &right)
float getMarkerSize() const
Definition: markermap.h:47
void fromStream(std::istream &str)
Definition: markermap.h:50
This class defines a set of markers whose locations are attached to a common reference system...
Definition: markermap.h:71
void setDictionary(std::string d)
Definition: markermap.h:141


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