00001
00002 #include "vvid_file_manager.h"
00003
00004
00005
00006
00007 #include <vcl_vector.h>
00008 #include <vcl_iostream.h>
00009 #include <vul/vul_timer.h>
00010 #include <vil1/vil1_image.h>
00011 #include <vil1/vil1_save.h>
00012 #include <vil1/vil1_memory_image_of.h>
00013 #include <vidl_vil1/vidl_vil1_movie.h>
00014 #include <vidl_vil1/vidl_vil1_clip.h>
00015 #include <vidl_vil1/vidl_vil1_io.h>
00016 #include <vidl_vil1/vidl_vil1_frame.h>
00017 #include <vgui/vgui.h>
00018 #include <vgui/vgui_error_dialog.h>
00019 #include <vgui/vgui_adaptor.h>
00020 #include <vgui/vgui_dialog.h>
00021 #include <vgui/vgui_utils.h>
00022 #include <vgui/vgui_shell_tableau.h>
00023 #include <vgui/vgui_style_sptr.h>
00024 #include <vgui/vgui_style.h>
00025 #include <bgui/bgui_image_tableau.h>
00026 #include <bgui/bgui_vtol2D_tableau.h>
00027 #include <bgui/bgui_picker_tableau.h>
00028 #include <bgui/bgui_bargraph_clipon_tableau.h>
00029 #include <vgui/vgui_viewer2D_tableau.h>
00030 #include <vgui/vgui_grid_tableau.h>
00031 #include <vgui/vgui_image_tableau.h>
00032 #include <vgui/vgui_rubberband_tableau.h>
00033 #include <bgui/bgui_vtol2D_rubberband_client.h>
00034 #include <vgui/vgui_composite_tableau.h>
00035 #include <vsol/vsol_point_2d.h>
00036 #include <vtol/vtol_face_2d.h>
00037 #include <brip/brip_vil1_float_ops.h>
00038 #include <bsol/bsol_algs.h>
00039 #include <btol/btol_face_algs.h>
00040 #include <sdet/sdet_harris_detector_params.h>
00041 #include <sdet/sdet_detector_params.h>
00042 #include <sdet/sdet_fit_lines_params.h>
00043 #include <sdet/sdet_grid_finder_params.h>
00044 #include <strk/strk_tracker_params.h>
00045 #include <strk/strk_info_tracker_params.h>
00046 #include <strk/strk_info_model_tracker_params.h>
00047 #include <strk/strk_art_info_model.h>
00048 #include <vpro/vpro_frame_diff_process.h>
00049 #include <vpro/vpro_motion_process.h>
00050 #include <vpro/vpro_lucas_kanade_process.h>
00051 #include <vpro/vpro_harris_corner_process.h>
00052 #include <vpro/vpro_edge_process.h>
00053 #include <vpro/vpro_edge_line_process.h>
00054 #include <vpro/vpro_grid_finder_process.h>
00055 #include <strk/strk_corr_tracker_process.h>
00056 #include <strk/strk_info_model_tracker_process.h>
00057 #include <strk/strk_info_tracker_process.h>
00058 #include <strk/strk_track_display_process.h>
00059 #include <strk/strk_feature_capture_process.h>
00060 #include <strk/strk_snippet_extractor_process.h>
00061 #include <vpro/vpro_basis_generator_process.h>
00062 #include <vpro/vpro_fourier_process.h>
00063 #include <vpro/vpro_spatial_filter_process.h>
00064 #include <strk/strk_art_model_display_process.h>
00065 #include <vpro/vpro_ihs_process.h>
00066 #include <vpro/vpro_half_res_process.h>
00067 #include <strk/strk_io.h>
00068
00069 vvid_file_manager *vvid_file_manager::instance_ = 0;
00070
00071
00072 vvid_file_manager *vvid_file_manager::instance()
00073 {
00074 if (!instance_)
00075 {
00076 instance_ = new vvid_file_manager();
00077 instance_->init();
00078 }
00079 return vvid_file_manager::instance_;
00080 }
00081
00082
00083
00084
00085 void vvid_file_manager::init()
00086 {
00087 grid_ = vgui_grid_tableau_new(2,1);
00088 grid_->set_grid_size_changeable(true);
00089
00090
00091 itab0_ = bgui_image_tableau_new();
00092 easy0_ = bgui_vtol2D_tableau_new(itab0_);
00093 bgui_vtol2D_rubberband_client* cl0 = new bgui_vtol2D_rubberband_client(easy0_);
00094
00095 rubber0_ = vgui_rubberband_tableau_new(cl0);
00096 vgui_composite_tableau_new comp0(easy0_,rubber0_);
00097 picktab0_ = bgui_picker_tableau_new(comp0);
00098 v2D0_ = vgui_viewer2D_tableau_new(picktab0_);
00099 grid_->add_at(v2D0_, 0,0);
00100
00101 itab1_ = bgui_image_tableau_new();
00102 easy1_ = bgui_vtol2D_tableau_new(itab1_);
00103 v2D1_ = vgui_viewer2D_tableau_new(easy1_);
00104 grid_->add_at(v2D1_, 1,0);
00105 vgui_shell_tableau_sptr shell = vgui_shell_tableau_new(grid_);
00106 this->add_child(shell);
00107 bargraph_ = 0;
00108
00109
00110
00111
00112
00113 stem_ = 0;
00114 long_tip_ =0;
00115 short_tip_=0;
00116 art_model_=0;
00117 background_model_ = 0;
00118 display_frame_repeat_=1;
00119 display_frame_skip_=0;
00120 skip_counter_=0;
00121 start_frame_ = 0;
00122 end_frame_ = 0;
00123 on_style_ = vgui_style::new_style(0.0, 1.0, 0.0, 3.0, 4.0);
00124 off_style_ = vgui_style::new_style(1.0, 0.0, 0.0, 3.0, 4.0);
00125 }
00126
00127
00128
00129
00130 vvid_file_manager::vvid_file_manager(): vgui_wrapper_tableau()
00131 {
00132 width_ = 512;
00133 height_ = 512;
00134 track_ = false;
00135 color_label_ = false;
00136 window_ = 0;
00137 frame_trail_.clear();
00138 my_movie_=(vidl_vil1_movie*)0;
00139 win_ = 0;
00140 cache_frames_ = false;
00141 save_display_ = false;
00142 play_video_ = true;
00143 pause_video_ = false;
00144 next_frame_ = false;
00145 prev_frame_ = false;
00146 save_display_ = false;
00147 overlay_pane_ = true;
00148 time_interval_ = 10.0;
00149 video_process_ = 0;
00150 art_model_ = 0;
00151 display_frame_repeat_=1;
00152 display_frame_skip_=0;
00153 skip_counter_=0;
00154 }
00155
00156 vvid_file_manager::~vvid_file_manager()
00157 {
00158 }
00159
00160
00161
00162
00163 bool vvid_file_manager::handle(const vgui_event &e)
00164 {
00165 return this->child.handle(e);
00166 }
00167
00168
00169 void vvid_file_manager::quit()
00170 {
00171 vgui::quit();
00172 }
00173
00174
00175
00176 void vvid_file_manager::display_image()
00177 {
00178 if (!video_process_)
00179 return;
00180 if (itab1_)
00181 itab1_->set_image(video_process_->get_output_image());
00182 }
00183
00184
00185
00186
00187 void vvid_file_manager::display_spatial_objects()
00188 {
00189 static bool toggle = false;
00190 if (!video_process_)
00191 return;
00192 vcl_vector<vsol_spatial_object_2d_sptr> const& sos =
00193 video_process_->get_output_spatial_objects();
00194 if (easy0_)
00195 {
00196
00197 if (color_label_)
00198 {
00199 float r,g,b;
00200
00201 if (track_)
00202 {
00203 frame_trail_.add_spatial_objects(sos);
00204 vcl_vector<vsol_spatial_object_2d_sptr> temp;
00205 frame_trail_.get_spatial_objects(temp);
00206 for (unsigned int i=0;i<temp.size();i++) {
00207 set_changing_colors( temp[i]->get_tag_id() , &r, &g, &b );
00208 vgui_style_sptr style = vgui_style::new_style(r, g, b, 1.0, 2.0);
00209 easy0_->set_vsol_spatial_object_2d_style(temp[i], style );
00210 easy0_->add_spatial_object(temp[i]);
00211 }
00212 }
00213 else
00214 {
00215 for (unsigned int i=0;i<sos.size();i++) {
00216 set_changing_colors( sos[i]->get_tag_id() , &r, &g, &b );
00217 #ifdef DEBUG
00218 vcl_cout<<'('<<sos[i]->get_tag_id()<<")\n";
00219 #endif
00220 vgui_style_sptr style = vgui_style::new_style(r, g, b, 1.0, 2.0);
00221 easy0_->set_vsol_spatial_object_2d_style(sos[i], style );
00222 easy0_->add_spatial_object(sos[i]);
00223 }
00224 }
00225 }
00226 else
00227 {
00228
00229 if (track_)
00230 {
00231 frame_trail_.add_spatial_objects(sos);
00232 vcl_vector<vsol_spatial_object_2d_sptr> temp;
00233 frame_trail_.get_spatial_objects(temp);
00234 easy0_->add_spatial_objects(temp);
00235 }
00236 else
00237 {
00238 if (toggle)
00239 {
00240 easy0_->add_spatial_objects(sos, off_style_);
00241 toggle = !toggle;
00242 }
00243 else
00244 {
00245 easy0_->add_spatial_objects(sos, on_style_);
00246 toggle = !toggle;
00247 }
00248 }
00249 }
00250 }
00251 }
00252
00253
00254
00255 void vvid_file_manager::set_changing_colors(int num, float *r, float *g, float *b)
00256 {
00257 int strength = num/6;
00258 int pattern = num%6;
00259 strength %= 20;
00260 float s = 1.0f - strength * 0.05f;
00261
00262 switch (pattern)
00263 {
00264 case 0 : (*r) = s; (*g) = 0; (*b) = 0; break;
00265 case 1 : (*r) = 0; (*g) = s; (*b) = 0; break;
00266 case 2 : (*r) = 0; (*g) = 0; (*b) = s; break;
00267 case 3 : (*r) = s; (*g) = s; (*b) = 0; break;
00268 case 4 : (*r) = 0; (*g) = s; (*b) = s; break;
00269 case 5 : (*r) = s; (*g) = 0; (*b) = s; break;
00270 default: (*r) = 0; (*g) = 0; (*b) = 0; break;
00271 }
00272 #ifdef DEBUG
00273 vcl_cout<<"color : "<<(*r)<<" : "<<(*g)<<" : "<<(*b)<<'\n';
00274 #endif
00275
00276 return;
00277 }
00278
00279
00280
00281
00282
00283 void vvid_file_manager::display_topology()
00284 {
00285 if (!easy0_)
00286 return;
00287 vul_timer t;
00288 vcl_vector<vtol_topology_object_sptr> const & topos =
00289 video_process_->get_output_topology();
00290 easy0_->clear_all();
00291
00292 if (track_)
00293 {
00294 frame_trail_.add_topology_objects(topos);
00295 vcl_vector<vtol_topology_object_sptr> temp;
00296 frame_trail_.get_topology_objects(temp);
00297 easy0_->add_topology_objects(temp);
00298 }
00299 else
00300 easy0_->add_topology_objects(topos);
00301 #ifdef DEBUG
00302 vcl_cout << "display " << topos.size()
00303 << " topology objs in " << t.real() << " msecs.\n";
00304 #endif
00305 easy0_->post_redraw();
00306 }
00307
00308 void vvid_file_manager::display_bargraph(vcl_vector<float> const& data)
00309 {
00310 if (!bargraph_)
00311 return;
00312 bargraph_->update(data);
00313 }
00314
00315
00316
00317
00318 void vvid_file_manager::load_video_file()
00319 {
00320 play_video_ = true;
00321 pause_video_ = false;
00322 next_frame_ = false;
00323 prev_frame_ = false;
00324 save_display_ = false;
00325 video_process_ = 0;
00326 frame_trail_.clear();
00327 vgui_dialog load_video_dlg("Load video file");
00328 static vcl_string image_filename = "";
00329 static vcl_string ext = "";
00330 load_video_dlg.file("Filename:", ext, image_filename);
00331 load_video_dlg.checkbox("Cache Frames ", cache_frames_);
00332 if (!load_video_dlg.ask())
00333 return;
00334
00335 my_movie_ = vidl_vil1_io::load_movie(image_filename.c_str());
00336 if (!my_movie_) {
00337 vgui_error_dialog("Failed to load movie file");
00338 return;
00339 }
00340 tabs_.clear();
00341 int n_frames = my_movie_->length();
00342 start_frame_ = 0;
00343 end_frame_ = n_frames-1;
00344 vidl_vil1_movie::frame_iterator pframe = my_movie_->first();
00345 vil1_image img = pframe->get_image();
00346
00347 height_ = img.height();
00348 width_ = img.width();
00349 vcl_cout << "Video Height " << height_ << vcl_endl
00350 << "Video Width " << width_ << vcl_endl;
00351 if (win_)
00352 win_->reshape(2*width_, height_);
00353 int i = 0;
00354 if (cache_frames_)
00355 {
00356 for (pframe = my_movie_->first(); pframe!=my_movie_->last(); ++pframe)
00357 {
00358 vil1_image img = pframe->get_image();
00359 vgui_image_tableau_sptr itab = vgui_image_tableau_new(img);
00360 bgui_vtol2D_tableau_new e(itab);
00361 tabs_.push_back(e);
00362 vcl_cout << "Loading Frame [" << i << "]: (" <<width_ <<'x'<<height_ << ")\n";
00363 ++i;
00364 }
00365 v2D0_->child.assign(tabs_[0]);
00366 itab1_->set_image(tabs_[0]->get_image_tableau()->get_image());
00367 }
00368 else
00369 {
00370
00371
00372 #if 0
00373 itab1_->set_image(img);
00374 #endif
00375 itab0_->set_image(img);
00376 }
00377 grid_->post_redraw();
00378 vgui::run_till_idle();
00379 }
00380
00381
00382 void vvid_file_manager::cached_play()
00383 {
00384 vul_timer t;
00385 for (vcl_vector<bgui_vtol2D_tableau_sptr>::iterator vit = tabs_.begin();
00386 vit != tabs_.end()&&play_video_; vit++)
00387 {
00388
00389 if (pause_video_&&play_video_)
00390 {
00391 if (next_frame_&&vit!=tabs_.end()-2)
00392 {
00393 vit+=2;
00394 next_frame_ = false;
00395 }
00396 if (prev_frame_&&vit!=tabs_.begin()+2)
00397 {
00398 vit--;
00399 prev_frame_ = false;
00400 }
00401 vit--;
00402 }
00403
00404 v2D0_->child.assign(*vit);
00405
00406
00407 while (t.all()<time_interval_) ;
00408
00409 grid_->post_redraw();
00410 vgui::run_till_idle();
00411 t.mark();
00412 }
00413 }
00414
00415
00416 void vvid_file_manager::un_cached_play()
00417 {
00418 if (!my_movie_)
00419 {
00420 vcl_cout << "No movie has been loaded\n";
00421 return;
00422 }
00423 if (video_process_)
00424 video_process_->set_n_frames(my_movie_->length());
00425 vidl_vil1_movie::frame_iterator pframe = my_movie_->begin();
00426 vidl_vil1_movie::frame_iterator lframe = pframe;
00427 pframe += start_frame_;
00428 lframe += end_frame_+1;
00429 for ( ; pframe!=my_movie_->end() && pframe!=lframe && play_video_; ++pframe)
00430 {
00431 int frame_index = pframe->get_real_frame_index();
00432 vgui::out << "frame["<< frame_index <<"]\n";
00433 vil1_image img = pframe->get_image();
00434 itab0_->set_image(img);
00435
00436 if (pause_video_)
00437 {
00438 if (next_frame_)
00439 {
00440 if (pframe!=my_movie_->last()) ++pframe;
00441 next_frame_ = false;
00442 }
00443 if (prev_frame_)
00444 {
00445 if (pframe!=my_movie_->first()) --pframe;
00446 prev_frame_ = false;
00447 }
00448
00449 --pframe;
00450 }
00451 else if (video_process_)
00452 {
00453 video_process_->set_frame_index(frame_index);
00454 vil1_memory_image_of<unsigned char> image(img);
00455 video_process_->add_input_image(image);
00456 if (video_process_->execute())
00457 {
00458 if (video_process_->get_output_type()==vpro_video_process::SPATIAL_OBJECT)
00459 display_spatial_objects();
00460 else if (video_process_->get_output_type()==vpro_video_process::IMAGE)
00461 display_image();
00462 else if (video_process_->get_output_type()==vpro_video_process::TOPOLOGY)
00463 display_topology();
00464 if (video_process_->graph_flag())
00465 {
00466 vcl_vector<float> const& data = video_process_->graph();
00467 this->display_bargraph(data);
00468 }
00469 }
00470 }
00471 grid_->post_redraw();
00472 vgui::run_till_idle();
00473 this->save_display(frame_index);
00474 }
00475
00476 if (video_process_)
00477 video_process_->finish();
00478 bargraph_= 0;
00479 easy1_->clear();
00480 if (save_display_)
00481 this->end_save_display();
00482 save_display_ = false;
00483 }
00484
00485 void vvid_file_manager::play_video()
00486 {
00487 play_video_ = true;
00488 pause_video_ = false;
00489 time_interval_ = 10.0;
00490 easy0_->clear_all();
00491 frame_trail_.clear();
00492
00493
00494 if (cache_frames_)
00495 {
00496 this->cached_play();
00497 v2D0_->child.assign(tabs_[0]);
00498 }
00499 else
00500 {
00501 this->un_cached_play();
00502 if (!my_movie_)
00503 return;
00504
00505 if (video_process_&&video_process_->get_output_image())
00506 itab1_->set_image(video_process_->get_output_image());
00507 else
00508 #if 0
00509 itab1_->set_image(my_movie_->get_image(0));
00510 #endif
00511 {
00512 vil1_image null;
00513 itab1_->set_image(null);
00514 }
00515 }
00516 this->post_redraw();
00517 }
00518
00519
00520
00521
00522 void vvid_file_manager::stop_video()
00523 {
00524 play_video_ = false;
00525 }
00526
00527
00528 void vvid_file_manager::pause_video()
00529 {
00530 pause_video_ =!pause_video_;
00531
00532 time_interval_ = 50.0;
00533 }
00534
00535 void vvid_file_manager::start_frame()
00536 {
00537 vgui_dialog frame_dlg("Start Frame");
00538 frame_dlg.field("Frame No.", start_frame_);
00539 if (!frame_dlg.ask())
00540 return;
00541 }
00542
00543 void vvid_file_manager::end_frame()
00544 {
00545 vgui_dialog frame_dlg("End Frame");
00546 frame_dlg.field("Frame No.", end_frame_);
00547 if (!frame_dlg.ask())
00548 return;
00549 }
00550
00551
00552
00553 void vvid_file_manager::next_frame()
00554 {
00555 next_frame_ = true;
00556 }
00557
00558
00559 void vvid_file_manager::prev_frame()
00560 {
00561 prev_frame_ = true;
00562 }
00563
00564 void vvid_file_manager::set_speed()
00565 {
00566
00567 }
00568
00569 void vvid_file_manager::easy2D_tableau_demo()
00570 {
00571 int inc = 40;
00572 for (vcl_vector<bgui_vtol2D_tableau_sptr>::iterator eit = tabs_.begin();
00573 eit != tabs_.end(); eit++, ++inc)
00574 {
00575 (*eit)->clear();
00576 (*eit)->set_foreground(0,1,1);
00577 (*eit)->set_point_radius(5);
00578 if (inc>60)
00579 inc = 40;
00580 for (unsigned int j = 0; j<=height_; j+=inc)
00581 for (unsigned int k=0; k<=width_; k+=inc)
00582 (*eit)->add_point(k,j);
00583 }
00584 }
00585
00586 void vvid_file_manager::no_op()
00587 {
00588 video_process_ = 0;
00589 }
00590
00591 void vvid_file_manager::difference_frames()
00592 {
00593 static vpro_frame_diff_params fdp;
00594 vgui_dialog frame_diff_dialog("Frame_Diff Params");
00595 frame_diff_dialog.field("Display Scale Range", fdp.range_);
00596 if (!frame_diff_dialog.ask())
00597 return;
00598 video_process_ = new vpro_frame_diff_process(fdp);
00599 }
00600
00601 void vvid_file_manager::compute_motion()
00602 {
00603 static vpro_motion_params vmp;
00604 vgui_dialog motion_dialog("Motion Params");
00605 motion_dialog.field("Low Range", vmp.low_range_);
00606 motion_dialog.field("High Range", vmp.high_range_);
00607 motion_dialog.field("Smooth Sigma", vmp.smooth_sigma_);
00608 if (!motion_dialog.ask())
00609 return;
00610
00611 video_process_ = new vpro_motion_process(vmp);
00612 }
00613
00614 void vvid_file_manager::compute_lucas_kanade()
00615 {
00616 static bool downsample = false;
00617 static int windowsize=2;
00618 static double thresh=20000;
00619 vgui_dialog downsample_dialog("Lucas-Kanade Params");
00620 downsample_dialog.checkbox("Downsample", downsample);
00621 downsample_dialog.field("WindowSize(2n+1) n=",windowsize);
00622 downsample_dialog.field("Motion Factor Threshold", thresh);
00623
00624 if (!downsample_dialog.ask())
00625 return;
00626 video_process_ = new vpro_lucas_kanade_process(downsample,windowsize,thresh);
00627 }
00628
00629 void vvid_file_manager::compute_harris_corners()
00630 {
00631 static int track_window;
00632 static sdet_harris_detector_params hdp;
00633 vgui_dialog harris_dialog("harris");
00634 harris_dialog.field("sigma", hdp.sigma_);
00635 harris_dialog.field("thresh", hdp.thresh_);
00636 harris_dialog.field("N = 2n+1, (n)", hdp.n_);
00637 harris_dialog.field("Max No.Corners(percent)", hdp.percent_corners_);
00638 harris_dialog.field("scale_factor", hdp.scale_factor_);
00639 harris_dialog.checkbox("Tracks", track_);
00640 harris_dialog.field("Window", track_window);
00641
00642 if (!harris_dialog.ask())
00643 return;
00644
00645 video_process_ = new vpro_harris_corner_process(hdp);
00646 if (track_)
00647 {
00648 frame_trail_.clear();
00649 frame_trail_.set_window(track_window);
00650 }
00651 }
00652
00653 void vvid_file_manager::compute_vd_edges()
00654 {
00655 static int track_window;
00656 static bool agr = false;
00657 static sdet_detector_params dp;
00658 vgui_dialog det_dialog("Video Edges");
00659 det_dialog.field("Gaussian sigma", dp.smooth);
00660 det_dialog.field("Noise Threshold", dp.noise_multiplier);
00661 det_dialog.checkbox("Automatic Threshold", dp.automatic_threshold);
00662 det_dialog.checkbox("Agressive Closure", agr);
00663 det_dialog.checkbox("Compute Junctions", dp.junctionp);
00664 det_dialog.checkbox("Tracks", track_);
00665 det_dialog.field("Window", track_window);
00666
00667 if (!det_dialog.ask())
00668 return;
00669
00670 if (agr)
00671 dp.aggressive_junction_closure=1;
00672 else
00673 dp.aggressive_junction_closure=0;
00674
00675 video_process_ = new vpro_edge_process(dp);
00676 if (track_)
00677 {
00678 frame_trail_.clear();
00679 frame_trail_.set_window(track_window);
00680 }
00681 }
00682
00683 void vvid_file_manager::compute_line_fit()
00684 {
00685 static bool agr = false;
00686 static sdet_detector_params dp;
00687 dp.borderp = false;
00688 static sdet_fit_lines_params flp;
00689 vgui_dialog line_dialog("Video Line Segments");
00690 line_dialog.field("Gaussian sigma", dp.smooth);
00691 line_dialog.field("Noise Threshold", dp.noise_multiplier);
00692 line_dialog.checkbox("Automatic Threshold", dp.automatic_threshold);
00693 line_dialog.checkbox("Agressive Closure", agr);
00694 line_dialog.checkbox("Compute Junctions", dp.junctionp);
00695 line_dialog.field("Min Fit Length", flp.min_fit_length_);
00696 line_dialog.field("RMS Distance", flp.rms_distance_);
00697 if (!line_dialog.ask())
00698 return;
00699
00700 if (agr)
00701 dp.aggressive_junction_closure=1;
00702 else
00703 dp.aggressive_junction_closure=0;
00704
00705 video_process_ = new vpro_edge_line_process(dp, flp);
00706 }
00707
00708 void vvid_file_manager::compute_grid_match()
00709 {
00710 static bool agr = false;
00711 static sdet_detector_params dp;
00712 dp.borderp = false;
00713 static sdet_fit_lines_params flp;
00714 static sdet_grid_finder_params gfp;
00715
00716 dp.noise_multiplier=4;
00717 flp.min_fit_length_=10;
00718 flp.rms_distance_=0.05;
00719 gfp.angle_tol_ = 3.0;
00720 vgui_dialog grid_dialog("Grid Match");
00721 grid_dialog.field("Gaussian sigma", dp.smooth);
00722 grid_dialog.field("Noise Threshold", dp.noise_multiplier);
00723 grid_dialog.checkbox("Automatic Threshold", dp.automatic_threshold);
00724 grid_dialog.checkbox("Agressive Closure", agr);
00725 grid_dialog.checkbox("Compute Junctions", dp.junctionp);
00726 grid_dialog.field("Min Fit Length", flp.min_fit_length_);
00727 grid_dialog.field("RMS Distance", flp.rms_distance_);
00728 grid_dialog.field("Angle Tolerance", gfp.angle_tol_);
00729 grid_dialog.field("Line Count Threshold", gfp.thresh_);
00730
00731
00732 if (!grid_dialog.ask())
00733 return;
00734
00735 if (agr)
00736 dp.aggressive_junction_closure=1;
00737 else
00738 dp.aggressive_junction_closure=0;
00739
00740 video_process_ = new vpro_grid_finder_process(dp, flp, gfp);
00741 }
00742
00743 void vvid_file_manager::compute_corr_tracking()
00744 {
00745 static strk_tracker_params tp;
00746 vgui_dialog tracker_dialog("Correlation Tracker ");
00747 tracker_dialog.field("Number of Samples", tp.n_samples_);
00748 tracker_dialog.field("Search Radius", tp.search_radius_);
00749 tracker_dialog.field("Smooth Sigma", tp.sigma_);
00750 if (!tracker_dialog.ask())
00751 return;
00752 vcl_cout << tp << '\n';
00753 vtol_topology_object_sptr to = easy0_->get_temp();
00754 if (!to)
00755 vcl_cout << "In vvid_file_manager::compute_corr_tracking() - no model\n";
00756 else
00757 {
00758 video_process_ = new strk_corr_tracker_process(tp);
00759 video_process_->add_input_topology_object(to);
00760 }
00761 }
00762
00763 void vvid_file_manager::compute_info_tracking()
00764 {
00765 static bool output_track = false;
00766 static bool output_hist = false;
00767 static bool display_hist = false;
00768 static strk_info_tracker_params tp;
00769 vgui_dialog tracker_dialog("Mutual Information Tracker V1.6");
00770 tracker_dialog.field("Number of Samples", tp.n_samples_);
00771 tracker_dialog.field("Search Radius", tp.search_radius_);
00772 tracker_dialog.field("Angle Range (radians)", tp.angle_range_);
00773 tracker_dialog.field("Scale Range (1+-s)", tp.scale_range_);
00774 tracker_dialog.field("Smooth Sigma", tp.sigma_);
00775 tracker_dialog.field("Min Gradient Mag", tp.min_gradient_);
00776 tracker_dialog.field("Parzen Sigma", tp.parzen_sigma_);
00777 tracker_dialog.checkbox("Model Background", tp.use_background_);
00778 tracker_dialog.checkbox("Add Gradient Info", tp.gradient_info_);
00779 tracker_dialog.checkbox("Add Color Info", tp.color_info_);
00780 tracker_dialog.checkbox("Renyi Joint Entropy", tp.renyi_joint_entropy_);
00781 tracker_dialog.checkbox("Output Track Data", output_track);
00782 tracker_dialog.checkbox("Output Feature Data", output_hist);
00783 tracker_dialog.checkbox("Display Histograms", display_hist);
00784 tracker_dialog.checkbox("Verbose", tp.verbose_);
00785 tracker_dialog.checkbox("Debug", tp.debug_);
00786 if (!tracker_dialog.ask())
00787 return;
00788 static vcl_string track_file, hist_file;
00789 if (output_track)
00790 {
00791 vgui_dialog output_dialog("Track Data File");
00792 static vcl_string ext = "*.*";
00793 output_dialog.file("Track File:", ext, track_file);
00794 if (!output_dialog.ask())
00795 return;
00796 }
00797 if (output_hist)
00798 {
00799 vgui_dialog hist_dialog("Feature Data File");
00800 static vcl_string ext = "*.*";
00801 hist_dialog.file("Feature File:", ext, hist_file);
00802 if (!hist_dialog.ask())
00803 return;
00804 }
00805 vcl_cout << tp << '\n';
00806 vtol_topology_object_sptr to = easy0_->get_temp();
00807 if (!to)
00808 vcl_cout << "In vvid_file_manager::compute_info_tracking() - no model\n";
00809 else
00810 {
00811 strk_info_tracker_process* vitp = new strk_info_tracker_process(tp);
00812 video_process_ = vitp;
00813 video_process_->add_input_topology_object(to);
00814 if (tp.use_background_) {
00815 if (!background_model_)
00816 vcl_cout << "In vvid_file_manager::compute_info_tracking() -"
00817 << " no background model\n";
00818 else
00819 video_process_->add_input_topology_object(background_model_->cast_to_topology_object());
00820 }
00821 if (output_track)
00822 if (!vitp->set_track_output_file(track_file))
00823 return;
00824 if (output_hist)
00825 if (!vitp->set_hist_output_file(hist_file))
00826 return;
00827 if (display_hist)
00828 {
00829 vgui_easy2D_tableau_sptr easy;
00830 easy.vertical_cast(easy1_);
00831 bargraph_ = new bgui_bargraph_clipon_tableau(easy);
00832 bargraph_->set_color_vector(vitp->color_index());
00833 }
00834 }
00835 }
00836
00837 void vvid_file_manager::save_display(int )
00838 {
00839 if (!save_display_)
00840 return;
00841
00842 if (display_frame_skip_) {
00843 if (skip_counter_>0)
00844 {
00845 --skip_counter_;
00846 return;
00847 }
00848 else
00849 skip_counter_ = display_frame_skip_;
00850 }
00851
00852 if (!overlay_pane_)
00853 {
00854 vil1_image image = itab1_->get_image();
00855 if (!image)
00856 return;
00857 display_output_frames_.push_back(image);
00858 return;
00859 }
00860
00861 vil1_memory_image_of<vil1_rgb<unsigned char> >
00862 temp = vgui_utils::colour_buffer_to_image();
00863 for (int i = 0; i<display_frame_repeat_; i++)
00864 display_output_frames_.push_back(temp);
00865 }
00866
00867 void vvid_file_manager::display_poly_track()
00868 {
00869 start_frame_ = 0;
00870 if (my_movie_)
00871 end_frame_ = my_movie_->length()-1;
00872 else
00873 end_frame_=0;
00874 vgui_dialog output_dialog("Track Data File(sets start frame)");
00875 static vcl_string track_file;
00876 static vcl_string trk_ext = "trk", out_ext = "out";
00877 output_dialog.file("Track File:", trk_ext, track_file);
00878 if (!output_dialog.ask())
00879 return;
00880 strk_track_display_process* vtd = new strk_track_display_process();
00881 video_process_ = vtd;
00882 vtd->set_input_file(track_file);
00883 start_frame_ = vtd->start_frame();
00884 end_frame_ = vtd->end_frame();
00885 }
00886
00887 void vvid_file_manager::generate_basis_sequence()
00888 {
00889 vgui_dialog output_dialog("Image Basis Generator");
00890 static vcl_string basis_file;
00891 static vcl_string ext = "*.*";
00892 output_dialog.file("Basis File:", ext, basis_file);
00893 if (!output_dialog.ask())
00894 return;
00895 video_process_ = new vpro_basis_generator_process(basis_file);
00896 }
00897
00898 void vvid_file_manager::compute_fourier_transform()
00899 {
00900 static vpro_fourier_params vfp;
00901 vgui_dialog fourier_dialog("Fourier Params");
00902 fourier_dialog.field("Display Scale Range", vfp.range_);
00903 if (!fourier_dialog.ask())
00904 return;
00905 video_process_ = new vpro_fourier_process(vfp);
00906 }
00907
00908 void vvid_file_manager::spatial_filter()
00909 {
00910 static vpro_spatial_filter_params vsfp;
00911 vgui_dialog spatial_filter_dialog("Spatial_Filter Params");
00912 spatial_filter_dialog.field("X Dir", vsfp.dir_fx_);
00913 spatial_filter_dialog.field("Y Dir", vsfp.dir_fy_);
00914 spatial_filter_dialog.field("Center Freq", vsfp.f0_);
00915 spatial_filter_dialog.field("Filter Radius", vsfp.radius_);
00916 spatial_filter_dialog.checkbox("Show Filtered Fourier Magnitude",
00917 vsfp.show_filtered_fft_);
00918 if (!spatial_filter_dialog.ask())
00919 return;
00920 video_process_ = new vpro_spatial_filter_process(vsfp);
00921 }
00922
00923 void vvid_file_manager::create_box()
00924 {
00925 rubber0_->rubberband_box();
00926 }
00927
00928 void vvid_file_manager::create_polygon()
00929 {
00930 rubber0_->rubberband_polygon();
00931 }
00932
00933 void vvid_file_manager::start_save_display()
00934 {
00935 save_display_ = true;
00936 skip_counter_ = display_frame_skip_;
00937 display_output_frames_.clear();
00938 vgui_dialog output_dialog("Display Movie Output");
00939 static vcl_string ext = "avi";
00940 output_dialog.file("Movie File:", ext, display_output_file_);
00941 output_dialog.field("# Frame Repeats ", display_frame_repeat_);
00942 output_dialog.field("# Frame Skips ", display_frame_skip_);
00943 output_dialog.checkbox("Save Overlay Pane (left) (or Image Pane (right))", overlay_pane_);
00944 if (!output_dialog.ask())
00945 return;
00946 }
00947
00948 void vvid_file_manager::end_save_display()
00949 {
00950 if (!save_display_||!display_output_frames_.size())
00951 return;
00952 save_display_ = false;
00953 vidl_vil1_clip_sptr clip = new vidl_vil1_clip(display_output_frames_);
00954 vidl_vil1_movie_sptr mov= new vidl_vil1_movie();
00955 mov->add_clip(clip);
00956 vidl_vil1_io::save(mov.ptr(), display_output_file_.c_str(), "AVI");
00957 display_output_frames_.clear();
00958 }
00959
00960 void vvid_file_manager::create_stem()
00961 {
00962 vcl_cout << "Make the stem ...\n";
00963 art_model_ = 0;
00964 vtol_topology_object_sptr to = easy0_->get_temp();
00965 if (!to)
00966 {
00967 vcl_cout << "Failed\n";
00968 return;
00969 }
00970 else
00971 vcl_cout << "Stem complete\n";
00972 stem_ = to->cast_to_face()->cast_to_face_2d();
00973 }
00974
00975 void vvid_file_manager::create_long_arm_tip()
00976 {
00977 vcl_cout << "Make the long_arm_tip ...\n";
00978 art_model_ = 0;
00979 vtol_topology_object_sptr to = easy0_->get_temp();
00980 if (!to)
00981 {
00982 vcl_cout << "Failed\n";
00983 return;
00984 }
00985 else
00986 vcl_cout << "long_arm_tip complete\n";
00987 long_tip_ = to->cast_to_face()->cast_to_face_2d();
00988 }
00989
00990 void vvid_file_manager::create_short_arm_tip()
00991 {
00992 vcl_cout << "Make the short_arm_tip ...\n";
00993 art_model_ = 0;
00994 vtol_topology_object_sptr to = easy0_->get_temp();
00995 if (!to)
00996 {
00997 vcl_cout << "Failed\n";
00998 return;
00999 }
01000 else
01001 vcl_cout << "short_arm_tip complete\n";
01002 short_tip_ = to->cast_to_face()->cast_to_face_2d();
01003 }
01004
01005 void vvid_file_manager::exercise_art_model()
01006 {
01007 if (!stem_||!long_tip_||!short_tip_)
01008 {
01009 vcl_cout << "Not enough components to make the art model\n";
01010 return;
01011 }
01012
01013 static bool refresh_model = false;
01014 static double stem_tx =0, stem_ty =0, stem_angle =0;
01015 static double long_arm_pivot_angle = 0, short_arm_pivot_angle =0;
01016 static double long_tip_angle = 0, short_tip_angle = 0;
01017
01018 vgui_dialog trans_art_dialog("Transform Art Model");
01019 trans_art_dialog.field(" Stem Tx", stem_tx);
01020 trans_art_dialog.field(" Stem Ty", stem_ty);
01021 trans_art_dialog.field(" Stem Angle", stem_angle);
01022 trans_art_dialog.field("Long Arm Pivot Angle",long_arm_pivot_angle);
01023 trans_art_dialog.field("Short Arm Pivot Angle",short_arm_pivot_angle);
01024 trans_art_dialog.field("Long Tip Angle", long_tip_angle);
01025 trans_art_dialog.field("Short Tip Angle", short_tip_angle);
01026 trans_art_dialog.checkbox("Refresh Model", refresh_model);
01027 if (!trans_art_dialog.ask())
01028 return;
01029
01030 if (refresh_model || !art_model_)
01031 {
01032 vcl_vector<vtol_face_2d_sptr> faces;
01033 vsol_point_2d_sptr pivot = btol_face_algs::centroid(stem_);
01034 faces.push_back(stem_);
01035 faces.push_back(long_tip_);
01036 faces.push_back(short_tip_);
01037 vil1_image img = itab0_->get_image();
01038 vil1_memory_image_of<float> image =
01039 brip_vil1_float_ops::convert_to_float(img);
01040 art_model_ = new strk_art_info_model(faces, pivot, image);
01041
01042 vcl_vector<vtol_face_2d_sptr> vtol_faces = art_model_->vtol_faces();
01043 easy0_->clear();
01044 easy0_->add_faces(vtol_faces);
01045 }
01046
01047 art_model_ = new strk_art_info_model(art_model_);
01048 art_model_->transform(stem_tx, stem_ty, stem_angle, long_arm_pivot_angle,
01049 short_arm_pivot_angle, long_tip_angle,
01050 short_tip_angle);
01051 easy0_->clear();
01052 vcl_vector<vtol_face_2d_sptr> new_faces = art_model_->vtol_faces();
01053 easy0_->add_faces(new_faces);
01054 easy0_->post_redraw();
01055 }
01056
01057
01058 void vvid_file_manager::track_art_model()
01059 {
01060 if (!stem_||!long_tip_||!short_tip_)
01061 {
01062 vcl_cout << "Not enough components to construct model\n";
01063 return;
01064 }
01065 vcl_vector<vtol_topology_object_sptr> faces;
01066 faces.push_back(stem_->cast_to_face());
01067 faces.push_back(long_tip_->cast_to_face());
01068 faces.push_back(short_tip_->cast_to_face());
01069
01070 static bool output_track = false;
01071 static strk_info_model_tracker_params imtp;
01072 vgui_dialog trans_art_dialog("Articulated Model Tracking");
01073 trans_art_dialog.field(" Number of Samples ", imtp.n_samples_);
01074 trans_art_dialog.field(" Stem Translation Radius ", imtp.stem_trans_radius_);
01075 trans_art_dialog.field(" Stem Angle Range", imtp.stem_angle_range_);
01076 trans_art_dialog.field("Long Arm Pivot Angle Range",
01077 imtp.long_arm_angle_range_);
01078 trans_art_dialog.field("Short Arm Pivot Angle Range",
01079 imtp.short_arm_angle_range_);
01080 trans_art_dialog.field("Long Arm Tip Angle Range",
01081 imtp.long_arm_tip_angle_range_);
01082 trans_art_dialog.field("Short Arm Tip Angle Range",
01083 imtp.short_arm_tip_angle_range_);
01084 trans_art_dialog.checkbox("Compute Gradient Info", imtp.gradient_info_);
01085 trans_art_dialog.checkbox("Output Track Data", output_track);
01086 trans_art_dialog.checkbox("Output Debug Messages", imtp.verbose_);
01087 if (!trans_art_dialog.ask())
01088 return;
01089 static vcl_string track_file;
01090 if (output_track)
01091 {
01092 vgui_dialog output_dialog("Track Data File");
01093 static vcl_string ext = "*.*";
01094 output_dialog.file("Track File:", ext, track_file);
01095 if (!output_dialog.ask())
01096 return;
01097 }
01098 vcl_cout << imtp << '\n';
01099 strk_info_model_tracker_process* imitp =
01100 new strk_info_model_tracker_process(imtp);
01101 video_process_ = imitp;
01102 video_process_->add_input_topology(faces);
01103 if (output_track)
01104 if (!imitp->set_output_file(track_file))
01105 return;
01106 }
01107
01108 void vvid_file_manager::display_art_model_track()
01109 {
01110 vgui_dialog output_dialog("Track Data File");
01111 static vcl_string track_file;
01112 static vcl_string trk_ext = "trk", out_ext = "out";
01113 output_dialog.file("Track File:", trk_ext, track_file);
01114 if (!output_dialog.ask())
01115 return;
01116 strk_art_model_display_process* vtd = new strk_art_model_display_process();
01117 video_process_ = vtd;
01118 vtd->set_input_file(track_file);
01119 }
01120
01121
01122 void vvid_file_manager::display_ihs()
01123 {
01124 video_process_ = new vpro_ihs_process();
01125 }
01126
01127 void vvid_file_manager::create_background_model()
01128 {
01129 vcl_cout << "Make the background model polygon ...\n";
01130 background_model_ = 0;
01131 vtol_topology_object_sptr to = easy0_->get_temp();
01132 if (!to)
01133 {
01134 vcl_cout << "Failed\n";
01135 return;
01136 }
01137 else
01138 vcl_cout << "Background model complete\n";
01139 background_model_ = to->cast_to_face()->cast_to_face_2d();
01140 }
01141
01142 void vvid_file_manager::save_frame()
01143 {
01144 vil1_image img = itab0_->get_image();
01145 if (!img)
01146 {
01147 vcl_cout << "In vvid_file_manager::save_frame() - no image\n";
01148 return;
01149 }
01150 vgui_dialog file_dialog("Frame Image File");
01151 static vcl_string image_file;
01152 static vcl_string ext = "tif";
01153 file_dialog.file("Track File:", ext, image_file);
01154 if (!file_dialog.ask())
01155 return;
01156 if (!vil1_save(img, image_file.c_str()))
01157 vcl_cout << "In vvid_file_manager::save_frame() - save failed\n";
01158 }
01159
01160 void vvid_file_manager::save_half_res()
01161 {
01162 vgui_dialog file_dialog("Half Resolution Output File");
01163 static vcl_string video_file;
01164 static vcl_string ext = "avi";
01165 file_dialog.file("Video File:", ext, video_file);
01166 if (!file_dialog.ask())
01167 return;
01168 vpro_half_res_process* hrp = new vpro_half_res_process(video_file);
01169 video_process_ = hrp;
01170 this->play_video();
01171 }
01172
01173
01174
01175 void vvid_file_manager::display_tracked_hist_data()
01176 {
01177 vgui_dialog hist_dlg("Histogram Track File");
01178 static vcl_string hist_filename = "";
01179 static vcl_string ext = "*.*";
01180 hist_dlg.file("Tracked Histogram filename:", ext, hist_filename);
01181 if (!hist_dlg.ask())
01182 return;
01183 vcl_ifstream hist_instr(hist_filename.c_str());
01184 unsigned int start_frame, n_frames, n_pixels;
01185 unsigned int n_int_bins, n_grad_dir_bins, n_color_bins;
01186 float diameter, aspect_ratio;
01187 vnl_matrix<float> hist_data;
01188 if (!strk_io::read_histogram_data(hist_instr, start_frame, n_frames,
01189 n_pixels, diameter, aspect_ratio,
01190 n_int_bins, n_grad_dir_bins, n_color_bins,
01191 hist_data))
01192 return;
01193 vil1_memory_image_of<float> temp =
01194 brip_vil1_float_ops::convert_to_float(hist_data);
01195 vil1_memory_image_of<unsigned char> image =
01196 brip_vil1_float_ops::convert_to_byte(temp);
01197 easy1_->get_image_tableau()->set_image(image);
01198 easy1_->post_redraw();
01199 vgui::run_till_idle();
01200 }
01201
01202
01203 void vvid_file_manager::capture_feature_data()
01204 {
01205 vgui_dialog file_dialog("Feature Capture From Track");
01206 static vcl_string track_file;
01207 static vcl_string hist_file;
01208 static vcl_string trk_ext = "trk", hist_ext = "hist";
01209 file_dialog.file("Track File(input):", trk_ext, track_file);
01210 file_dialog.file("Hist File(output):", hist_ext, hist_file);
01211 if (!file_dialog.ask())
01212 return;
01213 strk_info_tracker_params itp;
01214 itp.color_info_ = true;
01215 strk_feature_capture_process* fcp = new strk_feature_capture_process(itp);
01216 video_process_ = fcp;
01217 fcp->set_input_file(track_file);
01218 fcp->set_output_file(hist_file);
01219 start_frame_ = fcp->start_frame();
01220 end_frame_ = fcp->end_frame();
01221 }
01222
01223 void vvid_file_manager::capture_snippets()
01224 {
01225 vgui_dialog file_dialog("Snippet Capture From Track");
01226 static vcl_string track_file;
01227 static vcl_string snip_dir;
01228 static vcl_string trk_ext = "trk", snip_ext = "";
01229 static double frac = 0.1;
01230 file_dialog.file("Track File(input):", trk_ext, track_file);
01231 file_dialog.file("Snippet Directory(output):", snip_ext, snip_dir);
01232 file_dialog.field("Snippet ROI Margin (fraction of Bounding Box diameter)", frac);
01233 if (!file_dialog.ask())
01234 return;
01235 strk_snippet_extractor_process* sep = new strk_snippet_extractor_process();
01236 video_process_ = sep;
01237 sep->set_margin_fraction(frac);
01238 sep->set_input_file(track_file);
01239 sep->set_snippet_directory(snip_dir);
01240 start_frame_ = sep->start_frame();
01241 end_frame_ = sep->end_frame();
01242 }