contrib/brl/vvid/vvid_file_manager.h
Go to the documentation of this file.
00001 // This is brl/vvid/vvid_file_manager.h
00002 #ifndef vvid_file_manager_h_
00003 #define vvid_file_manager_h_
00004 //-----------------------------------------------------------------------------
00005 //:
00006 // \file
00007 // \author J.L. Mundy
00008 // \brief A sample video file player
00009 //
00010 // \verbatim
00011 //  Modifications:
00012 //   J.L. Mundy October 05, 2002 Ported from jvid
00013 // \endverbatim
00014 //----------------------------------------------------------------------------
00015 #include <vcl_vector.h>
00016 #include <vcl_list.h>
00017 #include <vgui/vgui_grid_tableau.h>
00018 #include <vgui/vgui_wrapper_tableau.h>
00019 #include <vgui/vgui_image_tableau_sptr.h>
00020 #include <vgui/vgui_rubberband_tableau_sptr.h>
00021 #include <vgui/vgui_style_sptr.h>
00022 #include <bgui/bgui_vtol2D_tableau_sptr.h>
00023 #include <bgui/bgui_picker_tableau_sptr.h>
00024 #include <bgui/bgui_bargraph_clipon_tableau_sptr.h>
00025 #include <vgui/vgui_viewer2D_tableau_sptr.h>
00026 #include <strk/strk_art_info_model_sptr.h>
00027 #include <vtol/vtol_face_2d_sptr.h>
00028 #include <vpro/vpro_video_process_sptr.h>
00029 #include <vgui/vgui_window.h>
00030 #include <vidl_vil1/vidl_vil1_movie_sptr.h>
00031 #include <vvid/vvid_frame_trail.h>
00032 #include <vil1/vil1_image.h>
00033 
00034 //: A singleton manager class for playing videos.
00035 // A vector of images with
00036 // enclosing image and easy2D tableaux is cached so that computed overlays
00037 // such as Harris corners can be played back quickly. The cache option can be
00038 // turned off if one is going to just play the video and not apply image
00039 // segmentation processing to the frames.
00040 //
00041 // A demo of overlaying points on the video is provide by ::easy2D_demo
00042 // to get rid of the points, reload the video
00043 //
00044 // It is planned to extend the class to handle multiple panes (grid locations)
00045 // so that different (or the same) videos can be playing simultaneously
00046 // in different zoom states as well as pause states. This extension will
00047 // the state variables to be changed to vectors as well as having multiple
00048 // caches.. etc.
00049 //
00050 // Known problems:
00051 //  - quiting while the video is paused can cause a seg fault since
00052 //    the movie gets deleted before the loop quits
00053 //  - There is a continuous gl error stream from vgui_adaptor. Something to
00054 //    do with "setting draw buffer to back"
00055 //
00056 
00057 class vvid_file_manager : public vgui_wrapper_tableau
00058 {
00059  public:
00060   vvid_file_manager();
00061   ~vvid_file_manager();
00062   //: returns the unique instance of vvid_file_manger
00063   static vvid_file_manager *instance();
00064 
00065   //: height (in pixels) of the video frame
00066   unsigned get_height() const { return height_; }
00067 
00068   //: width (in pixels) of the video frame
00069   unsigned get_width() const { return width_; }
00070 
00071   //: quit the application
00072   void quit();
00073 
00074   //: load each frame of the video into a cached vector of overlays if caching is enabled
00075   void load_video_file();
00076 
00077   //: loop through the frames and display
00078   void play_video();
00079 
00080   //: stop at the current frame
00081   void pause_video();
00082 
00083   //: stop playing and return to the first frame
00084   void stop_video();
00085 
00086   //: pops up a dialog to indicate what frame to start play
00087   void start_frame();
00088 
00089   //: pops up a dialog to indicate what frame to start play
00090   void end_frame();
00091 
00092   //: index to the next frame (must be paused)
00093   void next_frame();
00094 
00095   //: index to the previous frame (must be paused)
00096   void prev_frame();
00097 
00098   //: set the frame rate
00099   void set_speed();
00100 
00101   //: a demo of spatial overlays on the video (scrolling points)
00102   void easy2D_tableau_demo();
00103 
00104   //: No operation
00105   void no_op();
00106 
00107   //: show the difference of sequential frames
00108   void difference_frames();
00109 
00110   //: show the motion condition
00111   void compute_motion();
00112 
00113   //: show the Lucas-Kanade vectors as color
00114   void compute_lucas_kanade();
00115 
00116   //: show the Harris corners
00117   void compute_harris_corners();
00118 
00119   //: show VanDuc edges
00120   void compute_vd_edges();
00121 
00122   //: show fit lines
00123   void compute_line_fit();
00124 
00125   //: show matches of calibration grid
00126   void compute_grid_match();
00127 
00128   //: show correlation tracking
00129   void compute_corr_tracking();
00130 
00131   //: show mutual information tracking
00132   void compute_info_tracking();
00133 
00134   //: display a tracked polygon
00135   void display_poly_track();
00136 
00137   //: display a tracked art model
00138   void display_art_model_track();
00139 
00140   //: enable display movie generation
00141   void start_save_display();
00142 
00143   //: enable display movie generation
00144   void end_save_display();
00145 
00146   //: generate a basis sequence
00147   void generate_basis_sequence();
00148 
00149   //: compute fourier transform
00150   void compute_fourier_transform();
00151 
00152   //: compute fourier transform
00153   void spatial_filter();
00154 
00155   //: create a box by rubberbanding
00156   void create_box();
00157 
00158   //: create a polygon by rubberbanding
00159   void create_polygon();
00160 
00161   //: create the elements of the art model
00162   void create_stem();
00163   void create_long_arm_tip();
00164   void create_short_arm_tip();
00165   //: create a background model polygon
00166   void create_background_model();
00167   //: test model
00168   void exercise_art_model();
00169 
00170   //: process_art_model
00171   void track_art_model();
00172 
00173   //: display intensity hue and saturation 
00174   void display_ihs();
00175 
00176   //: save the current frame in pane 0
00177   void save_frame();
00178 
00179   //: save half resolution version of the current video
00180   void save_half_res();
00181 
00182   //: display tracked histogram feature data
00183   void display_tracked_hist_data();
00184 
00185   //: capture feature data from stored track
00186   void capture_feature_data();
00187 
00188   //: capture snippets
00189   void capture_snippets();
00190 
00191   //: get the window of this player
00192   vgui_window* get_window() { return win_; }
00193 
00194   //: set the window
00195   void set_window(vgui_window* win){win_=win;}
00196 
00197   //: tableau handle function
00198   virtual bool handle(const vgui_event&);
00199 
00200  protected:
00201   //utility functions
00202   void init();
00203   void cached_play();
00204   void un_cached_play();
00205   void display_image();
00206   void display_spatial_objects();
00207   void display_topology();
00208   void display_bargraph(vcl_vector<float> const& data);
00209   void set_changing_colors(int num, float *r, float *g, float *b);
00210   void save_display(int frame);
00211  private:
00212   //flags
00213   bool cache_frames_;
00214   bool play_video_;
00215   bool pause_video_;
00216   bool next_frame_;
00217   bool prev_frame_;
00218   bool save_display_;
00219   bool overlay_pane_;
00220   bool track_;//keep trail of display items
00221   int window_;//frame trail time window
00222   int start_frame_; //frame to start play
00223   int end_frame_; //frame to start play
00224   bool color_label_;//display with a different color for different labels
00225   float time_interval_;
00226   int display_frame_repeat_;//insert duplicate frames to slow playback
00227   int display_frame_skip_;//skip frames to speed playback
00228   int skip_counter_;
00229   unsigned width_;
00230   unsigned height_;
00231   vidl_vil1_movie_sptr my_movie_;
00232   vgui_window* win_;
00233   vcl_vector<bgui_vtol2D_tableau_sptr> tabs_;
00234   vgui_viewer2D_tableau_sptr v2D0_;
00235   vgui_viewer2D_tableau_sptr v2D1_;
00236   bgui_vtol2D_tableau_sptr easy0_;
00237   bgui_vtol2D_tableau_sptr easy1_;
00238   vgui_image_tableau_sptr itab0_;
00239   vgui_rubberband_tableau_sptr rubber0_;
00240   bgui_picker_tableau_sptr picktab0_;
00241   vgui_image_tableau_sptr itab1_;
00242   vpro_video_process_sptr video_process_;
00243   vgui_grid_tableau_sptr grid_;
00244   vvid_frame_trail frame_trail_;
00245   static vvid_file_manager *instance_;
00246   vcl_vector<vcl_vector<vsol_spatial_object_2d_sptr> > cached_spat_objs_;
00247   vcl_list<vil1_image> display_output_frames_;
00248   vcl_string display_output_file_;
00249   vtol_face_2d_sptr stem_;
00250   vtol_face_2d_sptr long_tip_;
00251   vtol_face_2d_sptr short_tip_;
00252   strk_art_info_model_sptr art_model_;
00253   vtol_face_2d_sptr background_model_;
00254   vgui_style_sptr on_style_;
00255   vgui_style_sptr off_style_;
00256   bgui_bargraph_clipon_tableau_sptr bargraph_;
00257 };
00258 
00259 #endif // vvid_file_manager_h_