My Project
MarkerDetector.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_DETECTOR_H
25 #define MARKER_DETECTOR_H
26 
33 #include "Alvar.h"
34 #include "Camera.h"
35 #include "ConnectedComponents.h"
36 #include "Draw.h"
37 #include "Line.h"
38 #include "Marker.h"
39 #include "Rotation.h"
40 #include "Util.h"
41 
42 #include <algorithm>
43 using std::rotate;
44 #include <cassert>
45 #include <list>
46 #include <map>
47 #include <vector>
48 
49 namespace alvar {
50 
54 class ALVAR_EXPORT MarkerDetectorImpl
55 {
56 protected:
57  virtual Marker *new_M(double _edge_length = 0, int _res = 0, double _margin = 0) = 0;
58  virtual void _markers_clear() = 0;
59  virtual void _markers_push_back(Marker *mn) = 0;
60  virtual size_t _markers_size() = 0;
61  virtual void _track_markers_clear() = 0;
62  virtual void _track_markers_push_back(Marker *mn) = 0;
63  virtual size_t _track_markers_size() = 0;
64  virtual Marker *_track_markers_at(size_t i) = 0;
65  virtual void _swap_marker_tables() = 0;
66 
67  Labeling *labeling;
68 
69  std::map<unsigned long, double> map_edge_length;
70  double edge_length;
71  int res;
72  double margin;
73  bool detect_pose_grayscale;
74 
76  virtual ~MarkerDetectorImpl();
77 
78 public:
81 
88  void TrackMarkerAdd(int id, PointDouble corners[4]);
89 
97  void SetMarkerSize(double _edge_length = 1, int _res = 5, double _margin = 2);
98 
103  void SetMarkerSizeForId(unsigned long id, double _edge_length = 1);
104 
108  void SetOptions(bool _detect_pose_grayscale = false);
109 
123  int Detect(cv::Mat & image,
124  Camera * cam,
125  bool track = false,
126  bool visualize = false,
127  double max_new_marker_error = 0.08,
128  double max_track_error = 0.2,
129  LabelingMethod labeling_method = CVSEQ,
130  bool update_pose = true);
131 
132  int DetectAdditional(cv::Mat &image,
133  Camera * cam,
134  bool visualize = false,
135  double max_track_error = 0.2);
136 };
137 
142 template <class M>
143 class ALVAR_EXPORT MarkerDetector : public MarkerDetectorImpl
144 {
145 protected:
146  Marker *
147  new_M(double _edge_length = 0, int _res = 0, double _margin = 0)
148  {
149  return new M(_edge_length, _res, _margin);
150  }
151 
152  void
153  _markers_clear()
154  {
155  markers->clear();
156  }
157  void
158  _markers_push_back(Marker *mn)
159  {
160  markers->push_back(*((M *)mn));
161  }
162  size_t
163  _markers_size()
164  {
165  return markers->size();
166  }
167  void
168  _track_markers_clear()
169  {
170  track_markers->clear();
171  }
172  void
173  _track_markers_push_back(Marker *mn)
174  {
175  track_markers->push_back(*((M *)mn));
176  }
177  size_t
178  _track_markers_size()
179  {
180  return track_markers->size();
181  }
182  Marker *
183  _track_markers_at(size_t i)
184  {
185  return &track_markers->at(i);
186  }
187 
188  void
189  _swap_marker_tables()
190  {
191  std::vector<M> *tmp_markers = markers;
192  markers = track_markers;
193  track_markers = tmp_markers;
194  }
195 
196 public:
197  std::vector<M> *markers;
198  std::vector<M> *track_markers;
199 
202  {
203  markers = new std::vector<M>;
204  track_markers = new std::vector<M>;
205  }
206 
209  {
210  delete markers;
211  delete track_markers;
212  }
213 };
214 
215 } // namespace alvar
216 
217 #endif
This file defines library export definitions, version numbers and build information.
This file implements a camera used for projecting points and computing homographies.
This file implements connected component labeling.
This file implements a collection of functions that are used to visualize lines, contours and corners...
This file implements a parametrized line.
This file implements a marker interface as well as ALVAR markers and ARToolKit markers.
This file implements a parametrized rotation.
This file implements generic utility functions and a serialization interface.
Simple Camera class for calculating distortions, orientation or projections with pre-calibrated camer...
Definition: Camera.h:82
Base class for labeling connected components from binary image.
MarkerDetector for detecting markers of type M
Templateless version of MarkerDetector. Please use MarkerDetector instead.
void SetOptions(bool _detect_pose_grayscale=false)
void SetMarkerSize(double _edge_length=1, int _res=5, double _margin=2)
void TrackMarkersReset()
Clear the markers that are tracked.
void SetMarkerSizeForId(unsigned long id, double _edge_length=1)
int Detect(cv::Mat &image, Camera *cam, bool track=false, bool visualize=false, double max_new_marker_error=0.08, double max_track_error=0.2, LabelingMethod labeling_method=CVSEQ, bool update_pose=true)
Detect Marker 's from image
void TrackMarkerAdd(int id, PointDouble corners[4])
Add markers to be tracked Sometimes application or e.g. the MultiMarker implementation knows more abo...
Basic 2D Marker functionality.
Definition: Marker.h:53
Main ALVAR namespace.
Definition: Alvar.h:174
ALVAR_EXPORT Point< cv::Point2d > PointDouble
The default double point type.
Definition: Util.h:110