svo
Semi-Direct Visual Odometry
include/svo/frame.h
Go to the documentation of this file.
00001 // This file is part of SVO - Semi-direct Visual Odometry.
00002 //
00003 // Copyright (C) 2014 Christian Forster <forster at ifi dot uzh dot ch>
00004 // (Robotics and Perception Group, University of Zurich, Switzerland).
00005 //
00006 // SVO is free software: you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the Free Software
00008 // Foundation, either version 3 of the License, or any later version.
00009 //
00010 // SVO is distributed in the hope that it will be useful, but WITHOUT ANY
00011 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00012 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #ifndef SVO_FRAME_H_
00018 #define SVO_FRAME_H_
00019 
00020 #include <sophus/se3.h>
00021 #include <vikit/math_utils.h>
00022 #include <vikit/abstract_camera.h>
00023 #include <boost/noncopyable.hpp>
00024 #include <svo/global.h>
00025 
00026 namespace g2o {
00027 class VertexSE3Expmap;
00028 }
00029 typedef g2o::VertexSE3Expmap g2oFrameSE3;
00030 
00031 namespace svo {
00032 
00033 class Point;
00034 struct Feature;
00035 
00036 typedef list<Feature*> Features;
00037 typedef vector<cv::Mat> ImgPyr;
00038 
00040 class Frame : boost::noncopyable
00041 {
00042 public:
00043   EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00044     
00045   static int                    frame_counter_;         
00046   int                           id_;                    
00047   double                        timestamp_;             
00048   vk::AbstractCamera*           cam_;                   
00049   Sophus::SE3                   T_f_w_;                 
00050   Matrix<double, 6, 6>          Cov_;                   
00051   ImgPyr                        img_pyr_;               
00052   Features                      fts_;                   
00053   vector<Feature*>              key_pts_;               
00054   bool                          is_keyframe_;           
00055   g2oFrameSE3*                  v_kf_;                  
00056   int                           last_published_ts_;     
00057 
00058   Frame(vk::AbstractCamera* cam, const cv::Mat& img, double timestamp);
00059   ~Frame();
00060 
00062   void initFrame(const cv::Mat& img);
00063 
00065   void setKeyframe();
00066 
00068   void addFeature(Feature* ftr);
00069 
00073   void setKeyPoints();
00074 
00076   void checkKeyPoints(Feature* ftr);
00077 
00079   void removeKeyPoint(Feature* ftr);
00080 
00082   inline size_t nObs() const { return fts_.size(); }
00083 
00085   bool isVisible(const Vector3d& xyz_w) const;
00086 
00088   inline const cv::Mat& img() const { return img_pyr_[0]; }
00089 
00091   inline bool isKeyframe() const { return is_keyframe_; }
00092 
00094   inline Vector2d w2c(const Vector3d& xyz_w) const { return cam_->world2cam( T_f_w_ * xyz_w ); }
00095 
00097   inline Vector3d c2f(const Vector2d& px) const { return cam_->cam2world(px[0], px[1]); }
00098 
00100   inline Vector3d c2f(const double x, const double y) const { return cam_->cam2world(x, y); }
00101 
00103   inline Vector3d w2f(const Vector3d& xyz_w) const { return T_f_w_ * xyz_w; }
00104 
00106   inline Vector3d f2w(const Vector3d& f) const { return T_f_w_.inverse() * f; }
00107 
00109   inline Vector2d f2c(const Vector3d& f) const { return cam_->world2cam( f ); }
00110 
00112   inline Vector3d pos() const { return T_f_w_.inverse().translation(); }
00113 
00116   inline static void jacobian_xyz2uv(
00117       const Vector3d& xyz_in_f,
00118       Matrix<double,2,6>& J)
00119   {
00120     const double x = xyz_in_f[0];
00121     const double y = xyz_in_f[1];
00122     const double z_inv = 1./xyz_in_f[2];
00123     const double z_inv_2 = z_inv*z_inv;
00124 
00125     J(0,0) = -z_inv;              // -1/z
00126     J(0,1) = 0.0;                 // 0
00127     J(0,2) = x*z_inv_2;           // x/z^2
00128     J(0,3) = y*J(0,2);            // x*y/z^2
00129     J(0,4) = -(1.0 + x*J(0,2));   // -(1.0 + x^2/z^2)
00130     J(0,5) = y*z_inv;             // y/z
00131 
00132     J(1,0) = 0.0;                 // 0
00133     J(1,1) = -z_inv;              // -1/z
00134     J(1,2) = y*z_inv_2;           // y/z^2
00135     J(1,3) = 1.0 + y*J(1,2);      // 1.0 + y^2/z^2
00136     J(1,4) = -J(0,3);             // -x*y/z^2
00137     J(1,5) = -x*z_inv;            // x/z
00138   }
00139 };
00140 
00141 
00143 namespace frame_utils {
00144 
00146 void createImgPyramid(const cv::Mat& img_level_0, int n_levels, ImgPyr& pyr);
00147 
00149 bool getSceneDepth(const Frame& frame, double& depth_mean, double& depth_min);
00150 
00151 } // namespace frame_utils
00152 } // namespace svo
00153 
00154 #endif // SVO_FRAME_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines