Go to the documentation of this file.00001
00002 #include "vvid_live_stereo_manager.h"
00003
00004
00005
00006
00007 #include <vcl_cstdlib.h>
00008 #include <vcl_iostream.h>
00009 #include <vil1/vil1_memory_image_of.h>
00010 #include <vgui/vgui.h>
00011 #include <vgui/vgui_adaptor.h>
00012 #include <vgui/vgui_dialog.h>
00013 #include <vgui/vgui_viewer2D_tableau.h>
00014 #include <vgui/vgui_grid_tableau.h>
00015 #include <vgui/vgui_image_tableau.h>
00016
00017 #include <vvid/cmu_1394_camera_params.h>
00018 #include <vpro/vpro_video_process.h>
00019 #include <vpro/vpro_epipolar_space_process.h>
00020
00021
00022 vvid_live_stereo_manager *vvid_live_stereo_manager::instance_ = 0;
00023
00024
00025 vvid_live_stereo_manager *vvid_live_stereo_manager::instance()
00026 {
00027 if (!instance_)
00028 instance_ = new vvid_live_stereo_manager();
00029 return vvid_live_stereo_manager::instance_;
00030 }
00031
00032
00033
00034
00035 vvid_live_stereo_manager::
00036 vvid_live_stereo_manager() : vgui_grid_tableau(2,2),
00037 cp_(cmu_1394_camera_params())
00038 {
00039 width_ = 960;
00040 height_ = 480;
00041 win_ = 0;
00042 live_capture_ = false;
00043 N_views_ = 2;
00044 video_process_ = (vpro_video_process*)new vpro_epipolar_space_process();
00045 init_successful_ = false;
00046 this->set_grid_size_changeable(true);
00047 }
00048
00049 vvid_live_stereo_manager::~vvid_live_stereo_manager()
00050 {
00051 }
00052
00053
00054
00055 bool vvid_live_stereo_manager::handle(const vgui_event &e)
00056 {
00057
00058
00059 return vgui_grid_tableau::handle(e);
00060 }
00061
00062 void vvid_live_stereo_manager::set_camera_params()
00063 {
00064 if (!vframes_.size())
00065 {
00066 vcl_cout << "in vvid_live_stereo_manager::set_camera_params() -"
00067 << " no live video frames\n";
00068 return;
00069 }
00070 vgui_dialog cam_dlg("Camera Parameters");
00071 cam_dlg.field("video_format",cp_.video_format_);
00072 cam_dlg.field("video_mode",cp_.video_mode_);
00073 cam_dlg.field("frame_rate",cp_.frame_rate_);
00074 cam_dlg.field("brightness",cp_.brightness_);
00075 cam_dlg.field("sharpness",cp_.sharpness_);
00076 cam_dlg.field("exposure",cp_.exposure_);
00077 cam_dlg.field("gain",cp_.gain_);
00078 cam_dlg.checkbox("image capture(acquisition) ", cp_.capture_);
00079 cam_dlg.checkbox("RGB(monochrome) ", cp_.rgb_);
00080 if (!cam_dlg.ask())
00081 return;
00082 cp_.constrain();
00083 for (int i = 0; i<N_views_; i++)
00084 vframes_[i]->set_camera_params(cp_);
00085 }
00086
00087
00088
00089
00090
00091 void vvid_live_stereo_manager::setup_views()
00092 {
00093
00094
00095 init_successful_ = true;
00096 vframes_.clear();
00097 for (int i = 0; i<N_views_; i++)
00098 {
00099 vvid_live_video_tableau_sptr vf =
00100 vvid_live_video_tableau_new(i, 2, cmu_1394_camera_params());
00101 vframes_.push_back(vf);
00102 init_successful_ = init_successful_&&vf->attach_live_video();
00103 if (!init_successful_)
00104 {
00105 vcl_cout << "In vvid_live_stereo_manager::setup_views() -"
00106 << " bad camera initialization\n";
00107 return;
00108 }
00109 this->add_at(vgui_viewer2D_tableau_new(vf), 1,i);
00110 }
00111
00112 it_ = vgui_image_tableau_new();
00113 v2D_ = vgui_viewer2D_tableau_new(it_);
00114 this->add_at(v2D_, 0,0);
00115 }
00116
00117 void vvid_live_stereo_manager::run_frames()
00118 {
00119 if (!init_successful_)
00120 return;
00121 while (live_capture_){
00122 for (int i=0; i<N_views_; i++)
00123 vframes_[i]->update_frame();
00124
00125 if (!cp_.rgb_&&N_views_==2)
00126 {
00127 vil1_memory_image_of<unsigned char> i1, i2;
00128 vil1_memory_image_of<vil1_rgb<unsigned char> > im;
00129
00130 video_process_->clear_input();
00131
00132 if (vframes_[0]->get_current_mono_image(2,i1))
00133 video_process_->add_input_image(i1);
00134 else return;
00135 if (vframes_[1]->get_current_mono_image(2,i2))
00136 video_process_->add_input_image(i2);
00137 else
00138 return;
00139 if (video_process_->execute())
00140 it_->set_image(video_process_->get_output_image());
00141 else
00142 return;
00143 }
00144 v2D_->post_redraw();
00145 vgui::run_till_idle();
00146 }
00147 }
00148
00149 void vvid_live_stereo_manager::start_live_video()
00150 {
00151 if (!init_successful_)
00152 this->setup_views();
00153 if (!init_successful_)
00154 return;
00155
00156 for (int i=0; i<N_views_; i++)
00157 vframes_[i]->start_live_video();
00158
00159 live_capture_=true;
00160 this->run_frames();
00161 }
00162
00163 void vvid_live_stereo_manager::stop_live_video()
00164 {
00165 live_capture_=false;
00166 if (!init_successful_)
00167 return;
00168 for (int i=0; i<N_views_; i++)
00169 vframes_[i]->stop_live_video();
00170 }
00171
00172 void vvid_live_stereo_manager::quit()
00173 {
00174 this->stop_live_video();
00175 vcl_exit(1);
00176 }
00177
00178 bool
00179 vvid_live_stereo_manager::get_current_rgb_image(int view_no,
00180 int pix_sample_interval,
00181 vil1_memory_image_of< vil1_rgb<unsigned char> >& im)
00182 {
00183 if (!init_successful_)
00184 return false;
00185 if (vframes_.size()< view_no+1)
00186 {
00187 vcl_cout << "In vvid_live_video_manger::get_current_rgb_imge(..) -"
00188 << " view_no out of range\n";
00189 return false;
00190 }
00191
00192 return vframes_[view_no]->get_current_rgb_image(pix_sample_interval, im);
00193 }
00194
00195 bool vvid_live_stereo_manager::
00196 get_current_mono_image(int view_no, int pix_sample_interval,
00197 vil1_memory_image_of<unsigned char>& im)
00198 {
00199 if (!init_successful_)
00200 return false;
00201 if (vframes_.size()< view_no+1)
00202 {
00203 vcl_cout << "In vvid_live_video_manger::get_current_mono_imge(..) -"
00204 << " view_no out of range\n";
00205 return false;
00206 }
00207
00208 return vframes_[view_no]->get_current_mono_image(pix_sample_interval, im);
00209 }
00210
00211 void vvid_live_stereo_manager::
00212 set_process_rgb_image(vil1_memory_image_of< vil1_rgb<unsigned char> >& im)
00213 {
00214 process_rgb_ = im;
00215 }
00216
00217 void vvid_live_stereo_manager::
00218 set_process_mono_image(vil1_memory_image_of<unsigned char>& im)
00219 {
00220 process_mono_ = im;
00221 }