svo
Semi-Direct Visual Odometry
include/svo/depth_filter.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_DEPTH_FILTER_H_
00018 #define SVO_DEPTH_FILTER_H_
00019 
00020 #include <queue>
00021 #include <boost/thread.hpp>
00022 #include <boost/function.hpp>
00023 #include <vikit/performance_monitor.h>
00024 #include <svo/global.h>
00025 #include <svo/feature_detection.h>
00026 #include <svo/matcher.h>
00027 
00028 namespace svo {
00029 
00030 class Frame;
00031 class Feature;
00032 class Point;
00033 
00035 struct Seed
00036 {
00037   EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00038 
00039   static int batch_counter;
00040   static int seed_counter;
00041   int batch_id;                
00042   int id;                      
00043   Feature* ftr;                
00044   float a;                     
00045   float b;                     
00046   float mu;                    
00047   float z_range;               
00048   float sigma2;                
00049   Matrix2d patch_cov;          
00050   Seed(Feature* ftr, float depth_mean, float depth_min);
00051 };
00052 
00059 class DepthFilter
00060 {
00061 public:
00062   EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00063 
00064   typedef boost::unique_lock<boost::mutex> lock_t;
00065   typedef boost::function<void ( Point*, double )> callback_t;
00066 
00068   struct Options
00069   {
00070     bool check_ftr_angle;                       
00071     bool epi_search_1d;                         
00072     bool verbose;                               
00073     bool use_photometric_disparity_error;       
00074     int max_n_kfs;                              
00075     double sigma_i_sq;                          
00076     double seed_convergence_sigma2_thresh;      
00077     Options()
00078     : check_ftr_angle(false),
00079       epi_search_1d(false),
00080       verbose(false),
00081       use_photometric_disparity_error(false),
00082       max_n_kfs(3),
00083       sigma_i_sq(5e-4),
00084       seed_convergence_sigma2_thresh(200.0)
00085     {}
00086   } options_;
00087 
00088   DepthFilter(
00089       feature_detection::DetectorPtr feature_detector,
00090       callback_t seed_converged_cb);
00091 
00092   virtual ~DepthFilter();
00093 
00095   void startThread();
00096 
00098   void stopThread();
00099 
00101   void addFrame(FramePtr frame);
00102 
00104   void addKeyframe(FramePtr frame, double depth_mean, double depth_min);
00105 
00109   void removeKeyframe(FramePtr frame);
00110 
00113   void reset();
00114 
00119   void getSeedsCopy(const FramePtr& frame, std::list<Seed>& seeds);
00120 
00122   std::list<Seed, aligned_allocator<Seed> >& getSeeds() { return seeds_; }
00123 
00125   static void updateSeed(
00126       const float x,
00127       const float tau2,
00128       Seed* seed);
00129 
00131   static double computeTau(
00132       const SE3& T_ref_cur,
00133       const Vector3d& f,
00134       const double z,
00135       const double px_error_angle);
00136 
00137 protected:
00138   feature_detection::DetectorPtr feature_detector_;
00139   callback_t seed_converged_cb_;
00140   std::list<Seed, aligned_allocator<Seed> > seeds_;
00141   boost::mutex seeds_mut_;
00142   bool seeds_updating_halt_;            
00143   boost::thread* thread_;
00144   std::queue<FramePtr> frame_queue_;
00145   boost::mutex frame_queue_mut_;
00146   boost::condition_variable frame_queue_cond_;
00147   FramePtr new_keyframe_;               
00148   bool new_keyframe_set_;               
00149   double new_keyframe_min_depth_;       
00150   double new_keyframe_mean_depth_;      
00151   vk::PerformanceMonitor permon_;       
00152   Matcher matcher_;
00153 
00155   void initializeSeeds(FramePtr frame);
00156 
00158   virtual void updateSeeds(FramePtr frame);
00159 
00161   void clearFrameQueue();
00162 
00164   void updateSeedsLoop();
00165 };
00166 
00167 } // namespace svo
00168 
00169 #endif // SVO_DEPTH_FILTER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines