My Project
MultiMarker.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 MULTIMARKER_H
25 #define MULTIMARKER_H
26 
33 #include "Alvar.h"
34 #include "Camera.h"
35 #include "FileFormat.h"
36 #include "Filter.h"
37 #include "MarkerDetector.h"
38 #include "Rotation.h"
39 
40 #include <eigen3/Eigen/Dense>
41 
42 namespace alvar {
43 
47 class ALVAR_EXPORT MultiMarker
48 {
49 protected:
50  // The marker information is stored in all three tables using
51  // the indices-order given in constructor.
52  // One idea is that the same 'pointcloud' could contain feature
53  // points after marker-corner-points. This way they would be
54  // optimized simultaneously with marker corners...
55  std::map<int, cv::Point3d> pointcloud;
56  std::vector<int>
57  marker_indices; // The marker id's to be used in marker field (first being the base)
58  std::vector<int> marker_status; // 0: not in point cloud, 1: in point cloud, 2: used in GetPose()
59 
60  int pointcloud_index(int marker_id, int marker_corner, bool add_if_missing = false);
61  int get_id_index(int id, bool add_if_missing = false);
62 
63  double
64  _GetPose(MarkerIterator &begin, MarkerIterator &end, Camera *cam, Pose &pose, cv::Mat &image);
65 
66  double
67  _GetPose(MarkerIterator &begin, MarkerIterator &end, Camera *cam, Pose &pose)
68  {
69  cv::Mat empty_img;
70  return _GetPose(begin, end, cam, pose, empty_img);
71  }
72 
73  int
74  _SetTrackMarkers(MarkerDetectorImpl &marker_detector, Camera *cam, Pose &pose, cv::Mat &image);
75 
76 private:
77  bool SaveXML(const char *fname);
78  bool SaveText(const char *fname);
79  bool LoadText(const char *fname);
80  bool LoadXML(const char *fname);
81 
82 public:
84  virtual void Reset();
85 
90  bool Save(const char *fname, FILE_FORMAT format = FILE_FORMAT_DEFAULT);
91 
96  bool Load(const char *fname, FILE_FORMAT format = FILE_FORMAT_DEFAULT);
97 
101  MultiMarker(std::vector<int> &indices);
102 
105  {
106  }
107 
116  template <class M>
117  double
118  GetPose(const std::vector<M> *markers, Camera *cam, Pose &pose, cv::Mat &image)
119  {
120  MarkerIteratorImpl<M> begin(markers->begin());
121  MarkerIteratorImpl<M> end(markers->end());
122  return _GetPose(begin, end, cam, pose, image);
123  }
124 
125  template <class M>
126  double
127  GetPose(const std::vector<M> *markers, Camera *cam, Pose &pose)
128  {
129  MarkerIteratorImpl<M> begin(markers->begin());
130  MarkerIteratorImpl<M> end(markers->end());
131  return _GetPose(begin, end, cam, pose);
132  }
135  template <class M>
136  double
137  Update(const std::vector<M> *markers, Camera *cam, Pose &pose, cv::Mat &image)
138  {
139  if (markers->size() < 1)
140  return -1.0;
141 
142  return GetPose(markers, cam, pose, image);
143  }
144 
145  template <class M>
146  double
147  Update(const std::vector<M> *markers, Camera *cam, Pose &pose)
148  {
149  if (markers->size() < 1)
150  return -1.0;
151 
152  return GetPose(markers, cam, pose);
153  }
154 
158 
165  void PointCloudCorners3d(double edge_length, Pose &pose, cv::Point3d corners[4]);
166 
172  void PointCloudAdd(int marker_id, double edge_length, Pose &pose);
173 
176  void PointCloudCopy(const MultiMarker *m);
177 
180  bool
182  {
183  return pointcloud.empty();
184  }
185 
187  size_t
189  {
190  return marker_indices.size();
191  }
192 
200  void PointCloudGet(int marker_id, int point, double &x, double &y, double &z);
201 
205  bool IsValidMarker(int marker_id);
206 
213  template <class M>
214  int
215  SetTrackMarkers(MarkerDetector<M> &marker_detector, Camera *cam, Pose &pose, cv::Mat &image)
216  {
217  return _SetTrackMarkers(marker_detector, cam, pose, image);
218  }
219 };
220 
221 } // namespace alvar
222 
223 #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 defines various file formats.
This file implements multiple filters.
This file implements a generic marker detector.
This file implements a parametrized rotation.
Simple Camera class for calculating distortions, orientation or projections with pre-calibrated camer...
Definition: Camera.h:82
MarkerDetector for detecting markers of type M
Templateless version of MarkerDetector. Please use MarkerDetector instead.
Iterator type for traversing templated Marker vector without the template.
Definition: Marker.h:365
Iterator implementation for traversing templated Marker vector without the template.
Definition: Marker.h:383
Base class for using MultiMarker.
Definition: MultiMarker.h:48
double GetPose(const std::vector< M > *markers, Camera *cam, Pose &pose, cv::Mat &image)
Calculates the pose of the camera from multi marker. Method uses the true 3D coordinates of markers t...
Definition: MultiMarker.h:118
double Update(const std::vector< M > *markers, Camera *cam, Pose &pose, cv::Mat &image)
Calls GetPose to obtain camera pose.
Definition: MultiMarker.h:137
void PointCloudReset()
Reserts the 3D point cloud of the markers.
void PointCloudCopy(const MultiMarker *m)
Copies the 3D point cloud from other multi marker object.
bool IsValidMarker(int marker_id)
Returns true if the marker is in the point cloud.
virtual void Reset()
Resets the multi marker.
size_t Size()
Return the number of markers added using PointCloudAdd.
Definition: MultiMarker.h:188
void PointCloudGet(int marker_id, int point, double &x, double &y, double &z)
Returns 3D co-ordinates of one corner point of a marker.
void PointCloudAdd(int marker_id, double edge_length, Pose &pose)
Adds marker corners to 3D point cloud of multi marker.
bool Save(const char *fname, FILE_FORMAT format=FILE_FORMAT_DEFAULT)
Saves multi marker configuration to a text file.
int SetTrackMarkers(MarkerDetector< M > &marker_detector, Camera *cam, Pose &pose, cv::Mat &image)
Set new markers to be tracked for MarkerDetector Sometimes the MultiMarker implementation knows more ...
Definition: MultiMarker.h:215
bool Load(const char *fname, FILE_FORMAT format=FILE_FORMAT_DEFAULT)
Loads multi marker configuration from a text file.
MultiMarker(std::vector< int > &indices)
Constructor.
bool PointCloudIsEmpty()
Returns true if the are not points in the 3D opint cloud.
Definition: MultiMarker.h:181
MultiMarker()
Default constructor.
Definition: MultiMarker.h:104
void PointCloudCorners3d(double edge_length, Pose &pose, cv::Point3d corners[4])
Calculates 3D coordinates of marker corners relative to given pose (camera).
Pose representation derived from the Rotation class
Definition: Pose.h:53
Main ALVAR namespace.
Definition: Alvar.h:174
FILE_FORMAT
Definition: FileFormat.h:39
@ FILE_FORMAT_DEFAULT
Default file format.
Definition: FileFormat.h:45