test-segmentImageMC.C

Go to the documentation of this file.
00001 /*!@file VFAT/test-segmentImageMC.C track color in grabbed frame        */
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:  T. Nathan Mundhenk <mundhenk@usc.edu>
00033 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/VFAT/test-segmentImageMC.C $
00034 // $Id: test-segmentImageMC.C 6988 2006-08-11 17:15:38Z rjpeters $
00035 //
00036 
00037 #include "Component/ModelManager.H"
00038 #include "Devices/FrameGrabberConfigurator.H"
00039 #include "GUI/XWindow.H"
00040 #include "Raster/Raster.H"
00041 #include "Transport/FrameIstream.H"
00042 #include "VFAT/segmentImageTrackMC.H"
00043 #include "rutz/shared_ptr.h"
00044 
00045 #include <cstdio>
00046 #include <cstdlib>
00047 
00048 // number of frames over which framerate info is averaged:
00049 #define NAVG 20
00050 
00051 // ######################################################################
00052 //! A basic test program for segmentImageMC tracker
00053 int main(const int argc, const char **argv)
00054 {
00055   // instantiate a model manager:
00056   ModelManager manager("Frame Grabber Tester");
00057 
00058   // Instantiate our various ModelComponents:
00059   nub::soft_ref<FrameGrabberConfigurator>
00060     gbc(new FrameGrabberConfigurator(manager));
00061   manager.addSubComponent(gbc);
00062 
00063   // Parse command-line:
00064   if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1);
00065 
00066   // do post-command-line configs:
00067   nub::soft_ref<FrameIstream> gb = gbc->getFrameGrabber();
00068   if (gb.isInvalid())
00069     LFATAL("You need to select a frame grabber type via the "
00070            "--fg-type=XX command-line option for this program "
00071            "to be useful");
00072   int width = gb->getWidth(), height = gb->getHeight();
00073 
00074   // let's get all our ModelComponent instances started:
00075   manager.start();
00076   XWindow wini(Dims(width, height), 0, 0, "test-input window");
00077   XWindow wino(Dims(width/4, height/4), 0, 0, "test-output window 2");
00078   XWindow winAux(Dims(500, 450), 0, 0, "Channel levels");
00079   Timer tim; Image< PixRGB<byte> > ima; Image< PixRGB<float> > fima;
00080   Image< PixRGB<byte> > display;
00081   uint64 t[NAVG]; unsigned int frame = 0;
00082   Image<PixH2SV2<float> > H2SVimage;
00083 
00084   /****************************************************************************/
00085   /* create 2 trackers that are bound together (e.g. 2 trackers in the same
00086      camera input image
00087   */
00088  /*
00089   //! Mean color to track (ideal color)
00090   std::vector<float> color(3,0.0F);
00091   color[0] = 20.0F; color[1] = 0.25F; color[2] = 156.0F;
00092 
00093   //! +/- tollerance value on mean for track
00094   std::vector<float> std(3,0.0F);
00095   std[0] = 30.0F; std[1] = 0.30F; std[2] = 60.0F;
00096 
00097   //! normalizer over color values (highest value possible)
00098   std::vector<float> norm(3,0.0F);
00099   norm[0] = 360.0F; norm[1] = 1.0F; norm[2] = 255.0F;
00100 
00101   //! how many standard deviations out to adapt, higher means less bias
00102   std::vector<float> adapt(3,0.0F);
00103   adapt[0] = 3.5F; adapt[1] = 3.5F; adapt[2] = 3.5F;
00104 
00105   //! highest value for color adaptation possible (hard boundary)
00106   std::vector<float> upperBound(3,0.0F);
00107   upperBound[0] = 50.0F; upperBound[1] = 0.4F ; upperBound[2] = 180.0F;
00108 
00109   //! lowest value for color adaptation possible (hard boundary)
00110   std::vector<float> lowerBound(3,0.0F);
00111   lowerBound[0] = 12.0F; lowerBound[1] = 0.1F; lowerBound[2] = 120.0F;
00112 */
00113   /****************************************************************************/
00114   //! Mean color to track (ideal color for red feducial)
00115   /*  std::vector<float> color(3,0.0F);
00116   color[0] = 10.0F; color[1] = 0.80F; color[2] = 156.0F;
00117 
00118   //! +/- tollerance value on mean for track
00119   std::vector<float> std(3,0.0F);
00120   std[0] = 30.0F; std[1] = 0.30F; std[2] = 60.0F;
00121 
00122   //! normalizer over color values (highest value possible)
00123   std::vector<float> norm(3,0.0F);
00124   norm[0] = 360.0F; norm[1] = 1.0F; norm[2] = 255.0F;
00125 
00126   //! how many standard deviations out to adapt, higher means less bias
00127   std::vector<float> adapt(3,0.0F);
00128   adapt[0] = 3.5F; adapt[1] = 3.5F; adapt[2] = 3.5F;
00129 
00130   //! highest value for color adaptation possible (hard boundry)
00131   std::vector<float> upperBound(3,0.0F);
00132   upperBound[0] = 50.0F; upperBound[1] = 1.0F ; upperBound[2] = 255.0F;
00133 
00134   //! lowest value for color adaptation possible (hard boundry)
00135   std::vector<float> lowerBound(3,0.0F);
00136   lowerBound[0] = 0.0F; lowerBound[1] = 0.1F; lowerBound[2] = 10.0F;
00137   */
00138   /****************************************************************************/
00139   //! Mean color to track (ideal color for blue feducial)
00140 
00141   /*
00142   std::vector<float> color(3,0.0F);
00143   //"PINK"
00144   //color[0] = 0.0F; color[1] = 0.88F; color[2] = 180.0F;
00145   //BLUE
00146   color[0] = 250.0F; color[1] = 0.50F; color[2] = 156.0F;
00147 
00148   //! +/- tollerance value on mean for track
00149   std::vector<float> std(3,0.0F);
00150   std[0] = 60.0F; std[1] = 0.30F; std[2] = 60.0F;
00151 
00152   //! normalizer over color values (highest value possible)
00153   std::vector<float> norm(3,0.0F);
00154   norm[0] = 360.0F; norm[1] = 1.0F; norm[2] = 255.0F;
00155 
00156   //! how many standard deviations out to adapt, higher means less bias
00157   std::vector<float> adapt(3,0.0F);
00158   adapt[0] = 3.5F; adapt[1] = 3.5F; adapt[2] = 3.5F;
00159 
00160   //! highest value for color adaptation possible (hard boundry)
00161   std::vector<float> upperBound(3,0.0F);
00162   upperBound[0] = 360.0F; upperBound[1] = 1.0F ; upperBound[2] = 255.0F;
00163 
00164   //! lowest value for color adaptation possible (hard boundry)
00165   std::vector<float> lowerBound(3,0.0F);
00166   lowerBound[0] = 200.0F; lowerBound[1] = 0.1F; lowerBound[2] = 10.0F;
00167   */
00168 
00169   /****************************************************************************/
00170   //! extracted signature
00171 
00172   // signature extracted for Nathan's mahogany shirt
00173 
00174   // H1 - H2 - S - V
00175   std::vector<float> color(4,0.0F);
00176   color[0] = 0.350962; color[1] = 0.645527; color[2] = 0.313523; color[3] = 0.720654;
00177 
00178   //! +/- tollerance value on mean for track
00179   std::vector<float> std(4,0.0F);
00180   std[0] = 0.339556; std[1] = 0.368726; std[2] = 0.609608; std[3] = 0.34012;
00181 
00182   //! normalizer over color values (highest value possible)
00183   std::vector<float> norm(4,0.0F);
00184   norm[0] = 1.0F; norm[1] = 1.0F; norm[2] = 1.0F; norm[3] = 1.0F;
00185 
00186   //! how many standard deviations out to adapt, higher means less bias
00187   std::vector<float> adapt(4,0.0F);
00188   adapt[0] = 3.5F; adapt[1] = 3.5F; adapt[2] = 3.5F; adapt[3] = 3.5F;
00189 
00190   //! highest value for color adaptation possible (hard boundary)
00191   std::vector<float> upperBound(4,0.0F);
00192   upperBound[0] = color[0] + 0.45F; upperBound[1] = color[1] + 0.45F;
00193   upperBound[2] = color[2] + 0.55F; upperBound[3] = color[3] + 0.55F;
00194 
00195   //! lowest value for color adaptation possible (hard boundary)
00196   std::vector<float> lowerBound(4,0.0F);
00197   lowerBound[0] = color[0] - 0.45F; lowerBound[1] = color[1] - 0.45F;
00198   lowerBound[2] = color[2] - 0.55F; lowerBound[3] = color[3] - 0.55F;
00199 
00200 
00201   //int zero = 0;
00202   int wi = width/4;
00203   int hi = height/4;
00204 
00205   segmentImageTrackMC<float,unsigned int, 4> segmenter(wi*hi);
00206 
00207   segmenter.SITsetTrackColor(&color,&std,&norm,&adapt,&upperBound,&lowerBound);
00208 
00209   /* This limits the area of consideration to an area smaller than
00210      the image size. That is, it creates a boundery in the image
00211      outside of which it will not consider pixes (i.e. a frame)
00212   */
00213   segmenter.SITsetFrame(&wi,&hi);
00214 
00215 
00216   /* Set display colors for output of tracking. Strictly asthetic */
00217   segmenter.SITsetCircleColor(255,255,0);
00218   segmenter.SITsetBoxColor(255,255,0,0,255,255);
00219   segmenter.SITsetUseSmoothing(true,10);
00220   //unsigned long counter = 0;
00221 
00222   while(1) {
00223 
00224     tim.reset();
00225     ima = gb->readRGB();
00226     uint64 t0 = tim.get();  // to measure display time
00227 
00228     Image<PixRGB<byte> > Aux;
00229     Aux.resize(100,450,true);
00230 
00231     /* Take in the image and color segment it */
00232     H2SVimage = ima;
00233     display = ima;
00234 
00235     /******************************************************************/
00236     // SEGMENT IMAGE ON EACH INPUT FRAME
00237 
00238     segmenter.SITtrackImageAny(H2SVimage,&display,&Aux,true);
00239 
00240     /* Retrieve and Draw all our output images */
00241     Image<byte> temp = segmenter.SITreturnCandidateImage();
00242 
00243     wini.drawImage(display);
00244     wino.drawImage(temp);
00245     winAux.drawImage(Aux);
00246 
00247     /******************************************************************/
00248     // Uncomment these lines to write each frame to the hard drive
00249     /******************************************************************/
00250     /*
00251     LINFO("COUNT %d",counter);
00252     // TRACKER DISPLAY
00253     Raster::WriteRGB(display,sformat("out.display.%d.ppm",counter));
00254     // BOOL CANDIDATE MAP
00255     Raster::WriteRGB(temp,sformat("out.temp.%d.ppm",counter));
00256     // ADAPTIVE THRESHOLDING BARS
00257     Raster::WriteRGB(Aux,sformat("out.Aux.%d.ppm",counter));
00258     // BLOB ID MAP
00259     Image<byte> blobs = segmenter.SITreturnBlobMap();
00260     inplaceNormalize(blobs, 0,255);
00261     Raster::WriteRGB(blobs,sformat("out.Blobs.%d.ppm",counter));
00262     counter++;
00263     */
00264     /******************************************************************/
00265 
00266     t[frame % NAVG] = tim.get();
00267     t0 = t[frame % NAVG] - t0;
00268     if (t0 > 28) LINFO("Display took %llums", t0);
00269     // compute and show framerate over the last NAVG frames:
00270     if (frame % NAVG == 0 && frame > 0)
00271     {
00272       uint64 avg = 0; for (int i = 0; i < NAVG; i ++) avg += t[i];
00273       float avg2 = 1000.0 / (float)avg * NAVG;
00274       printf("Framerate: %.1f fps\n", avg2);
00275     }
00276     frame ++;
00277   }
00278 
00279   manager.stop();
00280   return 0;
00281 }
00282 
00283 // ######################################################################
00284 /* So things look consistent in everyone's emacs... */
00285 /* Local Variables: */
00286 /* indent-tabs-mode: nil */
00287 /* End: */
Generated on Sun May 8 08:42:36 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3