Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef MARKER_DETECTOR_H
00025 #define MARKER_DETECTOR_H
00026
00033 #include "Alvar.h"
00034 #include "Util.h"
00035 #include "ConnectedComponents.h"
00036 #include "Draw.h"
00037 #include "Camera.h"
00038 #include "Marker.h"
00039 #include "Rotation.h"
00040 #include "Line.h"
00041 #include <algorithm>
00042 using std::rotate;
00043 #include <list>
00044 #include <vector>
00045 #include <map>
00046 #include <cassert>
00047
00048 namespace alvar {
00049
00053 class ALVAR_EXPORT MarkerDetectorImpl {
00054 protected:
00055 virtual Marker* new_M(double _edge_length = 0, int _res = 0, double _margin = 0) = 0;
00056 virtual void _markers_clear() = 0;
00057 virtual void _markers_push_back(Marker *mn) = 0;
00058 virtual size_t _markers_size() = 0;
00059 virtual void _track_markers_clear() = 0;
00060 virtual void _track_markers_push_back(Marker *mn) = 0;
00061 virtual size_t _track_markers_size() = 0;
00062 virtual Marker* _track_markers_at(size_t i) = 0;
00063 virtual void _swap_marker_tables() = 0;
00064
00065 Labeling* labeling;
00066
00067 std::map<unsigned long, double> map_edge_length;
00068 double edge_length;
00069 int res;
00070 double margin;
00071 bool detect_pose_grayscale;
00072
00073 MarkerDetectorImpl();
00074 virtual ~MarkerDetectorImpl();
00075
00076 public:
00078 void TrackMarkersReset();
00079
00086 void TrackMarkerAdd(int id, PointDouble corners[4]);
00087
00095 void SetMarkerSize(double _edge_length = 1, int _res = 5, double _margin = 2);
00096
00101 void SetMarkerSizeForId(unsigned long id, double _edge_length = 1);
00102
00106 void SetOptions(bool _detect_pose_grayscale=false);
00107
00121 int Detect(IplImage *image,
00122 Camera *cam,
00123 bool track=false,
00124 bool visualize=false,
00125 double max_new_marker_error=0.08,
00126 double max_track_error=0.2,
00127 LabelingMethod labeling_method=CVSEQ,
00128 bool update_pose=true);
00129
00130 int DetectAdditional(IplImage *image, Camera *cam, bool visualize=false, double max_track_error=0.2);
00131 };
00132
00137 template<class M>
00138 class ALVAR_EXPORT MarkerDetector : public MarkerDetectorImpl
00139 {
00140 protected:
00141 Marker* new_M(double _edge_length = 0, int _res = 0, double _margin = 0) {
00142 return new M(_edge_length, _res, _margin);
00143 }
00144
00145 void _markers_clear() { markers->clear(); }
00146 void _markers_push_back(Marker *mn) { markers->push_back(*((M*)mn)); }
00147 size_t _markers_size() { return markers->size(); }
00148 void _track_markers_clear() { track_markers->clear(); }
00149 void _track_markers_push_back(Marker *mn) { track_markers->push_back(*((M*)mn)); }
00150 size_t _track_markers_size() { return track_markers->size(); }
00151 Marker* _track_markers_at(size_t i) { return &track_markers->at(i); }
00152
00153 void _swap_marker_tables() {
00154 std::vector<M> *tmp_markers = markers;
00155 markers = track_markers;
00156 track_markers = tmp_markers;
00157 }
00158
00159 public:
00160
00161 std::vector<M> *markers;
00162 std::vector<M> *track_markers;
00163
00165 MarkerDetector() : MarkerDetectorImpl() {
00166 markers = new std::vector<M>;
00167 track_markers = new std::vector<M>;
00168 }
00169
00171 ~MarkerDetector() {
00172 delete markers;
00173 delete track_markers;
00174 }
00175 };
00176
00177 }
00178
00179 #endif