Tracker.h
Go to the documentation of this file.
00001 //-*- C++ -*-
00002 // Copyright 2008 Isis Innovation Limited
00003 // 
00004 // This header declares the Tracker class.
00005 // The Tracker is one of main components of the system,
00006 // and is responsible for determining the pose of a camera
00007 // from a video feed. It uses the Map to track, and communicates 
00008 // with the MapMaker (which runs in a different thread)
00009 // to help construct this map.
00010 //
00011 // Initially there is no map, so the Tracker also has a mode to 
00012 // do simple patch tracking across a stereo pair. This is handled 
00013 // by the TrackForInitialMap() method and associated sub-methods. 
00014 // Once there is a map, TrackMap() is used.
00015 //
00016 // Externally, the tracker should be used by calling TrackFrame()
00017 // with every new input video frame. This then calls either 
00018 // TrackForInitialMap() or TrackMap() as appropriate.
00019 //
00020 
00021 #ifndef __TRACKER_H
00022 #define __TRACKER_H
00023 
00024 #include "MapMaker.h"
00025 #include "ATANCamera.h"
00026 #include "MiniPatch.h"
00027 #include "Relocaliser.h"
00028 #include "ptam/Params.h"
00029 
00030 #include <sstream>
00031 #include <vector>
00032 #include <list>
00033 
00034 struct TrackerData;
00035 struct Trail    // This struct is used for initial correspondences of the first stereo pair.
00036 {
00037   MiniPatch mPatch;
00038   CVD::ImageRef irCurrentPos;
00039   CVD::ImageRef irInitialPos;
00040 };
00041 
00042 class Tracker
00043 {
00044 public:
00045   Tracker(CVD::ImageRef irVideoSize, const ATANCamera &c, Map &m, MapMaker &mm);
00046 
00047   // TrackFrame is the main working part of the tracker: call this every frame.
00048   void TrackFrame(CVD::Image<CVD::byte> &imFrame, bool bDraw); 
00049   void TrackFrame(CVD::Image<CVD::byte> &imFrame, bool bDraw, const TooN::SO3<double> & imuOrientation);
00050 
00051   inline SE3<> GetCurrentPose() { return mse3CamFromWorld;}
00052   //Weiss{
00053   inline Matrix<6> GetCurrentCov() { return mmCovariances;}
00054   inline KeyFrame::Ptr GetCurrentKF() { return mCurrentKF;}
00055   Vector<3> CalcSBIRotation(SmallBlurryImage *SBI1, SmallBlurryImage *SBI2);
00056   //}
00057   // Gets messages to be printed on-screen for the user.
00058   std::string GetMessageForUser();
00059   int getTrackingQuality(){return mTrackingQuality;}
00060 
00061   void command(const std::string & params);
00062   std::list<Trail> & getTrails(){return  mlTrails;};
00063   bool getTrailTrackingStarted(){return mnInitialStage == TRAIL_TRACKING_STARTED;};
00064   bool getTrailTrackingComplete(){return mnInitialStage == TRAIL_TRACKING_COMPLETE;};
00065   CVD::Image<TooN::Vector<2> > & ComputeGrid();             // Computes the reference grid;
00066 
00067 protected:
00068   CVD::Image<TooN::Vector<2> > mProjVertices;
00069   KeyFrame::Ptr mCurrentKF;            // The current working frame as a keyframe struct
00070 
00071   // The major components to which the tracker needs access:
00072   Map &mMap;                      // The map, consisting of points and keyframes
00073   MapMaker &mMapMaker;            // The class which maintains the map
00074   ATANCamera mCamera;             // Projection model
00075   Relocaliser mRelocaliser;       // Relocalisation module
00076 
00077   CVD::ImageRef mirSize;          // Image size of whole image
00078 
00079   void Reset();                   // Restart from scratch. Also tells the mapmaker to reset itself.
00080   void RenderGrid();              // Draws the reference grid
00081 
00082   // The following members are used for initial map tracking (to get the first stereo pair and correspondences):
00083   void TrackForInitialMap();      // This is called by TrackFrame if there is not a map yet.
00084   enum {TRAIL_TRACKING_NOT_STARTED, 
00085     TRAIL_TRACKING_STARTED,
00086     TRAIL_TRACKING_COMPLETE} mnInitialStage;  // How far are we towards making the initial map?
00087     void TrailTracking_Start();     // First frame of initial trail tracking. Called by TrackForInitialMap.
00088     int  TrailTracking_Advance();   // Steady-state of initial trail tracking. Called by TrackForInitialMap.
00089     std::list<Trail> mlTrails;      // Used by trail tracking
00090     KeyFrame::Ptr mFirstKF;              // First of the stereo pair
00091     KeyFrame::Ptr mPreviousFrameKF;      // Used by trail tracking to check married matches
00092 
00093     // Methods for tracking the map once it has been made:
00094     void TrackMap();                // Called by TrackFrame if there is a map.
00095     void AssessTrackingQuality();   // Heuristics to choose between good, poor, bad.
00096     void ApplyMotionModel();        // Decaying velocity motion model applied prior to TrackMap
00097     void UpdateMotionModel();       // Motion model is updated after TrackMap
00098     int SearchForPoints(std::vector<TrackerData*> &vTD,
00099                         int nRange,
00100                         int nFineIts);  // Finds points in the image
00101     Vector<6> CalcPoseUpdate(std::vector<TrackerData*> vTD,
00102                              double dOverrideSigma = 0.0,
00103                              bool bMarkOutliers = false); // Updates pose from found points.
00104     SE3<> mse3CamFromWorld;           // Camera pose: this is what the tracker updates every frame.
00105     SE3<> mse3StartPos;               // What the camera pose was at the start of the frame.
00106     Vector<6> mv6CameraVelocity;    // Motion model
00107     double mdVelocityMagnitude;     // Used to decide on coarse tracking
00108     double mdMSDScaledVelocityMagnitude; // Velocity magnitude scaled by relative scene depth.
00109     bool mbDidCoarse;               // Did tracking use the coarse tracking stage?
00110 
00111     bool mbDraw;                    // Should the tracker draw anything to OpenGL?
00112 
00113     // achtelik{
00114     SO3<> mso3CurrentImu;
00115     SO3<> mso3LastImu;
00116 
00117     //}
00118 
00119 
00120     // Weiss{
00121     Matrix<6>   mmCovariances;          // covariance of current converged pose estimate
00122     KeyFrame::Ptr mOldKF;
00123     bool mAutoreset;                            // indicates if user pressed reset or not
00124     //}
00125 
00126     // Interface with map maker:
00127     int mnFrame;                    // Frames processed since last reset
00128     int mnLastKeyFrameDropped;      // Counter of last keyframe inserted.
00129     void AddNewKeyFrame();          // Gives the current frame to the mapmaker to use as a keyframe
00130 
00131     // Tracking quality control:
00132     int manMeasAttempted[LEVELS];
00133     int manMeasFound[LEVELS];
00134     enum {BAD, DODGY, GOOD} mTrackingQuality;
00135     int mnLostFrames;
00136 
00137     // Relocalisation functions:
00138     bool AttemptRecovery();         // Called by TrackFrame if tracking is lost.
00139     bool mbJustRecoveredSoUseCoarse;// Always use coarse tracking after recovery!
00140 
00141     // Frame-to-frame motion init:
00142     SmallBlurryImage *mpSBILastFrame;
00143     SmallBlurryImage *mpSBIThisFrame;
00144     void CalcSBIRotation();
00145     Vector<6> mv6SBIRot;
00146     bool mbUseSBIInit;
00147 
00148     // User interaction for initial tracking:
00149     bool mbUserPressedSpacebar;
00150     std::ostringstream mMessageForUser;
00151 
00152     // GUI interface:
00153     void GUICommandHandler(std::string sCommand, std::string sParams);
00154     static void GUICommandCallBack(void* ptr, std::string sCommand, std::string sParams);
00155     struct Command {std::string sCommand; std::string sParams; };
00156     std::vector<Command> mvQueuedCommands;
00157 
00158 
00159 };
00160 
00161 #endif
00162 
00163 
00164 
00165 
00166 
00167 


ptam
Author(s): Stephan Weiss, Markus Achtelik, Simon Lynen
autogenerated on Tue Jan 7 2014 11:12:22