TooN Algorithm Library - tag  0.2
fourpointpose.h
Go to the documentation of this file.
1 #ifndef TAG_FOURPOINTPOSE_H_
2 #define TAG_FOURPOINTPOSE_H_
3 
4 #include <vector>
5 
6 #include <TooN/TooN.h>
7 #include <TooN/se3.h>
8 
9 namespace tag {
10 
14 
30 TooN::SE3<> fourPointPose( const std::vector<TooN::Vector<3> > & points, const std::vector<TooN::Vector<3> > & pixels, bool & valid, const double angularError = 0.14 );
31 
46 TooN::SE3<> fourPointPoseFromCamera( const std::vector<TooN::Vector<3> > & points, const std::vector<TooN::Vector<3> > & pixels, bool & valid, const double angularError = 0.14 );
47 
59 template <int ImagePlaneZ = 1>
62  TooN::SE3<> T;
64  bool valid;
66  double angularError;
68  static const int hypothesis_size = 4;
69 
70  inline Point4SE3Estimation(double ang = 0.14) : valid(false), angularError(ang) { }
71 
72  template<class It> inline bool estimate(It begin, It end) {
73  assert(std::distance(begin,end) >= 4);
74  valid = true;
75 
76  std::vector<TooN::Vector<3> > points(4);
77  std::vector<TooN::Vector<3> > pixels(4);
78  unsigned int i = 0;
79  for(It match = begin; match != end; match++, i++){
80  pixels[i] = unproject(match->pixel);
81  pixels[i][2] *= ImagePlaneZ;
82  points[i] = match->position;
83  }
84  T = fourPointPoseFromCamera( points, pixels, valid, angularError );
85  return valid;
86  }
87 
88  template<class Obs, class Tol> inline bool isInlier( const Obs& obs, const Tol& tolerance ) const {
89  return score(obs) < tolerance;
90  }
91 
92  template<class Obs> inline double score(const Obs & obs) const {
93  if(valid){
94  TooN::Vector<3> pos = T * obs.position;
95  TooN::Vector<2> diff = project(pos) - obs.pixel / ImagePlaneZ;
96  double disp = diff*diff;
97  return disp;
98  }
99  return 100;
100  }
101 
102  template<class Obs> inline double getSqError(const Obs & obs) const {
103  return score(obs);
104  }
105 };
106 
107 } // namespace tag
108 
109 #endif /*FOURPOINTPOSE*/