00001 // -*- c++ -*- 00002 // Copyright 2008 Isis Innovation Limited 00003 00004 // 00005 // This header declares the data structures to do with keyframes: 00006 // structs KeyFrame, Level, Measurement, Candidate. 00007 // 00008 // A KeyFrame contains an image pyramid stored as array of Level; 00009 // A KeyFrame also has associated map-point mesurements stored as a vector of Measurment; 00010 // Each individual Level contains an image, corner points, and special corner points 00011 // which are promoted to Candidate status (the mapmaker tries to make new map points from those.) 00012 // 00013 // KeyFrames are stored in the Map class and manipulated by the MapMaker. 00014 // However, the tracker also stores its current frame as a half-populated 00015 // KeyFrame struct. 00016 00017 00018 #ifndef __KEYFRAME_H 00019 #define __KEYFRAME_H 00020 #include <TooN/TooN.h> 00021 using namespace TooN; 00022 #include <TooN/se3.h> 00023 #include <cvd/image.h> 00024 #include <cvd/byte.h> 00025 #include <vector> 00026 #include <set> 00027 #include <map> 00028 #include <boost/shared_ptr.hpp> 00029 00030 #include "ptam/Params.h" 00031 00032 struct MapPoint; 00033 class SmallBlurryImage; 00034 //slynen{ reprojection 00035 struct TrackerData; 00036 //} 00037 #define LEVELS 4 00038 00039 // Candidate: a feature in an image which could be made into a map point 00040 struct Candidate 00041 { 00042 CVD::ImageRef irLevelPos; 00043 Vector<2> v2RootPos; 00044 double dSTScore; 00045 }; 00046 00047 // Measurement: A 2D image measurement of a map point. Each keyframe stores a bunch of these. 00048 struct Measurement 00049 { 00050 int nLevel; // Which image level? 00051 bool bSubPix; // Has this measurement been refined to sub-pixel level? 00052 Vector<2> v2RootPos; // Position of the measurement, REFERED TO PYRAMID LEVEL ZERO 00053 enum {SRC_TRACKER, SRC_REFIND, SRC_ROOT, SRC_TRAIL, SRC_EPIPOLAR} Source; // Where has this measurement come frome? 00054 }; 00055 00056 // Each keyframe is made of LEVELS pyramid levels, stored in struct Level. 00057 // This contains image data and corner points. 00058 struct Level 00059 { 00060 inline Level() 00061 { 00062 bImplaneCornersCached = false; 00063 }; 00064 00065 CVD::Image<CVD::byte> im; // The pyramid level pixels 00066 std::vector<CVD::ImageRef> vCorners; // All FAST corners on this level 00067 std::vector<int> vCornerRowLUT; // Row-index into the FAST corners, speeds up access 00068 std::vector<CVD::ImageRef> vMaxCorners; // The maximal FAST corners 00069 Level& operator=(const Level &rhs); 00070 00071 std::vector<Candidate> vCandidates; // Potential locations of new map points 00072 00073 bool bImplaneCornersCached; // Also keep image-plane (z=1) positions of FAST corners to speed up epipolar search 00074 std::vector<Vector<2> > vImplaneCorners; // Corner points un-projected into z=1-plane coordinates 00075 }; 00076 00077 // The actual KeyFrame struct. The map contains of a bunch of these. However, the tracker uses this 00078 // struct as well: every incoming frame is turned into a keyframe before tracking; most of these 00079 // are then simply discarded, but sometimes they're then just added to the map. 00080 struct KeyFrame 00081 { 00082 typedef boost::shared_ptr<KeyFrame> Ptr; 00083 00084 inline KeyFrame() 00085 { 00086 pSBI = NULL; 00087 } 00088 SE3<> se3CfromW; // The coordinate frame of this key-frame as a Camera-From-World transformation 00089 bool bFixed; // Is the coordinate frame of this keyframe fixed? (only true for first KF!) 00090 Level aLevels[LEVELS]; // Images, corners, etc lives in this array of pyramid levels 00091 std::map<boost::shared_ptr<MapPoint>, Measurement> mMeasurements; // All the measurements associated with the keyframe 00092 00093 //slynen pcl interface{ 00094 int bID; 00095 //} 00096 void MakeKeyFrame_Lite(CVD::BasicImage<CVD::byte> &im); // This takes an image and calculates pyramid levels etc to fill the 00097 // keyframe data structures with everything that's needed by the tracker.. 00098 void MakeKeyFrame_Rest(); // ... while this calculates the rest of the data which the mapmaker needs. 00099 00100 //slynen{ reprojection 00101 std::vector<boost::shared_ptr<MapPoint> > vpPoints; // stores the map points found in this keyframe 00102 enum { iBestPointsCount = 5 }; // how many points to use for keyframe evaluation 00103 boost::shared_ptr<MapPoint> apCurrentBestPoints[iBestPointsCount]; // stores the currently best Points for Keyframe identification 00104 void AddKeyMapPoint(boost::shared_ptr<MapPoint> mp); // checks whether to add a MapPoint to the KeyMapPoint of the KeyFrame 00105 // those points help selecting the Keyframes which are visible for reprojection 00106 //} 00107 00108 double dSceneDepthMean; // Hacky hueristics to improve epipolar search. 00109 double dSceneDepthSigma; 00110 00111 //Weiss{ 00112 double dSceneDepthMedian; // used to keep same scale after auto-re-init 00113 int ID; // KF id used to identify KFs when exporting them... 00114 //} 00115 00116 SmallBlurryImage *pSBI; // The relocaliser uses this 00117 }; 00118 00119 typedef std::map<boost::shared_ptr<MapPoint>, Measurement>::iterator meas_it; // For convenience, and to work around an emacs paren-matching bug 00120 00121 00122 #endif 00123