SLAMflex SE  0.1.0
SLAMflex provides detection and tracking of dominant planes for smartphone devices. This plane can then be used to show AR content relative to the plane orientation. The detection of plane is performed in the field of view of the smartphone camera. In subsequent frames it is tracked. The interface returns the plane position and orientation.
KeyFrame.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 // Copyright 2008 Isis Innovation Limited
3 
4 //
5 // This header declares the data structures to do with keyframes:
6 // structs KeyFrame, Level, Measurement, Candidate.
7 //
8 // A KeyFrame contains an image pyramid stored as array of Level;
9 // A KeyFrame also has associated map-point mesurements stored as a vector of Measurment;
10 // Each individual Level contains an image, corner points, and special corner points
11 // which are promoted to Candidate status (the mapmaker tries to make new map points from those.)
12 //
13 // KeyFrames are stored in the Map class and manipulated by the MapMaker.
14 // However, the tracker also stores its current frame as a half-populated
15 // KeyFrame struct.
16 
17 
18 #ifndef __KEYFRAME_H
19 #define __KEYFRAME_H
20 #include "TooN.h"
21 using namespace TooN;
22 #include "se3.h"
23 #include "image.h"
24 #include "byte.h"
25 #include <vector>
26 #include <set>
27 #include <map>
28 #include "globals.h"
29 
30 class MapPoint;
31 class SmallBlurryImage;
32 
33 #define LEVELS 4
34 
35 // Candidate: a feature in an image which could be made into a map point
36 struct Candidate
37 {
40  double dSTScore;
41 };
42 
43 // Measurement: A 2D image measurement of a map point. Each keyframe stores a bunch of these.
45 {
46  int nLevel; // Which image level?
47  bool bSubPix; // Has this measurement been refined to sub-pixel level?
48  Vector<2> v2RootPos; // Position of the measurement, REFERED TO PYRAMID LEVEL ZERO
49  enum {SRC_TRACKER, SRC_REFIND, SRC_ROOT, SRC_TRAIL, SRC_EPIPOLAR} Source; // Where has this measurement come frome?
50 };
51 
52 // Each keyframe is made of LEVELS pyramid levels, stored in struct Level.
53 // This contains image data and corner points.
54 struct Level
55 {
56  inline Level()
57  {
58  bImplaneCornersCached = false;
59  };
60 
61  CVD::Image<CVD::byte> im; // The pyramid level pixels
62  std::vector<CVD::ImageRef> vCorners; // All FAST corners on this level
63  std::vector<int> vCornerRowLUT; // Row-index into the FAST corners, speeds up access
64  std::vector<CVD::ImageRef> vMaxCorners; // The maximal FAST corners
65  Level& operator=(const Level &rhs);
66 
67  std::vector<Candidate> vCandidates; // Potential locations of new map points
68 
69  bool bImplaneCornersCached; // Also keep image-plane (z=1) positions of FAST corners to speed up epipolar search
70  std::vector<Vector<2> > vImplaneCorners; // Corner points un-projected into z=1-plane coordinates
71 };
72 
73 // The actual KeyFrame struct. The map contains of a bunch of these. However, the tracker uses this
74 // struct as well: every incoming frame is turned into a keyframe before tracking; most of these
75 // are then simply discarded, but sometimes they're then just added to the map.
76 struct KeyFrame
77 {
78  inline KeyFrame()
79  {
80  pSBI = NULL;
81  }
82  SE3<> se3CfromW; // The coordinate frame of this key-frame as a Camera-From-World transformation
83  bool bFixed; // Is the coordinate frame of this keyframe fixed? (only true for first KF!)
84  Level aLevels[LEVELS]; // Images, corners, etc lives in this array of pyramid levels
85  std::map<MapPoint*, Measurement> mMeasurements; // All the measurements associated with the keyframe
86 
87  int MakeKeyFrame_Lite(CVD::BasicImage<CVD::byte> &im, int threshold); // This takes an image and calculates pyramid levels etc to fill the
88  // keyframe data structures with everything that's needed by the tracker..
89  void MakeKeyFrame_Rest(); // ... while this calculates the rest of the data which the mapmaker needs.
90 
91  double dSceneDepthMean; // Hacky hueristics to improve epipolar search.
93 
94  SmallBlurryImage *pSBI; // The relocaliser uses this
95 };
96 
97 typedef std::map<MapPoint*, Measurement>::iterator meas_it; // For convenience, and to work around an emacs paren-matching bug
98 
99 
100 #endif
101 
bool bSubPix
Definition: KeyFrame.h:47
std::map< MapPoint *, Measurement >::iterator meas_it
Definition: KeyFrame.h:97
SmallBlurryImage * pSBI
Definition: KeyFrame.h:94
#define LEVELS
Definition: KeyFrame.h:33
Vector< 2 > v2RootPos
Definition: KeyFrame.h:39
KeyFrame()
Definition: KeyFrame.h:78
bool bFixed
Definition: KeyFrame.h:83
Everything lives inside this namespace.
Definition: allocator.hh:48
double dSceneDepthSigma
Definition: KeyFrame.h:92
bool bImplaneCornersCached
Definition: KeyFrame.h:69
std::vector< CVD::ImageRef > vCorners
Definition: KeyFrame.h:62
Definition: se3.h:50
std::vector< Vector< 2 > > vImplaneCorners
Definition: KeyFrame.h:70
SE3 se3CfromW
Definition: KeyFrame.h:82
void threshold(BasicImage< T > &im, const T &minimum, const T &hi)
Definition: vision.h:163
Definition: KeyFrame.h:54
Vector< 2 > v2RootPos
Definition: KeyFrame.h:48
int nLevel
Definition: KeyFrame.h:46
std::vector< int > vCornerRowLUT
Definition: KeyFrame.h:63
std::map< MapPoint *, Measurement > mMeasurements
Definition: KeyFrame.h:85
double dSceneDepthMean
Definition: KeyFrame.h:91
std::vector< CVD::ImageRef > vMaxCorners
Definition: KeyFrame.h:64
double dSTScore
Definition: KeyFrame.h:40
std::vector< Candidate > vCandidates
Definition: KeyFrame.h:67
Level()
Definition: KeyFrame.h:56
CVD::ImageRef irLevelPos
Definition: KeyFrame.h:38