test-CrossRecognizer.C

00001 /*!@file BeoSub/test-BeoSubCross.C find cross     */
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-CrossRecognizer.C $
00034 // $Id: test-CrossRecognizer.C 10794 2009-02-08 06:21:09Z itti $
00035 
00036 #include "Component/ModelManager.H"
00037 
00038 #include "Media/FrameSeries.H"
00039 #include "Transport/FrameIstream.H"
00040 #include "Media/MediaOpts.H"
00041 #include "Raster/GenericFrame.H"
00042 
00043 #include "Image/CutPaste.H"
00044 #include "Image/Image.H"
00045 #include "Image/Pixels.H"
00046 #include "Raster/Raster.H"
00047 
00048 #include "Image/DrawOps.H"
00049 #include "Image/ColorOps.H"
00050 #include "BeoSub/IsolateColor.H"
00051 
00052 #include "GUI/XWinManaged.H"
00053 
00054 #include "SeaBee/CrossRecognizer.H"
00055 
00056 
00057 //END CAMERA STUFF
00058 //canny
00059 #define BOOSTBLURFACTOR 90.0
00060 #define FREE_ARG char*
00061 //#define PI 3.14159
00062 #define FILLBLEED 4
00063 #define INITIAL_TEMPERATURE 30.0
00064 #define FINAL_TEMPERATURE 0.5
00065 #define ALPHA 0.98
00066 #define STEPS_PER_CHANGE 1000
00067 
00068 #define BIN_ANGLE 0.588001425
00069 
00070 int main(int argc, char* argv[])
00071 {
00072  MYLOGVERB = LOG_INFO;
00073 
00074   ModelManager manager("CrossRecognizer Tester");
00075 
00076   nub::soft_ref<InputFrameSeries> ifs(new InputFrameSeries(manager));
00077   manager.addSubComponent(ifs);
00078 
00079   manager.exportOptions(MC_RECURSE);
00080 
00081   // Parse command-line:
00082   if (manager.parseCommandLine(argc, argv,
00083                                "[image {*.ppm}]",
00084                                0, 1)
00085       == false) return(1);
00086 
00087   int w = ifs->getWidth(),  h = ifs->getHeight();
00088   std::string dims = convertToString(Dims(w, h));
00089   LINFO("image size: [%dx%d]", w, h);
00090   manager.setOptionValString(&OPT_InputFrameDims, dims);
00091 
00092   manager.setModelParamVal("InputFrameDims", Dims(w, h),
00093                            MC_RECURSE | MC_IGNORE_MISSING);
00094 
00095   manager.start();
00096 
00097   bool goforever = true;
00098 
00099   rutz::shared_ptr<XWinManaged> dispWin;
00100   dispWin.reset(new XWinManaged(Dims(w*2,h*2), 0, 0, "Cross Recognizer Display"));
00101 
00102   rutz::shared_ptr<CrossRecognizer> crossRecognizer(new CrossRecognizer());
00103 
00104   Image< PixRGB<byte> > img(w,h, ZEROS);
00105 
00106   // count of the number of points that are outside
00107   // std dev to determine if current avg center point is stale
00108   rutz::shared_ptr<uint> stalePointCount(new uint());
00109   *stalePointCount = 0;
00110   rutz::shared_ptr<float> crossAngle(new float());
00111   rutz::shared_ptr<Point2D<int> > crossCenterPoint(new Point2D<int>(0,0));
00112   uint fNum = 0;
00113 
00114   while(goforever)
00115     {
00116       Image< PixRGB<byte> > dispImg(w*2,h*2, ZEROS);
00117       rutz::shared_ptr<Image< PixRGB<byte> > > outputImg(new Image<PixRGB<byte> >(w,h, ZEROS));
00118       rutz::shared_ptr<Image<byte> > orangeIsoImage(new Image<byte>(w,h, ZEROS));
00119 
00120       ifs->updateNext(); img = ifs->readRGB();
00121       if(!img.initialized()) {Raster::waitForKey(); break; }
00122 
00123       inplacePaste(dispImg, img, Point2D<int>(0,0));
00124 
00125       //orangeIsoImage->resize(w,h);
00126       isolateOrange(img, *orangeIsoImage);
00127 
00128       inplacePaste(dispImg, toRGB(*orangeIsoImage), Point2D<int>(w,0));
00129       //Timer tim(1000000);
00130 
00131       crossRecognizer->getCrossLocation(orangeIsoImage,
00132                                         outputImg,
00133                                         CrossRecognizer::HOUGH,
00134                                         crossCenterPoint,
00135                                         crossAngle,
00136                                         stalePointCount);
00137 
00138       inplacePaste(dispImg, *outputImg, Point2D<int>(0,h));
00139 
00140       //wtf does this do?
00141       //Point2D<int> p(colorSegmentedImage.getWidth()/2, colorSegmentedImage.getHeight()/2);
00142       //Point2D<int> p2((int)(colorSegmentedImage.getWidth()/2+cos(crossAngle)*LINESCALE),
00143       //           (int)(colorSegmentedImage.getHeight()/2+sin(crossAngle)*LINESCALE));
00144 
00145       Image<PixRGB<byte> > crossOverlayImage = img;
00146 
00147       PixRGB <byte> crossColor;
00148 
00149       if(*stalePointCount <= 30)
00150         {
00151           crossColor =  PixRGB <byte> (0, 255,0);
00152         }
00153       else
00154         {
00155           crossColor =  PixRGB <byte> (255, 0 ,0);
00156         }
00157       float tmpAngle = *crossAngle;
00158       Point2D<int> tmpCenterPoint = *crossCenterPoint;
00159       drawCrossOR(crossOverlayImage,
00160                   tmpCenterPoint,
00161                   crossColor,
00162                   20,5, fabs(tmpAngle));
00163 
00164 
00165       inplacePaste(dispImg, crossOverlayImage, Point2D<int>(w,h));
00166 
00167       writeText( dispImg, Point2D<int>(0,0), sformat("Frame: %6d", fNum).c_str(),
00168                  PixRGB<byte>(255,0,0));
00169       writeText( dispImg, Point2D<int>(w,0), sformat("Edge Detect and Hough").c_str(),
00170                  PixRGB<byte>(255,0,0));
00171       writeText( dispImg, Point2D<int>(0,h), sformat("Identify Cross").c_str(),
00172                  PixRGB<byte>(255,0,0));
00173 
00174       dispWin->drawImage(dispImg, 0, 0);
00175       fNum++;
00176 
00177       //wait a little
00178       Raster::waitForKey();
00179     }
00180 
00181   // get ready to terminate:
00182   manager.stop();
00183   return 0;
00184 }
00185 
00186 // ######################################################################
00187 /* So things look consistent in everyone's emacs... */
00188 /* Local Variables: */
00189 /* indent-tabs-mode: nil */
00190 /* End: */
Generated on Sun May 8 08:42:15 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3