Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 #ifndef SEGMENTATION_INTERFACE
00031 #define SEGMENTATION_INTERFACE
00032 
00033 #include "object_segmentation_gui/ObjectSegmentationGuiAction.h"
00034 #include "object_segmentation_gui/utils.h"
00035 
00036 #include "active_realtime_segmentation/fgbgsegment.h"
00037 #include "active_realtime_segmentation/pyra/tpimage.h"
00038 
00039 #include <sensor_msgs/Image.h>
00040 
00041 #include <boost/thread/mutex.hpp>
00042 #include <boost/thread/thread.hpp>
00043 #include <boost/thread/condition_variable.hpp>
00044 #include <deque>
00045 
00046 namespace object_segmentation_gui {
00047   
00048   typedef geometry_msgs::Point32    Point;
00049 
00050   class ObjectSegmenter
00051   {
00052   public:
00053     
00054     enum ActionType{PAUSE, RESET, CLICK, REGION, STOP, GRADCHANGE};
00055 
00056     struct Box2D
00057     {
00058       Point p_tl_;
00059       Point p_br_;
00060     };
00061     
00062     struct Action
00063     {
00064       ActionType type_;
00065       Box2D box_;
00066       
00067       
00068       bool with_colors_;
00069       bool with_color_holes_;
00070       bool uniform_;
00071       bool with_disparities_;
00072       bool with_surface_;
00073 
00074       float grad_weight_;
00075       
00076     };
00077 
00078     ObjectSegmenter( float grad_weight, int n_iter, 
00079                      bool use_gpu, float w_size = 0.20f, 
00080                      float b_size = 0.20f);
00081     ~ObjectSegmenter();
00082     
00083     void setNewData( const sensor_msgs::Image &image_, 
00084                      const stereo_msgs::DisparityImage &disparity_);
00085     
00086     void queueAction( const Action &action);
00087     
00088     bool getCurrentResult( sensor_msgs::Image &image);
00089     void getCurrentSurface(float &alpha, float &beta, float &gamma);
00090 
00091     void getCurrentSegmFlags( bool &with_colors, 
00092                               bool &with_color_holes_,
00093                               bool &uniform_,
00094                               bool &with_disparities_,
00095                               bool &with_surface_ );
00096 
00097     void setCurrentSegmFlags( bool with_colors, 
00098                               bool with_color_holes,
00099                               bool uniform,
00100                               bool with_disparities,
00101                               bool with_surface );
00102 
00103   protected:
00104     
00105   private:
00106     
00107     
00108     void doSegment();
00109 
00110     void stopThread();
00111 
00112     void setCurrentResult();
00113     bool dequeueAction( Action &action);
00114     void clearQueue();
00115 
00116     void waitForAction();
00117 
00118     void pause();
00119 
00120     
00121     template <typename Callable>
00122       void startThread( Callable f );
00123     
00124     
00125     
00126     
00127     void fillInitMask( Image<uint8_t> &init_mask, int start_x, int start_y, int stop_x, int stop_y);
00128     
00129     
00130     void fillImage( sensor_msgs::Image &image, const Image<uint8_t> &segm_mask);
00131     
00132     bool validResult( const Image<uint8_t> &segm_mask);
00133    
00134     int w_;
00135     int h_;
00136     int grad_weight_;
00137     int drange_;
00138 
00139     float window_size_;
00140     float ball_size_;
00141 
00142     bool use_gpu_;
00143     int  n_iter_;
00144 
00145     bool init_;
00146 
00147     int num_fg_hypos_;
00148 
00149     FgBgSegment *fgbgsegment;
00150     
00151     
00152     Image<uint8_t> gpu_image;
00153     Image<float> gpu_disparities;
00154 
00155     
00156     Image<uint8_t> init_mask;
00157 
00158     
00159     Image<uint8_t> segm_mask;
00160     float alpha_, beta_, gamma_; 
00161     
00162     
00163     std::deque<Action> action_queue_;
00164     
00165     boost::thread* thread_;
00166     boost::mutex   queue_mutex_;
00167     boost::mutex   image_mutex_;
00168 
00169     boost::condition_variable cond_var_;
00170 
00171   };
00172 }
00173 
00174 #endif // SEGMENTATION_INTERFACE