Marker.h
Go to the documentation of this file.
1 /*
2  * This file is part of ALVAR, A Library for Virtual and Augmented Reality.
3  *
4  * Copyright 2007-2012 VTT Technical Research Centre of Finland
5  *
6  * Contact: VTT Augmented Reality Team <alvar.info@vtt.fi>
7  * <http://www.vtt.fi/multimedia/alvar.html>
8  *
9  * ALVAR is free software; you can redistribute it and/or modify it under the
10  * terms of the GNU Lesser General Public License as published by the Free
11  * Software Foundation; either version 2.1 of the License, or (at your option)
12  * any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17  * for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with ALVAR; if not, see
21  * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>.
22  */
23 
24 #ifndef MARKER_H
25 #define MARKER_H
26 
34 #include "Alvar.h"
35 #include <iostream>
36 #include <algorithm>
37 #include "Util.h"
38 #include "Camera.h"
39 #include "Pose.h"
40 #include "Bitset.h"
41 #include <vector>
43 #include <Eigen/StdVector>
44 
45 namespace alvar {
46 
53  {
54  protected:
55  void VisualizeMarkerPose(IplImage *image, Camera *cam, double visualize2d_points[12][2], CvScalar color=CV_RGB(255,0,0)) const;
56  virtual void VisualizeMarkerContent(IplImage *image, Camera *cam, double datatext_point[2], double content_point[2]) const;
57  virtual void VisualizeMarkerError(IplImage *image, Camera *cam, double errortext_point[2]) const;
58  bool UpdateContentBasic(std::vector<Point<CvPoint2D64f> > &_marker_corners_img, IplImage *gray, Camera *cam, int frame_no = 0);
59 
60  public:
61  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
62  bool valid;
63 
70  void CompareCorners(std::vector<Point<CvPoint2D64f> > &_marker_corners_img, int *orientation, double *error);
73  void CompareContent(std::vector<Point<CvPoint2D64f> > &_marker_corners_img, IplImage *gray, Camera *cam, int *orientation) const;
76  virtual bool UpdateContent(std::vector<Point<CvPoint2D64f> > &_marker_corners_img, IplImage *gray, Camera *cam, int frame_no = 0);
79  void UpdatePose(std::vector<Point<CvPoint2D64f> > &_marker_corners_img, Camera *cam, int orientation, int frame_no = 0, bool update_pose = true);
83  virtual bool DecodeContent(int *orientation);
84 
87  CvMat *GetContent() const {
88  return marker_content;
89  }
92  void SaveMarkerImage(const char *filename, int save_res = 0) const;
95  void ScaleMarkerToImage(IplImage *image) const;
98  void Visualize(IplImage *image, Camera *cam, CvScalar color=CV_RGB(255,0,0)) const;
100  void SetMarkerSize(double _edge_length = 0, int _res = 0, double _margin = 0);
102  double GetMarkerEdgeLength() const { return edge_length; }
104  ~Marker();
110  Marker(double _edge_length = 0, int _res = 0, double _margin = 0);
112  Marker(const Marker& m);
118  virtual unsigned long GetId() const { return 0; }
119  virtual void SetId(unsigned long _id) {};
120 
126  int GetRes() const { return res; }
127 
132  double GetMargin() const { return margin; }
133 
144  double GetError(int errors = (MARGIN_ERROR | DECODE_ERROR)) const {
145  int count = 0;
146  double error = 0;
147  if (errors & MARGIN_ERROR) {error+=margin_error; count++;}
148  if (errors & DECODE_ERROR) {error+=decode_error; count++;}
149  if (errors & TRACK_ERROR) {error+=track_error; count++;}
150  return error/count;
151  }
153  void SetError(int error_type, double value) {
154  if (error_type == MARGIN_ERROR) margin_error = value;
155  else if (error_type == DECODE_ERROR) decode_error = value;
156  else if (error_type == TRACK_ERROR) track_error = value;
157  }
158  static const int MARGIN_ERROR=1;
159  static const int DECODE_ERROR=2;
160  static const int TRACK_ERROR=4;
161  protected:
162  double margin_error;
163  double decode_error;
164  double track_error;
165  double edge_length;
166  int res;
167  double margin;
169 
170  public:
171 
173  std::vector<PointDouble> marker_points;
175  std::vector<PointDouble> marker_corners;
177  std::vector<PointDouble> marker_corners_img;
179  std::vector<PointDouble> ros_marker_points_img;
183  std::vector<PointDouble> marker_margin_w;
185  std::vector<PointDouble> marker_margin_b;
186 #ifdef VISUALIZE_MARKER_POINTS
187  std::vector<PointDouble> marker_allpoints_img;
188 #endif
189  };
190 
195  {
196  protected:
197  int default_res() { std::cout<<"MarkerArtoolkit::default_res"<<std::endl; return 3; }
198  double default_margin() { return 1.5; }
199 
200  public:
201  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
203  unsigned long id;
205  MarkerArtoolkit(double _edge_length = 0, int _res = 0, double _margin = 0) :
206  Marker(_edge_length, (_res?_res:3), (_margin?_margin:1.5))
207  {
208  }
210  unsigned long GetId() const { return id; }
211  void SetId(unsigned long _id) { id = _id; }
213  bool DecodeContent(int *orientation);
215  void SetContent(unsigned long _id);
216  };
217 
222  {
223  protected:
224  virtual void VisualizeMarkerContent(IplImage *image, Camera *cam, double datatext_point[2], double content_point[2]) const;
225  void DecodeOrientation(int *error, int *total, int *orientation);
226  int DecodeCode(int orientation, BitsetExt *bs, int *erroneous, int *total, unsigned char* content_type);
227  void Read6bitStr(BitsetExt *bs, char *s, size_t s_max_len);
228  void Add6bitStr(BitsetExt *bs, char *s);
229  int UsableDataBits(int marker_res, int hamming);
230  bool DetectResolution(std::vector<Point<CvPoint2D64f> > &_marker_corners_img, IplImage *gray, Camera *cam);
231 
232  public:
233  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
234  static const int MAX_MARKER_STRING_LEN=2048;
239  MARKER_CONTENT_TYPE_HTTP
240  };
241  unsigned char content_type;
242 
244  union {
245  unsigned long id;
246  char str[MAX_MARKER_STRING_LEN];
247  } data;
248 
254  MarkerData(double _edge_length = 0, int _res = 0, double _margin = 0) :
255  Marker(_edge_length, _res, (_margin?_margin:2))
256  {
257  }
259  unsigned long GetId() const { return data.id; }
261  void SetId(unsigned long _id) { data.id = _id; }
266  virtual bool UpdateContent(std::vector<Point<CvPoint2D64f> > &_marker_corners_img, IplImage *gray, Camera *cam, int frame_no = 0);
269  bool DecodeContent(int *orientation);
272  void SetContent(MarkerContentType content_type, unsigned long id, const char *str, bool force_strong_hamming=false, bool verbose=false);
273  };
274 
277  class ALVAR_EXPORT MarkerIterator : public std::iterator<std::forward_iterator_tag, Marker*> {
278  public:
279  virtual bool operator==(const MarkerIterator& other) = 0;
280  virtual bool operator!=(const MarkerIterator& other) = 0;
281  virtual MarkerIterator& operator++() = 0;
282  virtual const Marker* operator*() = 0;
283  virtual const Marker* operator->() = 0;
284  virtual MarkerIterator& reset() = 0;
285 
286  void *_data;
287  };
288 
293  template<typename T>
295  public:
296  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
297  typedef typename std::vector<T, Eigen::aligned_allocator<T> >::const_iterator const_iterator_aligntype;
298  MarkerIteratorImpl(const_iterator_aligntype i) : _begin(i), _i(i) {
299  _data = this;
300  }
301 
303 
304  // The assignment and relational operators are straightforward
306  _i = other._i;
307  return(*this);
308  }
309 
310  bool operator==(const MarkerIterator& other) {
311  MarkerIteratorImpl* pother = (MarkerIteratorImpl*)other._data;
312  return (_i == pother->_i);
313  }
314 
315  bool operator!=(const MarkerIterator& other) {
316  MarkerIteratorImpl* pother = (MarkerIteratorImpl*)other._data;
317  return (_i != pother->_i);
318  }
319 
321  _i++;
322  return(*this);
323  }
324 
325  const Marker* operator*() {
326  return &(*_i);
327  }
328 
329  const Marker* operator->() {
330  return &(*_i);
331  }
332 
334  _i = _begin;
335  return (*this);
336  }
337 
338  private:
339  const_iterator_aligntype _begin;
340  const_iterator_aligntype _i;
341  };
342 
343 } // namespace alvar
344 
345 #endif
Main ALVAR namespace.
Definition: Alvar.h:174
int ros_orientation
Definition: Marker.h:181
TFSIMD_FORCE_INLINE Vector3 operator*(const Matrix3x3 &m, const Vector3 &v)
int GetRes() const
Definition: Marker.h:126
const Marker * operator->()
Definition: Marker.h:329
filename
pcl::PointCloud< ARPoint > ARCloud
double default_margin()
Definition: Marker.h:198
unsigned char content_type
Definition: Marker.h:241
std::vector< PointDouble > marker_corners_img
Marker corners in image coordinates.
Definition: Marker.h:177
CvMat * GetContent() const
Returns the content as a matrix.
Definition: Marker.h:87
This file implements bit set handling.
This file implements a camera used for projecting points and computing homographies.
virtual unsigned long GetId() const
Get id for this marker This is used e.g. in MarkerDetector to associate a marker id with an appropria...
Definition: Marker.h:118
TFSIMD_FORCE_INLINE bool operator==(const Matrix3x3 &m1, const Matrix3x3 &m2)
unsigned long id
Definition: Marker.h:245
XmlRpcServer s
void SetError(int error_type, double value)
Set the marker error estimate.
Definition: Marker.h:153
const double margin
std::vector< PointDouble > marker_margin_w
Samples to be used in figuring out min/max for thresholding.
Definition: Marker.h:183
bool operator!=(const MarkerIterator &other)
Definition: Marker.h:315
unsigned char * image
Definition: GlutViewer.cpp:155
virtual void SetId(unsigned long _id)
Definition: Marker.h:119
MarkerData contains matrix of Hamming encoded data.
Definition: Marker.h:221
bool operator==(const MarkerIterator &other)
Definition: Marker.h:310
MarkerIterator & reset()
Definition: Marker.h:333
void SetId(unsigned long _id)
Set the ID.
Definition: Marker.h:261
Simple Camera class for calculating distortions, orientation or projections with pre-calibrated camer...
Definition: Camera.h:82
const_iterator_aligntype _begin
Definition: Marker.h:339
MarkerIterator & operator++()
Definition: Marker.h:320
double decode_error
Definition: Marker.h:163
unsigned long GetId() const
Get ID for recognizing this marker.
Definition: Marker.h:210
std::vector< PointDouble > marker_margin_b
Samples to be used in figuring out min/max for thresholding.
Definition: Marker.h:185
Pose pose
The current marker Pose.
Definition: Marker.h:136
MarkerIteratorImpl(const_iterator_aligntype i)
Definition: Marker.h:298
const_iterator_aligntype _i
Definition: Marker.h:340
double GetError(int errors=(MARGIN_ERROR|DECODE_ERROR)) const
Get marker detection error estimate.
Definition: Marker.h:144
MarkerArtoolkit(double _edge_length=0, int _res=0, double _margin=0)
Constructor.
Definition: Marker.h:205
Pose representation derived from the Rotation class
Definition: Pose.h:50
MarkerArtoolkit for using matrix markers similar with the ones used in ARToolkit. ...
Definition: Marker.h:194
EIGEN_MAKE_ALIGNED_OPERATOR_NEW bool valid
Definition: Marker.h:62
TFSIMD_FORCE_INLINE bool operator!=(const Vector3 &other) const
std::vector< PointDouble > ros_marker_points_img
Marker points in image coordinates.
Definition: Marker.h:179
Basic 2D Marker functionality.
Definition: Marker.h:52
cv::Mat gray
double track_error
Definition: Marker.h:164
unsigned long GetId() const
Get ID for recognizing this marker.
Definition: Marker.h:259
double edge_length
Definition: Marker.h:165
const Marker * operator*()
Definition: Marker.h:325
This file implements generic utility functions and a serialization interface.
Iterator type for traversing templated Marker vector without the template.
Definition: Marker.h:277
double GetMarkerEdgeLength() const
Get edge length (to support different size markers.
Definition: Marker.h:102
#define ALVAR_EXPORT
Definition: Alvar.h:168
std::vector< PointDouble > marker_points
Marker color points in marker coordinates.
Definition: Marker.h:173
CvMat * marker_content
Definition: Marker.h:168
Iterator implementation for traversing templated Marker vector without the template.
Definition: Marker.h:294
MarkerIteratorImpl & operator=(const MarkerIteratorImpl &other)
Definition: Marker.h:305
This file implements a pose.
MarkerData(double _edge_length=0, int _res=0, double _margin=0)
Default constructor.
Definition: Marker.h:254
Camera * cam
double margin_error
Definition: Marker.h:162
const int res
An extended Bitset ( BitsetExt ) for handling e.g. Hamming encoding/decoding.
Definition: Bitset.h:135
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef std::vector< T, Eigen::aligned_allocator< T > >::const_iterator const_iterator_aligntype
Definition: Marker.h:297
double GetMargin() const
Definition: Marker.h:132
double margin
Definition: Marker.h:167
This file defines library export definitions, version numbers and build information.
void SetId(unsigned long _id)
Definition: Marker.h:211
ar_track_alvar::ARCloud ros_corners_3D
Definition: Marker.h:180
EIGEN_MAKE_ALIGNED_OPERATOR_NEW unsigned long id
MarkerArtoolkit supports only &#39;id&#39; as data type
Definition: Marker.h:203
std::vector< PointDouble > marker_corners
Marker corners in marker coordinates.
Definition: Marker.h:175


ar_track_alvar
Author(s): Scott Niekum
autogenerated on Thu Jun 6 2019 19:27:24