test-PipeRecognizer.C

Go to the documentation of this file.
00001 /*!@file SeaBee/test-PipeRecognizer.C test pipe recognizer   */
00002 // //////////////////////////////////////////////////////////////////// //
00003 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00004 // University of Southern California (USC) and the iLab at USC.         //
00005 // See http://iLab.usc.edu for information about this project.          //
00006 // //////////////////////////////////////////////////////////////////// //
00007 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00008 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00009 // in Visual Environments, and Applications'' by Christof Koch and      //
00010 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00011 // pending; application number 09/912,225 filed July 23, 2001; see      //
00012 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00013 // //////////////////////////////////////////////////////////////////// //
00014 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00015 //                                                                      //
00016 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00017 // redistribute it and/or modify it under the terms of the GNU General  //
00018 // Public License as published by the Free Software Foundation; either  //
00019 // version 2 of the License, or (at your option) any later version.     //
00020 //                                                                      //
00021 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00022 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00023 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00024 // PURPOSE.  See the GNU General Public License for more details.       //
00025 //                                                                      //
00026 // You should have received a copy of the GNU General Public License    //
00027 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00028 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00029 // Boston, MA 02111-1307 USA.                                           //
00030 // //////////////////////////////////////////////////////////////////// //
00031 //
00032 // Primary maintainer for this file: Michael Montalbo <montalbo@usc.edu>
00033 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/SeaBee/test-PipeRecognizer.C $
00034 // $Id: test-PipeRecognizer.C 12962 2010-03-06 02:13:53Z irock $
00035 
00036 #include "Component/ModelManager.H"
00037 
00038 #include "Media/FrameSeries.H"
00039 #include "Transport/FrameIstream.H"
00040 #include "Media/MediaOpts.H"
00041 
00042 #include "Image/Image.H"
00043 #include "Image/Pixels.H"
00044 #include "Raster/Raster.H"
00045 #include "Image/CutPaste.H"
00046 #include "Image/OpenCVUtil.H"
00047 
00048 #include "BeoSub/IsolateColor.H"
00049 #include "Image/DrawOps.H"
00050 #include "Image/ColorOps.H"
00051 
00052 #include "GUI/XWinManaged.H"
00053 
00054 #include "SeaBee/PipeRecognizer.H"
00055 
00056 #include "BeoSub/ColorSegmenter.H"
00057 
00058 int main(int argc, char* argv[])
00059 {
00060 
00061   MYLOGVERB = LOG_INFO;
00062 
00063   ModelManager manager("PipeRecognizer Tester");
00064 
00065   nub::soft_ref<InputFrameSeries> ifs(new InputFrameSeries(manager));
00066   manager.addSubComponent(ifs);
00067 
00068   manager.exportOptions(MC_RECURSE);
00069 
00070   // Parse command-line:
00071   if (manager.parseCommandLine(argc, argv,
00072                                "[image {*.ppm}]",
00073                                0, 1)
00074       == false) return(1);
00075 
00076   int w = ifs->getWidth(),  h = ifs->getHeight();
00077   std::string dims = convertToString(Dims(w, h));
00078   LINFO("image size: [%dx%d]", w, h);
00079   manager.setOptionValString(&OPT_InputFrameDims, dims);
00080 
00081   manager.setModelParamVal("InputFrameDims", Dims(w, h),
00082                            MC_RECURSE | MC_IGNORE_MISSING);
00083 
00084   manager.start();
00085 
00086   bool goforever = true;
00087 
00088   rutz::shared_ptr<XWinManaged> dispWin;
00089   dispWin.reset(new XWinManaged(Dims(w*2,h*2), 0, 0, "Pipe Recognizer Display"));
00090 
00091   // input and output image
00092   Image< PixRGB<byte> > img(w,h, ZEROS);
00093 
00094   rutz::shared_ptr<PipeRecognizer> pipeRecognizer(new PipeRecognizer());
00095 
00096   uint fNum = 0;
00097 
00098   while(goforever)
00099     {
00100       Image< PixRGB<byte> > dispImg(w*2,h*2, ZEROS);
00101       rutz::shared_ptr<Image< PixRGB<byte> > >
00102         outputImg(new Image<PixRGB<byte> >(w,h, ZEROS));
00103 
00104       rutz::shared_ptr<Image<byte> > orangeIsoImage;
00105       orangeIsoImage.reset(new Image<byte>(w,h, ZEROS));
00106 
00107       //read an input image
00108       ifs->updateNext(); img = ifs->readRGB();
00109       if(!img.initialized()) {Raster::waitForKey(); break; }
00110 
00111       inplacePaste(dispImg, img, Point2D<int>(0,0));
00112 
00113       orangeIsoImage->resize(w,h);
00114       //get all of the orange pixels in the image
00115       isolateOrange(img, *orangeIsoImage);
00116 
00117       inplacePaste(dispImg, toRGB(*orangeIsoImage), Point2D<int>(w,0));
00118 
00119       //get all the orange lines in the image
00120       std::vector<LineSegment2D> pipelines =
00121         pipeRecognizer->getPipeLocation
00122         (orangeIsoImage, outputImg, PipeRecognizer::HOUGH);
00123 
00124 
00125       int minY = -1; //minimum midpoint y coordinate found
00126       int followLineIndex = -1; //index of pipeline with minimum y coordinate
00127 
00128       //iterates through pipelines and finds the topmost one in the image
00129       for(uint i = 0; i < pipelines.size(); i++)
00130         {
00131           LineSegment2D pipeline = pipelines[i];
00132           Point2D<int> midpoint = (pipeline.point1() + pipeline.point2())/2;
00133 
00134           if(midpoint.j < minY || minY == -1)
00135             {
00136               minY = midpoint.j;
00137               followLineIndex = i;
00138             }
00139         }
00140 
00141       //if we found a pipeline
00142       if(followLineIndex != -1)
00143         {
00144           LineSegment2D followLine = pipelines[followLineIndex];
00145           Point2D<int> midpoint = (followLine.point1() + followLine.point2())/2;
00146 
00147           Point2D<int> projPoint;
00148           projPoint.i = (int)(midpoint.i+30*cos(followLine.angle()));
00149           projPoint.j = (int)(midpoint.j+30*sin(followLine.angle()));
00150 
00151           drawLine(*outputImg, midpoint, projPoint, PixRGB <byte> (255, 255,0), 3);
00152 
00153           inplacePaste(dispImg, *outputImg, Point2D<int>(0,h));
00154 
00155           dispWin->drawImage(dispImg, 0, 0);
00156           LINFO("%d",fNum); fNum++;
00157         }
00158 
00159       //wait for a key
00160       Raster::waitForKey();
00161     }
00162 
00163   // get ready to terminate:
00164   manager.stop();
00165   return 0;
00166 }
00167 
00168 // ######################################################################
00169 /* So things look consistent in everyone's emacs... */
00170 /* Local Variables: */
00171 /* indent-tabs-mode: nil */
00172 /* End: */
Generated on Sun May 8 08:42:15 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3