33 MarkerDetectorImpl::MarkerDetectorImpl() {
39 MarkerDetectorImpl::~MarkerDetectorImpl() {
40 if (labeling)
delete labeling;
43 void MarkerDetectorImpl::TrackMarkersReset() {
44 _track_markers_clear();
47 void MarkerDetectorImpl::TrackMarkerAdd(
int id,
PointDouble corners[4]) {
49 if (map_edge_length.find(
id) != map_edge_length.end()) {
59 _track_markers_push_back(mn);
63 void MarkerDetectorImpl::SetMarkerSize(
double _edge_length,
int _res,
double _margin) {
64 edge_length = _edge_length;
67 map_edge_length.clear();
70 void MarkerDetectorImpl::SetMarkerSizeForId(
unsigned long id,
double _edge_length) {
71 map_edge_length[id] = _edge_length;
74 void MarkerDetectorImpl::SetOptions(
bool _detect_pose_grayscale) {
75 detect_pose_grayscale = _detect_pose_grayscale;
78 int MarkerDetectorImpl::Detect(IplImage *
image,
84 LabelingMethod labeling_method,
87 assert(image->origin == 0);
91 _swap_marker_tables();
94 switch(labeling_method)
100 ((
LabelingCvSeq*)labeling)->SetOptions(detect_pose_grayscale);
104 labeling->SetCamera(cam);
105 labeling->LabelSquares(image, visualize);
106 vector<vector<PointDouble> >& blob_corners = labeling->blob_corners;
107 IplImage*
gray = labeling->gray;
113 for (
size_t ii=0; ii<_track_markers_size(); ii++) {
114 Marker *mn = _track_markers_at(ii);
115 if (mn->
GetError(Marker::DECODE_ERROR|Marker::MARGIN_ERROR) > 0)
continue;
117 int track_orientation=0;
118 double track_error=1e200;
119 for(
unsigned i = 0; i < blob_corners.size(); ++i) {
120 if (blob_corners[i].empty())
continue;
122 if (error < track_error) {
124 track_orientation = orientation;
128 if (track_error <= max_track_error) {
129 mn->
SetError(Marker::DECODE_ERROR, 0);
130 mn->
SetError(Marker::MARGIN_ERROR, 0);
131 mn->
SetError(Marker::TRACK_ERROR, track_error);
133 mn->
UpdatePose(blob_corners[track_i], cam, track_orientation, update_pose);
134 _markers_push_back(mn);
135 blob_corners[track_i].clear();
136 if (visualize) mn->
Visualize(image, cam, CV_RGB(255,255,0));
142 for(
size_t i = 0; i < blob_corners.size(); ++i)
144 if (blob_corners[i].empty())
continue;
152 if (map_edge_length.find(mn->
GetId()) != map_edge_length.end()) {
155 mn->
UpdatePose(blob_corners[i], cam, orientation, update_pose);
157 _markers_push_back(mn);
159 if (visualize) mn->
Visualize(image, cam, CV_RGB(255,0,0));
165 return (
int) _markers_size();
170 assert(image->origin == 0);
171 if(!labeling)
return -1;
175 vector<vector<PointDouble> >& blob_corners = labeling->blob_corners;
177 for (
size_t ii=0; ii<_track_markers_size(); ii++) {
178 Marker *mn = _track_markers_at(ii);
179 if (mn->
GetError(Marker::DECODE_ERROR|Marker::MARGIN_ERROR) > 0)
continue;
181 int track_orientation=0;
182 double track_error=1e200;
183 for(
unsigned i = 0; i < blob_corners.size(); ++i) {
184 if (blob_corners[i].empty())
continue;
186 if (error < track_error) {
188 track_orientation = orientation;
192 if (track_error <= max_track_error) {
193 mn->
SetError(Marker::DECODE_ERROR, 0);
194 mn->
SetError(Marker::MARGIN_ERROR, 0);
195 mn->
SetError(Marker::TRACK_ERROR, track_error);
196 mn->
UpdatePose(blob_corners[track_i], cam, track_orientation);
197 _markers_push_back(mn);
199 blob_corners[track_i].clear();
202 mn->
Visualize(image, cam, CV_RGB(0,255,255));
double max_new_marker_error
std::vector< PointDouble > marker_corners_img
Marker corners in image coordinates.
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...
virtual bool UpdateContent(std::vector< Point< CvPoint2D64f > > &_marker_corners_img, IplImage *gray, Camera *cam, int frame_no=0)
Updates the marker_content from the image using Homography.
void SetError(int error_type, double value)
Set the marker error estimate.
void Visualize(IplImage *image, Camera *cam, CvScalar color=CV_RGB(255, 0, 0)) const
Visualize the marker.
This file implements a generic marker detector.
virtual void SetId(unsigned long _id)
virtual bool DecodeContent(int *orientation)
Decodes the marker content. Please call UpdateContent before this. This virtual method is meant to be...
Simple Camera class for calculating distortions, orientation or projections with pre-calibrated camer...
MarkerDetector for detecting markers of type M
double GetError(int errors=(MARGIN_ERROR|DECODE_ERROR)) const
Get marker detection error estimate.
void UpdatePose(std::vector< Point< CvPoint2D64f > > &_marker_corners_img, Camera *cam, int orientation, int frame_no=0, bool update_pose=true)
Updates the markers pose estimation.
Basic 2D Marker functionality.
void CompareCorners(std::vector< Point< CvPoint2D64f > > &_marker_corners_img, int *orientation, double *error)
Compares the marker corners with the previous match.
ALVAR_EXPORT Point< CvPoint2D64f > PointDouble
The default double point type.
void SetMarkerSize(double _edge_length=0, int _res=0, double _margin=0)
Method for resizing the marker dimensions.
Labeling class that uses OpenCV routines to find connected components.