00001
00002 #include "segv_segmentation_manager.h"
00003
00004
00005
00006
00007 #include <vcl_cstdlib.h>
00008 #include <vcl_iostream.h>
00009 #include <vcl_fstream.h>
00010 #include <vbl/vbl_array_2d.h>
00011 #include <vil1/vil1_image.h>
00012 #include <vil1/vil1_memory_image_of.h>
00013 #include <vil1/vil1_load.h>
00014 #include <vil1/vil1_crop.h>
00015 #include <vdgl/vdgl_digital_curve.h>
00016 #include <vdgl/vdgl_digital_curve_sptr.h>
00017 #include <sdet/sdet_detector_params.h>
00018 #include <sdet/sdet_detector.h>
00019 #include <sdet/sdet_harris_detector_params.h>
00020 #include <sdet/sdet_harris_detector.h>
00021 #include <sdet/sdet_fit_lines_params.h>
00022 #include <sdet/sdet_fit_lines.h>
00023 #include <sdet/sdet_grid_finder_params.h>
00024 #include <sdet/sdet_grid_finder.h>
00025 #include <vgui/vgui.h>
00026 #include <vgui/vgui_find.h>
00027 #include <vgui/vgui_tableau.h>
00028 #include <vgui/vgui_dialog.h>
00029 #include <vgui/vgui_style_sptr.h>
00030 #include <vgui/vgui_style.h>
00031 #include <vgui/vgui_viewer2D_tableau.h>
00032 #include <vgui/vgui_shell_tableau.h>
00033 #include <vgui/vgui_grid_tableau.h>
00034 #include <vgui/vgui_rubberband_tableau.h>
00035 #include <vgui/vgui_range_map_params.h>
00036 #include <bgui/bgui_image_tableau.h>
00037 #include <bgui/bgui_vtol2D_tableau.h>
00038 #include <bgui/bgui_vtol2D_rubberband_client.h>
00039 #include <bgui/bgui_picker_tableau.h>
00040 #include <vsol/vsol_point_2d.h>
00041 #include <vsol/vsol_point_2d_sptr.h>
00042 #include <vsol/vsol_curve_2d.h>
00043 #include <vsol/vsol_curve_2d_sptr.h>
00044 #include <vsol/vsol_polygon_2d_sptr.h>
00045 #include <vsol/vsol_polygon_2d.h>
00046 #include <vtol/vtol_vertex_2d.h>
00047 #include <vtol/vtol_vertex.h>
00048 #include <vtol/vtol_edge_2d.h>
00049 #include <vtol/vtol_one_chain_sptr.h>
00050 #include <vtol/vtol_one_chain.h>
00051 #include <vtol/vtol_intensity_face.h>
00052 #include <bbas/bsol/bsol_algs.h>
00053 #include <brip/brip_vil1_float_ops.h>
00054 #include <brip/brip_para_cvrg_params.h>
00055 #include <brip/brip_para_cvrg.h>
00056 #include <brip/brip_watershed_params.h>
00057 #include <sdet/sdet_watershed_region_proc_params.h>
00058 #include <sdet/sdet_watershed_region_proc.h>
00059 #include <sdet/sdet_vehicle_finder_params.h>
00060 #include <sdet/sdet_vehicle_finder.h>
00061 #include <sdet/sdet_region_proc_params.h>
00062 #include <sdet/sdet_region_proc.h>
00063 #include <strk/strk_region_info_params.h>
00064 #include <strk/strk_region_info.h>
00065 #include <strk/strk_io.h>
00066
00067 segv_segmentation_manager *segv_segmentation_manager::instance_ = 0;
00068
00069 segv_segmentation_manager *segv_segmentation_manager::instance()
00070 {
00071 if (!instance_)
00072 {
00073 instance_ = new segv_segmentation_manager();
00074 instance_->init();
00075 }
00076 return segv_segmentation_manager::instance_;
00077 }
00078
00079
00080
00081
00082 segv_segmentation_manager::segv_segmentation_manager():vgui_wrapper_tableau()
00083 {
00084 first_ = true;
00085 }
00086
00087 segv_segmentation_manager::~segv_segmentation_manager()
00088 {
00089 }
00090
00091
00092 void segv_segmentation_manager::init()
00093 {
00094 bgui_image_tableau_sptr itab = bgui_image_tableau_new();
00095 bgui_vtol2D_tableau_sptr t2D = bgui_vtol2D_tableau_new(itab);
00096 bgui_vtol2D_rubberband_client* rcl = new bgui_vtol2D_rubberband_client(t2D);
00097 vgui_rubberband_tableau_sptr rubber = vgui_rubberband_tableau_new(rcl);
00098 vgui_composite_tableau_new comp(t2D,rubber);
00099 bgui_picker_tableau_sptr picktab = bgui_picker_tableau_new(comp);
00100 vgui_viewer2D_tableau_sptr v2D = vgui_viewer2D_tableau_new(picktab);
00101 grid_ = vgui_grid_tableau_new(1,1);
00102 grid_->set_grid_size_changeable(true);
00103 grid_->add_at(v2D, 0, 0);
00104 vgui_shell_tableau_sptr shell = vgui_shell_tableau_new(grid_);
00105 this->add_child(shell);
00106 first_ = true;
00107 }
00108
00109
00110 void segv_segmentation_manager::set_selected_grid_image(vil1_image& image)
00111 {
00112 bgui_image_tableau_sptr itab = this->selected_image_tab();
00113 if (!itab)
00114 this->add_image(image);
00115 else
00116 itab->set_image(image);
00117 itab->post_redraw();
00118 }
00119
00120 void segv_segmentation_manager::
00121 add_image_at(vil1_image& image, const unsigned col, const unsigned row)
00122 {
00123 bgui_image_tableau_sptr itab = bgui_image_tableau_new(image);
00124 bgui_vtol2D_tableau_sptr t2D = bgui_vtol2D_tableau_new(itab);
00125 bgui_vtol2D_rubberband_client* rcl = new bgui_vtol2D_rubberband_client(t2D);
00126 vgui_rubberband_tableau_sptr rubber = vgui_rubberband_tableau_new(rcl);
00127 vgui_composite_tableau_new comp(t2D,rubber);
00128 bgui_picker_tableau_sptr picktab = bgui_picker_tableau_new(comp);
00129 vgui_viewer2D_tableau_sptr v2D = vgui_viewer2D_tableau_new(picktab);
00130 grid_->add_at(v2D, col, row);
00131 itab->post_redraw();
00132 }
00133
00134
00135 void segv_segmentation_manager::add_image(vil1_image& image)
00136 {
00137 unsigned row=0, col=0;
00138 grid_->get_last_selected_position(&col, &row);
00139 this->add_image_at(image, col, row);
00140 }
00141
00142
00143 bgui_image_tableau_sptr segv_segmentation_manager::selected_image_tab()
00144 {
00145 unsigned row=0, col=0;
00146 grid_->get_last_selected_position(&col, &row);
00147 vgui_tableau_sptr top_tab = grid_->get_tableau_at(col, row);
00148 if (top_tab)
00149 {
00150 bgui_image_tableau_sptr itab;
00151 itab.vertical_cast(vgui_find_below_by_type_name(top_tab,
00152 vcl_string("vgui_image_tableau")));
00153 if (itab)
00154 return itab;
00155 }
00156 vcl_cout << "Unable to get bgui_image_tableau at (" << col
00157 << ", " << row << ")\n";
00158 return bgui_image_tableau_sptr();
00159 }
00160
00161
00162 bgui_vtol2D_tableau_sptr segv_segmentation_manager::selected_vtol2D_tab()
00163 {
00164 unsigned row=0, col=0;
00165 grid_->get_last_selected_position(&col, &row);
00166 vgui_tableau_sptr top_tab = grid_->get_tableau_at(col, row);
00167 if (top_tab)
00168 {
00169 bgui_vtol2D_tableau_sptr v2D;
00170 v2D.vertical_cast(vgui_find_below_by_type_name(top_tab,
00171 vcl_string("bgui_vtol2D_tableau")));
00172 if (v2D)
00173 return v2D;
00174 }
00175 vcl_cout << "Unable to get bgui_vtol2D_tableau at (" << col
00176 << ", " << row << ")\n";
00177 return bgui_vtol2D_tableau_sptr();
00178 }
00179
00180
00181 bgui_picker_tableau_sptr segv_segmentation_manager::selected_picker_tab()
00182 {
00183 unsigned row=0, col=0;
00184 grid_->get_last_selected_position(&col, &row);
00185 vgui_tableau_sptr top_tab = grid_->get_tableau_at(col, row);
00186 if (top_tab)
00187 {
00188 bgui_picker_tableau_sptr pick;
00189 pick.vertical_cast(vgui_find_below_by_type_name(top_tab,
00190 vcl_string("bgui_picker_tableau")));
00191 if (pick)
00192 return pick;
00193 }
00194 vcl_cout << "Unable to get bgui_picker_tableau at (" << col
00195 << ", " << row << ")\n";
00196 return bgui_picker_tableau_sptr();
00197 }
00198
00199
00200 vgui_rubberband_tableau_sptr segv_segmentation_manager::selected_rubber_tab()
00201 {
00202 unsigned row=0, col=0;
00203 grid_->get_last_selected_position(&col, &row);
00204 vgui_tableau_sptr top_tab = grid_->get_tableau_at(col, row);
00205 if (top_tab)
00206 {
00207 vgui_rubberband_tableau_sptr rubber;
00208 rubber.vertical_cast(vgui_find_below_by_type_name(top_tab,
00209 vcl_string("vgui_rubberband_tableau")));
00210 if (rubber)
00211 return rubber;
00212 }
00213 vcl_cout << "Unable to get vgui_rubberband_tableau at (" << col
00214 << ", " << row << ")\n";
00215 return vgui_rubberband_tableau_sptr();
00216 }
00217
00218 vil1_image segv_segmentation_manager::selected_image()
00219 {
00220 bgui_image_tableau_sptr itab = this->selected_image_tab();
00221 if (!itab)
00222 return vil1_image();
00223 return itab->get_image();
00224 }
00225
00226 vil1_image segv_segmentation_manager::image_at(const unsigned col,
00227 const unsigned row)
00228 {
00229 vgui_tableau_sptr top_tab = grid_->get_tableau_at(col, row);
00230 if (!top_tab)
00231 return vil1_image();
00232
00233 bgui_image_tableau_sptr itab;
00234 itab.vertical_cast(vgui_find_below_by_type_name(top_tab,
00235 vcl_string("vgui_image_tableau")));
00236 if (!itab)
00237 {
00238 vcl_cout << "Unable to get bgui_image_tableau at (" << col
00239 << ", " << row << ")\n";
00240 return vil1_image();
00241 }
00242 return itab->get_image();
00243 }
00244
00245 void segv_segmentation_manager::quit()
00246 {
00247 vcl_exit(1);
00248 }
00249
00250 void segv_segmentation_manager::load_image()
00251 {
00252 static bool greyscale = true;
00253 vgui_dialog load_image_dlg("Load image file");
00254 static vcl_string image_filename = "/home/dec/images/cal_image1.tif";
00255 static vcl_string ext = "*.*";
00256 load_image_dlg.file("Image Filename:", ext, image_filename);
00257 load_image_dlg.checkbox("greyscale ", greyscale);
00258 if (!load_image_dlg.ask())
00259 return;
00260
00261 vil1_image temp = vil1_load(image_filename.c_str()), image;
00262
00263 if (greyscale)
00264 image = brip_vil1_float_ops::convert_to_grey(temp);
00265 else
00266 image = temp;
00267
00268 if (first_)
00269 {
00270 this->set_selected_grid_image(image);
00271 first_ = false;
00272 }
00273 else
00274 this->add_image(image);
00275 }
00276
00277
00278
00279
00280 void segv_segmentation_manager::clear_display()
00281 {
00282 bgui_vtol2D_tableau_sptr t2D = this->selected_vtol2D_tab();
00283 if (!t2D)
00284 return;
00285 t2D->clear_all();
00286 }
00287
00288
00289
00290
00291 void
00292 segv_segmentation_manager::draw_edges(vcl_vector<vtol_edge_2d_sptr>& edges,
00293 bool verts)
00294 {
00295 bgui_vtol2D_tableau_sptr t2D = this->selected_vtol2D_tab();
00296 if (!t2D)
00297 return;
00298 this->clear_display();
00299 #if 0
00300 vgui_image_tableau_sptr itab = t2D->get_image_tableau();
00301 if (!itab)
00302 {
00303 vcl_cout << "In segv_segmentation_manager::draw_edges - null image tab\n";
00304 return;
00305 }
00306 #endif
00307 for (vcl_vector<vtol_edge_2d_sptr>::iterator eit = edges.begin();
00308 eit != edges.end(); eit++)
00309 {
00310 t2D->add_edge(*eit);
00311
00312 if (verts)
00313 {
00314 if ((*eit)->v1())
00315 {
00316 vtol_vertex_2d_sptr v1 = (*eit)->v1()->cast_to_vertex_2d();
00317 t2D->add_vertex(v1);
00318 }
00319 if ((*eit)->v2())
00320 {
00321 vtol_vertex_2d_sptr v2 = (*eit)->v2()->cast_to_vertex_2d();
00322 t2D->add_vertex(v2);
00323 }
00324 }
00325 }
00326 t2D->post_redraw();
00327 }
00328
00329
00330
00331
00332
00333 void segv_segmentation_manager::
00334 draw_polylines(vcl_vector<vsol_polyline_2d_sptr > const& polys)
00335 {
00336 bgui_vtol2D_tableau_sptr t2D = this->selected_vtol2D_tab();
00337 if (!t2D)
00338 return;
00339
00340 vgui_image_tableau_sptr itab = t2D->get_image_tableau();
00341 if (!itab)
00342 {
00343 vcl_cout << "In segv_segmentation_manager::draw_edges - null image tab\n";
00344 return;
00345 }
00346 for (vcl_vector<vsol_polyline_2d_sptr>::const_iterator pit = polys.begin();
00347 pit != polys.end(); pit++)
00348 {
00349 t2D->add_vsol_polyline_2d(*pit);
00350 }
00351
00352 t2D->post_redraw();
00353 }
00354
00355
00356
00357
00358 void segv_segmentation_manager::
00359 draw_lines(vcl_vector<vsol_line_2d_sptr > const& lines,
00360 const vgui_style_sptr& style)
00361 {
00362 bgui_vtol2D_tableau_sptr t2D = this->selected_vtol2D_tab();
00363 if (!t2D)
00364 return;
00365
00366 #if 0
00367 vgui_image_tableau_sptr itab = t2D->get_image_tableau();
00368 if (!itab)
00369 {
00370 vcl_cout << "In segv_segmentation_manager::draw_edges - null image tab\n";
00371 return;
00372 }
00373 #endif
00374 for (vcl_vector<vsol_line_2d_sptr>::const_iterator lit = lines.begin();
00375 lit != lines.end(); lit++)
00376 {
00377 t2D->add_vsol_line_2d(*lit,style);
00378 }
00379
00380 t2D->post_redraw();
00381 }
00382
00383
00384
00385
00386 void segv_segmentation_manager::
00387 draw_points(vcl_vector<vsol_point_2d_sptr> const& points, const vgui_style_sptr& style)
00388 {
00389 bgui_vtol2D_tableau_sptr t2D = this->selected_vtol2D_tab();
00390 if (!t2D)
00391 return;
00392
00393 vgui_image_tableau_sptr itab = t2D->get_image_tableau();
00394 if (!itab)
00395 {
00396 vcl_cout << "In segv_segmentation_manager::draw_edges - null image tab\n";
00397 return;
00398 }
00399 for (vcl_vector<vsol_point_2d_sptr>::const_iterator pit = points.begin();
00400 pit != points.end(); pit++)
00401 {
00402 t2D->add_vsol_point_2d(*pit,style);
00403 }
00404
00405 t2D->post_redraw();
00406 }
00407
00408 void segv_segmentation_manager::draw_regions(vcl_vector<vtol_intensity_face_sptr>& regions,
00409 bool verts)
00410 {
00411 bgui_vtol2D_tableau_sptr t2D = this->selected_vtol2D_tab();
00412 if (!t2D)
00413 return;
00414 for (vcl_vector<vtol_intensity_face_sptr>::iterator rit = regions.begin();
00415 rit != regions.end(); rit++)
00416 {
00417 vtol_face_2d_sptr f = (*rit)->cast_to_face_2d();
00418 t2D->add_face(f);
00419 if (verts)
00420 {
00421 vcl_vector<vtol_vertex_sptr> vts;
00422 f->vertices(vts);
00423 for (vcl_vector<vtol_vertex_sptr>::iterator vit = vts.begin();
00424 vit != vts.end(); vit++)
00425 {
00426 vtol_vertex_2d_sptr v = (*vit)->cast_to_vertex_2d();
00427 t2D->add_vertex(v);
00428 }
00429 }
00430 }
00431 t2D->post_redraw();
00432 }
00433
00434 void segv_segmentation_manager::original_image()
00435 {
00436 #if 0
00437 if (img_)
00438 {
00439 t2D->get_image_tableau()->set_image(img_);
00440 t2D->post_redraw();
00441 }
00442 #endif
00443 }
00444
00445 void segv_segmentation_manager::roi()
00446 {
00447 vil1_image img = selected_image();
00448 if (!img)
00449 {
00450 vcl_cout << "In segv_segmentation_manager::roi() - no image\n";
00451 return;
00452 }
00453 float x0=0, y0=0, x1=0, y1=0;
00454 bgui_picker_tableau_sptr picktab = this->selected_picker_tab();
00455 vcl_cout << "Choose upper left corner of ROI.\n";
00456 picktab->pick_point(&x0,&y0);
00457 vcl_cout << "picked (x="<<x0<<", y="<<y0<<")\n"
00458 << "Choose lower right corner of ROI.\n";
00459 picktab->pick_point(&x1,&y1);
00460 vcl_cout << "picked (x="<<x1<<", y="<<y1<<")\n";
00461 if ( (x1 > x0) && (y1 > y0) )
00462 {
00463 int w = int(x1 - x0);
00464 int h = int(y1 - y0);
00465 vil1_image cropped = vil1_crop(img,int(x0),int(y0),w,h);
00466 vcl_cout << "cropped x=" <<x0<<" y=" <<y0<< " w=" <<w<<" h=" <<h<< '\n';
00467 #if 0
00468 if (cropped)
00469 {
00470 img = cropped;
00471 t2D->get_image_tableau()->set_image(cropped);
00472 t2D->post_redraw();
00473 return;
00474 }
00475 #endif
00476 if (cropped)
00477 {
00478 this->add_image(cropped);
00479 return;
00480 }
00481 vcl_cout << "crop failed.\n";
00482 return;
00483 }
00484 vcl_cout << "invalid ROI\n";
00485 return;
00486 }
00487
00488 void segv_segmentation_manager::gaussian()
00489 {
00490 vil1_image img = selected_image();
00491 if (!img)
00492 {
00493 vcl_cout << "In segv_segmentation_manager::gaussian() - no image\n";
00494 return;
00495 }
00496 static float sigma = 1.0;
00497 vgui_dialog gauss_dialog("Gaussian Smooth");
00498 gauss_dialog.field("Gaussian sigma", sigma);
00499 if (!gauss_dialog.ask())
00500 return;
00501 vil1_memory_image_of<float> input(img);
00502 vil1_memory_image_of<float> smooth = brip_vil1_float_ops::gaussian(input, sigma);
00503 vil1_memory_image_of<unsigned char> char_smooth =
00504 brip_vil1_float_ops::convert_to_byte(smooth);
00505 this->add_image(char_smooth);
00506 }
00507
00508 void segv_segmentation_manager::convolution()
00509 {
00510 vgui_dialog kernel_dlg("Load Kernel");
00511 static vcl_string kernel_filename = "c:/images";
00512 static vcl_string ext = "*.*";
00513 kernel_dlg.file("Kernel Filename:", ext, kernel_filename);
00514 if (!kernel_dlg.ask())
00515 return;
00516 vbl_array_2d<float> kernel = brip_vil1_float_ops::load_kernel(kernel_filename);
00517
00518
00519 vil1_image img = selected_image();
00520 if (!img)
00521 {
00522 vcl_cout << "In segv_segmentation_manager::convolution() - no image\n";
00523 return;
00524 }
00525 vil1_memory_image_of<unsigned char> temp(img);
00526 vil1_memory_image_of<float> temp2 = brip_vil1_float_ops::convert_to_float(temp);
00527
00528
00529 vil1_memory_image_of<float> conv = brip_vil1_float_ops::convolve(temp2, kernel);
00530
00531
00532 vil1_memory_image_of<unsigned char> char_conv =
00533 brip_vil1_float_ops::convert_to_byte(conv);
00534
00535
00536 this->add_image(char_conv);
00537 }
00538
00539 void segv_segmentation_manager::downsample()
00540 {
00541 vil1_image img = selected_image();
00542 if (!img)
00543 {
00544 vcl_cout << "In segv_segmentation_manager::downsample) - no image\n";
00545 return;
00546 }
00547 static float filter_factor = 0.36f;
00548 vgui_dialog downsample_dialog("Downsample");
00549 downsample_dialog.field("Bert-Adelson Factor", filter_factor);
00550 if (!downsample_dialog.ask())
00551 return;
00552 vil1_memory_image_of<unsigned char> input(img);
00553 vil1_memory_image_of<float> inputf = brip_vil1_float_ops::convert_to_float(input);
00554 vil1_memory_image_of<float> half_res =
00555 brip_vil1_float_ops::half_resolution(inputf, filter_factor);
00556 vil1_memory_image_of<unsigned char> char_half_res =
00557 brip_vil1_float_ops::convert_to_byte(half_res);
00558 this->add_image(char_half_res);
00559 }
00560
00561 void segv_segmentation_manager::harris_measure()
00562 {
00563 vil1_image img = selected_image();
00564 if (!img)
00565 {
00566 vcl_cout << "In segv_segmentation_manager::harris_measure) - no image\n";
00567 return;
00568 }
00569 static sdet_harris_detector_params hdp;
00570 vgui_dialog harris_dialog("harris");
00571 harris_dialog.field("sigma", hdp.sigma_);
00572 harris_dialog.field("thresh", hdp.thresh_);
00573 harris_dialog.field("N = 2n+1, (n)", hdp.n_);
00574 harris_dialog.field("Max No Corners(percent)", hdp.percent_corners_);
00575 harris_dialog.field("scale_factor", hdp.scale_factor_);
00576 if (!harris_dialog.ask())
00577 return;
00578 sdet_harris_detector hd(hdp);
00579 hd.set_image(img);
00580 hd.extract_corners();
00581 vcl_vector<vsol_point_2d_sptr>& points = hd.get_points();
00582 int N = points.size();
00583 if (!N)
00584 return;
00585 bgui_vtol2D_tableau_sptr t2D = this->selected_vtol2D_tab();
00586 if (!t2D)
00587 return;
00588 t2D->clear_all();
00589 for (int i=0; i<N; i++)
00590 t2D->add_vsol_point_2d(points[i]);
00591 t2D->post_redraw();
00592 }
00593
00594 void segv_segmentation_manager::beaudet_measure()
00595 {
00596 vil1_image img = selected_image();
00597 if (!img)
00598 {
00599 vcl_cout <<"In segv_segmentation_manager::beaudet_measure) - no image\n";
00600 return;
00601 }
00602 static float sigma = 1.0f;
00603
00604
00605 static float cmax=100;
00606 vgui_dialog harris_dialog("beaudet");
00607 harris_dialog.field("sigma", sigma);
00608 harris_dialog.field("range", cmax);
00609 if (!harris_dialog.ask())
00610 return;
00611 int w = img.width(), h = img.height();
00612 vil1_memory_image_of<unsigned char> input(img);
00613 vil1_memory_image_of<float> inputf = brip_vil1_float_ops::convert_to_float(input);
00614 vil1_memory_image_of<float> smooth = brip_vil1_float_ops::gaussian(inputf, sigma);
00615 vil1_memory_image_of<float> Ixx, Ixy, Iyy, b;
00616 Ixx.resize(w,h); Ixy.resize(w,h); Iyy.resize(w,h);
00617 brip_vil1_float_ops::hessian_3x3(smooth, Ixx, Ixy, Iyy);
00618 b = brip_vil1_float_ops::beaudet(Ixx, Ixy, Iyy);
00619 vil1_memory_image_of<unsigned char> uchar_b =
00620 brip_vil1_float_ops::convert_to_byte(b,0.0f, cmax);
00621 this->add_image(uchar_b);
00622 }
00623
00624 void segv_segmentation_manager::vd_edges()
00625 {
00626 this->clear_display();
00627 static bool agr = true;
00628 static sdet_detector_params dp;
00629 static float nm = 2.0;
00630
00631 vgui_dialog vd_dialog("VD Edges");
00632 vd_dialog.field("Gaussian sigma", dp.smooth);
00633 vd_dialog.field("Noise Threshold", nm);
00634 vd_dialog.checkbox("Automatic Threshold", dp.automatic_threshold);
00635 vd_dialog.checkbox("Agressive Closure", agr);
00636 vd_dialog.checkbox("Compute Junctions", dp.junctionp);
00637 if (!vd_dialog.ask())
00638 return;
00639 dp.noise_multiplier=nm;
00640 if (agr)
00641 dp.aggressive_junction_closure=1;
00642 else
00643 dp.aggressive_junction_closure=0;
00644 vil1_image img = selected_image();
00645 if (!img)
00646 {
00647 vcl_cout << "In segv_segmentation_manager::vd_edges() - no image\n";
00648 return;
00649 }
00650 sdet_detector det(dp);
00651 det.SetImage(img);
00652
00653 det.DoContour();
00654 vcl_vector<vtol_edge_2d_sptr>* edges = det.GetEdges();
00655 if (edges)
00656 this->draw_edges(*edges, true);
00657 }
00658
00659 void segv_segmentation_manager::regions()
00660 {
00661 this->clear_display();
00662 static bool debug = false;
00663 static bool agr = true;
00664 static bool residual = false;
00665 static sdet_detector_params dp;
00666 static float nm = 1.0;
00667 vgui_dialog region_dialog("Edgel Regions");
00668 region_dialog.field("Gaussian sigma", dp.smooth);
00669 region_dialog.field("Noise Threshold", nm);
00670 region_dialog.checkbox("Automatic Threshold", dp.automatic_threshold);
00671 region_dialog.checkbox("Agressive Closure", agr);
00672 region_dialog.checkbox("Compute Junctions", dp.junctionp);
00673 region_dialog.checkbox("Debug", debug);
00674 region_dialog.checkbox("Residual Image", residual);
00675 if (!region_dialog.ask())
00676 return;
00677 dp.noise_multiplier=nm;
00678 if (agr)
00679 dp.aggressive_junction_closure=1;
00680 else
00681 dp.aggressive_junction_closure=0;
00682
00683 vil1_image img = selected_image();
00684 if (!img)
00685 {
00686 vcl_cout << "In segv_segmentation_manager::regions() - no image\n";
00687 return;
00688 }
00689 sdet_region_proc_params rpp(dp, true, debug, 2);
00690 sdet_region_proc rp(rpp);
00691 rp.set_image(img);
00692 rp.extract_regions();
00693 if (debug)
00694 {
00695 vil1_image ed_img = rp.get_edge_image();
00696 #if 0
00697 vgui_image_tableau_sptr itab = t2D->get_image_tableau();
00698 if (!itab)
00699 {
00700 vcl_cout << "In segv_segmentation_manager::regions() - null image tableau\n";
00701 return;
00702 }
00703 itab->set_image(ed_img);
00704 itab->post_redraw();
00705 #endif
00706 this->add_image(ed_img);
00707 }
00708 if (!debug)
00709 {
00710 vcl_vector<vtol_intensity_face_sptr>& regions = rp.get_regions();
00711 this->draw_regions(regions, true);
00712 }
00713 if (residual)
00714 {
00715 vil1_image res_img = rp.get_residual_image();
00716 #if 0
00717 vgui_image_tableau_sptr itab = t2D->get_image_tableau();
00718 if (!itab)
00719 {
00720 vcl_cout << "In segv_segmentation_manager::regions() - null image tableau\n";
00721 return;
00722 }
00723 itab->set_image(res_img);
00724 itab->post_redraw();
00725 #endif
00726 this->add_image(res_img);
00727 }
00728 }
00729
00730
00731
00732
00733
00734
00735
00736 void segv_segmentation_manager::test_camera_parms()
00737 {
00738 this->clear_display();
00739 vgui_dialog tcp_dialog("Test Camera Parms");
00740 static vcl_string camera_parms_filename = "/home/dec/camera_parms.left.txt";
00741 static vcl_string input_points_filename = "/home/dec/point_correspondences.left.txt";
00742 static vcl_string ext = "*.*";
00743 static bool show_input_points = true;
00744 static bool show_calculated_points = true;
00745 static int view_num = 1;
00746 tcp_dialog.file("camera parms file:", ext, camera_parms_filename);
00747 tcp_dialog.file("input points file:", ext, input_points_filename);
00748 tcp_dialog.field("view number:",view_num);
00749 tcp_dialog.checkbox("show input points",show_input_points);
00750 tcp_dialog.checkbox("show calculated points",show_calculated_points);
00751
00752 if (!tcp_dialog.ask())
00753 return;
00754
00755 if (show_calculated_points)
00756 {
00757
00758 vnl_matrix_fixed<double,3,3> K;
00759 vcl_ifstream parms_instream(camera_parms_filename.c_str());
00760
00761 double k_values[9];
00762 for (int i=0; i < 9; i++)
00763 {
00764 parms_instream >> k_values[i];
00765
00766 }
00767 K.put(0,0,k_values[0]); K.put(0,1,k_values[1]); K.put(0,2,k_values[2]);
00768 K.put(1,0,k_values[3]); K.put(1,1,k_values[4]); K.put(1,2,k_values[5]);
00769 K.put(2,0,k_values[6]); K.put(2,1,k_values[7]); K.put(2,2,k_values[8]);
00770
00771 vcl_cout << "K =\n" << K << '\n';
00772
00773
00774 int n_views = 0;
00775 parms_instream >> n_views;
00776
00777
00778 vnl_matrix_fixed<double,3,4> M;
00779
00780 double m_values[12];
00781 double dummy;
00782 for (int v = 1; v <= view_num; v++)
00783 {
00784 if (v > n_views)
00785 {
00786 vcl_cout << "error: view number > n_views\n";
00787 break;
00788 }
00789 for (int i=0; i < 12; i++)
00790 {
00791 parms_instream >> m_values[i];
00792
00793 }
00794
00795 for (int i=0; i < 4; i++)
00796 {
00797 parms_instream >> dummy;
00798 }
00799 }
00800 parms_instream.close();
00801
00802 M.put(0,0,m_values[0]); M.put(0,1,m_values[1]); M.put(0,2,m_values[2]); M.put(0,3,m_values[3]);
00803 M.put(1,0,m_values[4]); M.put(1,1,m_values[5]); M.put(1,2,m_values[6]); M.put(1,3,m_values[7]);
00804 M.put(2,0,m_values[8]); M.put(2,1,m_values[9]); M.put(2,2,m_values[10]); M.put(2,3,m_values[11]);
00805
00806 vcl_cout << "M =\n" << M << '\n';
00807
00808
00809 sdet_grid_finder_params gfp;
00810 sdet_grid_finder gf(gfp);
00811 vcl_vector<vsol_point_2d_sptr> calculated_points;
00812 gf.transform_grid_points(K,M,calculated_points);
00813
00814
00815 vgui_style_sptr style = vgui_style::new_style(1.0f,0.0f,0.0f,5.0f,1.0f);
00816 this->draw_points(calculated_points,style);
00817 }
00818 if (show_input_points)
00819 {
00820 vcl_vector<vsol_point_2d_sptr> input_points;
00821 vcl_ifstream points_instream(input_points_filename.c_str());
00822 int n_points = 0;
00823
00824 points_instream >> n_points;
00825
00826 double dummy;
00827 double* points_x = new double[n_points];
00828 double* points_y = new double[n_points];
00829 for (int i = 0; i < n_points; i++)
00830 {
00831 points_instream >> dummy;
00832 points_instream >> dummy;
00833 }
00834
00835
00836 int n_views = 0;
00837 points_instream >> n_views;
00838
00839
00840 for (int v = 1; v <= view_num; v++)
00841 {
00842 if (v > n_views)
00843 {
00844 vcl_cout << "error: view number > n_views\n";
00845 break;
00846 }
00847 for (int i = 0; i < n_points; i++)
00848 {
00849 points_instream >> points_x[i];
00850 points_instream >> points_y[i];
00851 }
00852 }
00853 for (int i = 0; i < n_points; i++)
00854 {
00855 vsol_point_2d_sptr point = new vsol_point_2d(points_x[i],points_y[i]);
00856 input_points.push_back(point);
00857 }
00858 vgui_style_sptr style = vgui_style::new_style(0.0f,1.0f,0.0f,4.0f,1.0f);
00859 this->draw_points(input_points,style);
00860 delete[] points_x;
00861 delete[] points_y;
00862 }
00863
00864 return;
00865 }
00866
00867 void segv_segmentation_manager::fit_lines()
00868 {
00869 this->clear_display();
00870 static sdet_grid_finder_params gfp;
00871 vcl_vector<vcl_string> choices;
00872 gfp.get_debug_choices(choices);
00873 static bool agr = true;
00874 static sdet_detector_params dp;
00875 dp.borderp=false;
00876 static sdet_fit_lines_params flp;
00877 static float nm = 2.0;
00878 static bool detect_grid=true;
00879
00880 static bool matched_lines = false;
00881 static bool manual_pt_selection = false;
00882 vgui_dialog vd_dialog("Fit Lines");
00883 vd_dialog.field("Gaussian sigma", dp.smooth);
00884 vd_dialog.field("Noise Threshold", nm);
00885 vd_dialog.checkbox("Automatic Threshold", dp.automatic_threshold);
00886 vd_dialog.checkbox("Agressive Closure", agr);
00887 vd_dialog.checkbox("Compute Junctions", dp.junctionp);
00888 vd_dialog.field("Min Fit Length", flp.min_fit_length_);
00889 vd_dialog.field("RMS Distance", flp.rms_distance_);
00890 vd_dialog.field("Angle Tolerance", gfp.angle_tol_);
00891 vd_dialog.field("Line Count Threshold", gfp.thresh_);
00892 vd_dialog.checkbox("Detect Grid", detect_grid);
00893 vd_dialog.checkbox("Grid Debug Output", gfp.verbose_);
00894 vd_dialog.checkbox("Matched Lines", matched_lines);
00895 vd_dialog.checkbox("Use Manual Point Selection",manual_pt_selection);
00896 vd_dialog.choice("Choose Debug Line Display", choices, gfp.debug_state_);
00897 if (!vd_dialog.ask())
00898 return;
00899 dp.noise_multiplier=nm;
00900 if (agr)
00901 dp.aggressive_junction_closure=1;
00902 else
00903 dp.aggressive_junction_closure=0;
00904 dp.borderp = false;
00905