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.
TrackerData.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 // Copyright 2008 Isis Innovation Limited
3 #ifndef __TRACKERDATA_H
4 #define __TRACKERDATA_H
5 
6 #include "PatchFinder.h"
7 #include "ATANCamera.h"
8 #include "globals.h"
9 
10 // This class contains all the intermediate results associated with
11 // a map-point that the tracker keeps up-to-date. TrackerData
12 // basically handles all the tracker's point-projection jobs,
13 // and also contains the PatchFinder which does the image search.
14 // It's very code-heavy for an h-file (it's a bunch of methods really)
15 // but it's only included from Tracker.cc!
16 
18 {
19 TrackerData(MapPoint *pMapPoint)
20 : Point(*pMapPoint)
21  {};
22 
23  MapPoint &Point;
25 
26  // Projection itermediates:
27  Vector<3> v3Cam; // Coords in current cam frame
28  Vector<2> v2ImPlane; // Coords in current cam z=1 plane
29  Vector<2> v2Image; // Pixel coords in LEVEL0
30  Matrix<2> m2CamDerivs; // Camera projection derivs
31  bool bInImage;
33 
35  bool bSearched;
36  bool bFound;
37  bool bDidSubPix;
38  Vector<2> v2Found; // Pixel coords of found patch (L0)
39  double dSqrtInvNoise; // Only depends on search level..
40 
41 
42  // Stuff for pose update:
44  Matrix<2,6> m26Jacobian; // Jacobian wrt camera position
45 
46  // Project point into image given certain pose and camera.
47  // This can bail out at several stages if the point
48  // will not be properly in the image.
49  inline void Project(const SE3<> &se3CFromW, ATANCamera &Cam)
50  {
51  bInImage = bPotentiallyVisible = false;
52  v3Cam = se3CFromW * Point.v3WorldPos;
53  if(v3Cam[2] < 0.001)
54  return;
55  v2ImPlane = project(v3Cam);
56  if(v2ImPlane*v2ImPlane > Cam.LargestRadiusInImage() * Cam.LargestRadiusInImage())
57  return;
58  v2Image = Cam.Project(v2ImPlane);
59  if(Cam.Invalid())
60  return;
61 
62  if(v2Image[0] < 0 || v2Image[1] < 0 || v2Image[0] > irImageSize[0] || v2Image[1] > irImageSize[1])
63  return;
64  bInImage = true;
65  }
66 
67  // Get the projection derivatives (depend only on the camera.)
68  // This is called Unsafe because it depends on the camera caching
69  // results from the previous projection:
70  // Only do this right after the same point has been projected!
71  inline void GetDerivsUnsafe(ATANCamera &Cam)
72  {
73  m2CamDerivs = Cam.GetProjectionDerivs();
74  }
75 
76  // Does projection and gets camera derivs all in one.
77  inline void ProjectAndDerivs(SE3<> &se3, ATANCamera &Cam)
78  {
79  Project(se3, Cam);
80  if(bFound)
81  GetDerivsUnsafe(Cam);
82  }
83 
84  // Jacobian of projection W.R.T. the camera position
85  // I.e. if p_cam = SE3Old * p_world,
86  // SE3New = SE3Motion * SE3Old
87  inline void CalcJacobian()
88  {
89  double dOneOverCameraZ = 1.0 / v3Cam[2];
90  for(int m=0; m<6; m++)
91  {
92  const Vector<4> v4Motion = SE3<>::generator_field(m, unproject(v3Cam));
93  Vector<2> v2CamFrameMotion;
94  v2CamFrameMotion[0] = (v4Motion[0] - v3Cam[0] * v4Motion[2] * dOneOverCameraZ) * dOneOverCameraZ;
95  v2CamFrameMotion[1] = (v4Motion[1] - v3Cam[1] * v4Motion[2] * dOneOverCameraZ) * dOneOverCameraZ;
96  m26Jacobian.T()[m] = m2CamDerivs * v2CamFrameMotion;
97  };
98  }
99 
100  // Sometimes in tracker instead of reprojecting, just update the error linearly!
101  inline void LinearUpdate(const Vector<6> &v6)
102  {
103  v2Image += m26Jacobian * v6;
104  }
105 
106  // This static member is filled in by the tracker and allows in-image checks in this class above.
108 };
109 
110 
111 
112 
113 
114 
115 #endif
116 
117 
118 
119 
void GetDerivsUnsafe(ATANCamera &Cam)
Definition: TrackerData.h:71
Vector< 2 > v2Found
Definition: TrackerData.h:38
bool bDidSubPix
Definition: TrackerData.h:37
Vector< 2 > Project(const Vector< 2 > &camframe)
Definition: ATANCamera.cpp:109
bool bPotentiallyVisible
Definition: TrackerData.h:32
Matrix< 2, 6 > m26Jacobian
Definition: TrackerData.h:44
Vector<(Size==Dynamic?Dynamic:Size+1), Precision > unproject(const Vector< Size, Precision, Base > &v)
Definition: helpers.h:166
TrackerData(MapPoint *pMapPoint)
Definition: TrackerData.h:19
bool bInImage
Definition: TrackerData.h:31
MapPoint & Point
Definition: TrackerData.h:21
Definition: se3.h:50
Vector< 3 > v3WorldPos
Definition: MapPoint.h:38
Vector< 3 > v3Cam
Definition: TrackerData.h:27
PatchFinder Finder
Definition: TrackerData.h:24
void Project(const SE3<> &se3CFromW, ATANCamera &Cam)
Definition: TrackerData.h:49
void CalcJacobian()
Definition: TrackerData.h:87
void LinearUpdate(const Vector< 6 > &v6)
Definition: TrackerData.h:101
Vector< 2 > v2Image
Definition: TrackerData.h:29
bool Invalid()
Definition: ATANCamera.h:89
bool bSearched
Definition: TrackerData.h:35
Vector< 2 > v2ImPlane
Definition: TrackerData.h:28
void ProjectAndDerivs(SE3<> &se3, ATANCamera &Cam)
Definition: TrackerData.h:77
Vector< 2 > v2Error_CovScaled
Definition: TrackerData.h:43
double dSqrtInvNoise
Definition: TrackerData.h:39
Matrix< 2 > m2CamDerivs
Definition: TrackerData.h:30
int nSearchLevel
Definition: TrackerData.h:34
double LargestRadiusInImage()
Definition: ATANCamera.h:90
Matrix< 2, 2 > GetProjectionDerivs()
Definition: ATANCamera.cpp:172
Vector<(Size==Dynamic?Dynamic:Size-1), Precision > project(const Vector< Size, Precision, Base > &v)
Definition: helpers.h:157
static CVD::ImageRef irImageSize
Definition: TrackerData.h:107