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 #include <Eigen/StdVector>
00048
00049 namespace alvar {
00050
00054 class ALVAR_EXPORT MarkerDetectorImpl {
00055 protected:
00056 virtual Marker* new_M(double _edge_length = 0, int _res = 0, double _margin = 0) = 0;
00057 virtual void _markers_clear() = 0;
00058 virtual void _markers_push_back(Marker *mn) = 0;
00059 virtual size_t _markers_size() = 0;
00060 virtual void _track_markers_clear() = 0;
00061 virtual void _track_markers_push_back(Marker *mn) = 0;
00062 virtual size_t _track_markers_size() = 0;
00063 virtual Marker* _track_markers_at(size_t i) = 0;
00064 virtual void _swap_marker_tables() = 0;
00065
00066 Labeling* labeling;
00067
00068 std::map<unsigned long, double> map_edge_length;
00069 double edge_length;
00070 int res;
00071 double margin;
00072 bool detect_pose_grayscale;
00073
00074 MarkerDetectorImpl();
00075 virtual ~MarkerDetectorImpl();
00076
00077 public:
00079 void TrackMarkersReset();
00080
00087 void TrackMarkerAdd(int id, PointDouble corners[4]);
00088
00096 void SetMarkerSize(double _edge_length = 1, int _res = 5, double _margin = 2);
00097
00102 void SetMarkerSizeForId(unsigned long id, double _edge_length = 1);
00103
00107 void SetOptions(bool _detect_pose_grayscale=false);
00108
00122 int Detect(IplImage *image,
00123 Camera *cam,
00124 bool track=false,
00125 bool visualize=false,
00126 double max_new_marker_error=0.08,
00127 double max_track_error=0.2,
00128 LabelingMethod labeling_method=CVSEQ,
00129 bool update_pose=true);
00130
00131 int DetectAdditional(IplImage *image, Camera *cam, bool visualize=false, double max_track_error=0.2);
00132 };
00133
00138 template<class M>
00139 class ALVAR_EXPORT MarkerDetector : public MarkerDetectorImpl
00140 {
00141 protected:
00142 Marker* new_M(double _edge_length = 0, int _res = 0, double _margin = 0) {
00143 return new M(_edge_length, _res, _margin);
00144 }
00145
00146 void _markers_clear() { markers->clear(); }
00147 void _markers_push_back(Marker *mn) { markers->push_back(*((M*)mn)); }
00148 size_t _markers_size() { return markers->size(); }
00149 void _track_markers_clear() { track_markers->clear(); }
00150 void _track_markers_push_back(Marker *mn) { track_markers->push_back(*((M*)mn)); }
00151 size_t _track_markers_size() { return track_markers->size(); }
00152 Marker* _track_markers_at(size_t i) { return &track_markers->at(i); }
00153
00154 void _swap_marker_tables() {
00155 std::vector<M, Eigen::aligned_allocator<M> > *tmp_markers = markers;
00156 markers = track_markers;
00157 track_markers = tmp_markers;
00158 }
00159
00160 public:
00161
00162 std::vector<M, Eigen::aligned_allocator<M> > *markers;
00163 std::vector<M, Eigen::aligned_allocator<M> > *track_markers;
00164
00166 MarkerDetector() : MarkerDetectorImpl() {
00167 markers = new std::vector<M, Eigen::aligned_allocator<M> >;
00168 track_markers = new std::vector<M, Eigen::aligned_allocator<M> >;
00169 }
00170
00172 ~MarkerDetector() {
00173 delete markers;
00174 delete track_markers;
00175 }
00176 };
00177
00178 }
00179
00180 #endif