My Project
SfM.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 SFM_H
25 #define SFM_H
26 
33 #include "EC.h"
34 
35 namespace alvar {
36 
41 class ALVAR_EXPORT SimpleSfM
42 {
43 public:
45  class Feature : public ExternalContainer
46  {
47  public:
48  bool has_stored_pose;
49  Pose pose1;
50  cv::Point2f p2d1;
51  cv::Point3f p3d_sh;
52  cv::Point2f projected_p2d_sh;
53  int tri_cntr; // This is needed only by UpdateTriangulateOnly
54  int estimation_type;
55 
57  {
58  has_stored_pose = false;
59  p3d_sh.x = 0.f;
60  p3d_sh.y = 0.f;
61  p3d_sh.z = 0.f;
62  tri_cntr = 0;
63  estimation_type = 0;
64  }
65  Feature(const Feature &c) : ExternalContainer(c)
66  {
67  has_stored_pose = c.has_stored_pose;
68  pose1 = c.pose1;
69  p2d1 = c.p2d1;
70  p3d_sh = c.p3d_sh;
71  projected_p2d_sh = c.projected_p2d_sh;
72  tri_cntr = c.tri_cntr;
73  estimation_type = c.estimation_type;
74  }
75  };
77  std::map<int, Feature> container;
78  std::map<int, Feature> container_triangulated;
79 
80 protected:
81  std::map<int, Feature> container_reset_point;
82  std::map<int, Feature> container_triangulated_reset_point;
83 
84  CameraEC cam;
85  MarkerDetectorEC<MarkerData> marker_detector;
87  Pose pose;
88  bool pose_ok;
89 
90  bool update_tri;
91  std::string multi_marker_file;
92  bool markers_found;
93  double scale;
94  Pose pose_original;
95  Pose pose_difference;
96 
97 public:
100  : tf(200, 200, 0.01, 20, 4, 6), pose_ok(false), update_tri(false), markers_found(false)
101  {
102  }
104  void Reset(bool reset_also_triangulated = true);
108  void Clear();
110  void
111  SetScale(double s)
112  {
113  scale = s;
114  }
120  bool AddMultiMarker(const char *fname, FILE_FORMAT format = FILE_FORMAT_XML);
124  void AddMarker(int marker_id, double edge_length, Pose &pose);
126  bool Update(cv::Mat &image,
127  bool assume_plane = true,
128  bool triangulate = true,
129  float reproj_err_limit = 5.f,
130  float triangulate_angle = 15.f);
132  bool UpdateTriangulateOnly(cv::Mat &image);
134  bool UpdateRotationsOnly(cv::Mat &image);
136  void Draw(cv::Mat &rgba);
137 };
138 
139 } // namespace alvar
140 #endif
This file implements a collection of External Container (EC) versions of many ALVAR classes.
Version of Camera using external container.
Definition: EC.h:492
Basic structure to be usable with EC methods.
Definition: EC.h:153
Version of MarkerDetector using external container.
Definition: EC.h:836
Version of MultiMarker using external container.
Definition: EC.h:959
Pose representation derived from the Rotation class
Definition: Pose.h:53
Extended version of ExternalContainer structure used internally in SimpleSfM.
Definition: SfM.h:46
Simple structure from motion implementation using CameraEC , MarkerDetectorEC and TrackerFeaturesEC.
Definition: SfM.h:42
bool Update(cv::Mat &image, bool assume_plane=true, bool triangulate=true, float reproj_err_limit=5.f, float triangulate_angle=15.f)
Update position assuming that camera is moving with 6-DOF.
std::map< int, Feature > container
The map of all tracked features.
Definition: SfM.h:77
bool UpdateRotationsOnly(cv::Mat &image)
Update position assuming that user is more standing still and viewing the environment.
bool UpdateTriangulateOnly(cv::Mat &image)
Update camera 6-DOF position using triangulated points only (This is the old version of Update)
void SetScale(double s)
Set the suitable scale to be used. This affects quite much how the tracking behaves (when features ar...
Definition: SfM.h:111
void AddMarker(int marker_id, double edge_length, Pose &pose)
Add an marker to be a basis for tracking. It is good idea to call SetResetPoint after these.
Pose * GetPose()
Get the estimated pose.
bool AddMultiMarker(MultiMarkerEC *mm)
Add MultiMarker to be a basis for tracking. It is good idea to call SetResetPoint after these.
CameraEC * GetCamera()
Get the camera used internally. You need to use this to set correct camera calibration (see SamplePoi...
void SetResetPoint()
Remember the current state and return here when the Reset is called.
void Draw(cv::Mat &rgba)
Draw debug information about the tracked features and detected markers.
void Clear()
Clear all tracked features.
void Reset(bool reset_also_triangulated=true)
Reset the situation back to the point it was when SetResetPoint was called.
SimpleSfM()
Constructor.
Definition: SfM.h:99
bool AddMultiMarker(const char *fname, FILE_FORMAT format=FILE_FORMAT_XML)
Add MultiMarker from file as a basis for tracking. It is good idea to call SetResetPoint after these.
Version of TrackerFeatures using external container.
Definition: EC.h:292
Main ALVAR namespace.
Definition: Alvar.h:174
FILE_FORMAT
Definition: FileFormat.h:39
@ FILE_FORMAT_XML
XML file format.
Definition: FileFormat.h:66