contrib/brl/bseg/vpro/vpro_edge_process.cxx
Go to the documentation of this file.
00001 // This is brl/bseg/vpro/vpro_edge_process.cxx
00002 #include "vpro_edge_process.h"
00003 //: \file
00004 #include <vcl_iostream.h>
00005 #include <vul/vul_timer.h>
00006 #include <vcl_vector.h>
00007 #include <vil1/vil1_memory_image_of.h>
00008 #include <vtol/vtol_edge_2d_sptr.h>
00009 #include <vtol/vtol_edge_2d.h>
00010 #include <brip/brip_vil1_float_ops.h>
00011 #include <sdet/sdet_detector.h>
00012 
00013 vpro_edge_process::vpro_edge_process(sdet_detector_params & dp)
00014   : sdet_detector_params(dp)
00015 {
00016 }
00017 
00018 vpro_edge_process::~vpro_edge_process()
00019 {
00020 }
00021 
00022 bool vpro_edge_process::execute()
00023 {
00024   vul_timer t;
00025   if (this->get_N_input_images() != 1)
00026   {
00027     vcl_cout<<"In vpro_edge_process::execute() - not exactly one input image\n";
00028     return false;
00029   }
00030   output_topo_objs_.clear();
00031 
00032   vil1_image img = vpro_video_process::get_input_image(0);
00033   vil1_memory_image_of<unsigned char> cimg;
00034   if (img.components() == 3)
00035   {
00036     vil1_memory_image_of<float> fimg = brip_vil1_float_ops::convert_to_float(img);
00037     vpro_video_process::clear_input();//remove image from input
00038     //convert a color image to grey
00039     cimg = brip_vil1_float_ops::convert_to_byte(fimg);
00040   }
00041   else
00042   {
00043     cimg = vil1_memory_image_of<unsigned char>(img);
00044     vpro_video_process::clear_input();
00045   }
00046   //initialize the detector
00047   sdet_detector detector(*(static_cast<sdet_detector_params*>(this)));
00048   detector.SetImage(cimg);
00049   //process edges
00050   detector.DoContour();
00051   vcl_vector<vtol_edge_2d_sptr> * edges = detector.GetEdges();
00052 
00053   if (!edges)
00054     return false;
00055 
00056    for (vcl_vector<vtol_edge_2d_sptr>::iterator eit = edges->begin();
00057         eit != edges->end(); eit++)
00058      output_topo_objs_.push_back((*eit)->cast_to_topology_object());
00059 
00060   output_image_ = 0;//no output image is produced
00061   vcl_cout << "process " << edges->size()
00062            << " edges in " << t.real() << " msecs.\n";
00063   return true;
00064 }