track.C

Go to the documentation of this file.
00001 /*!@file RCBot/track.C track featuers */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00005 // University of Southern California (USC) and the iLab at USC.         //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: Lior Elazary <lelazary@yahoo.com>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/RCBot/track.C $
00035 // $Id: track.C 14376 2011-01-11 02:44:34Z pez $
00036 //
00037 
00038 #include "Component/ModelManager.H"
00039 #include "Component/OptionManager.H"
00040 #include "Controllers/PID.H"
00041 #include "Corba/Objects/CMap.H"
00042 #include "Devices/FrameGrabberConfigurator.H"
00043 #include "Devices/sc8000.H"
00044 #include "GUI/XWinManaged.H"
00045 #include "Image/ColorOps.H"
00046 #include "Image/CutPaste.H"
00047 #include "Image/DrawOps.H"
00048 #include "Image/Image.H"
00049 #include "Image/MathOps.H"
00050 #include "Image/Pixels.H"
00051 #include "Image/ShapeOps.H"
00052 #include "Image/Transforms.H"
00053 #include "Image/fancynorm.H"
00054 #include "Neuro/SaliencyMap.H"
00055 #include "Neuro/VisualCortex.H"
00056 #include "Neuro/WTAwinner.H"
00057 #include "Neuro/WinnerTakeAll.H"
00058 #include "RCBot/Motion/MotionEnergy.H"
00059 #include "Raster/Raster.H"
00060 #include "Transport/FrameIstream.H"
00061 #include "Util/Timer.H"
00062 #include "Util/Types.H"
00063 #include "Util/log.H"
00064 #include <math.h>
00065 
00066 #define UP_KEY 98
00067 #define DOWN_KEY 104
00068 #define LEFT_KEY 100
00069 #define RIGHT_KEY 102
00070 
00071 XWinManaged window(Dims(256, 256), -1, -1, "Test Output 1");
00072 XWinManaged window1(Dims(256, 256), -1, -1, "S Map");
00073 XWinManaged window2(Dims(256, 256), -1, -1, "S Map");
00074 
00075 #define sml        0
00076 #define delta_min  3
00077 #define delta_max  4
00078 #define level_min  0
00079 #define level_max  2
00080 #define maxdepth   (level_max + delta_max + 1)
00081 #define normtyp    (VCXNORM_MAXNORM)
00082 
00083 // ######################################################################
00084 int main(int argc, char **argv)
00085 {
00086   MYLOGVERB = LOG_DEBUG;
00087 
00088   CORBA::ORB_ptr orb = CORBA::ORB_init(argc,argv,"omniORB4");
00089 
00090   // instantiate a model manager:
00091   ModelManager manager("Track Features");
00092 
00093   // Instantiate our various ModelComponents:
00094   nub::soft_ref<FrameGrabberConfigurator>
00095     gbc(new FrameGrabberConfigurator(manager));
00096   manager.addSubComponent(gbc);
00097 
00098   // Parse command-line:
00099   if (manager.parseCommandLine(argc, (const char **)argv, "", 0, 0) == false) return(1);
00100 
00101   // do post-command-line configs:
00102   nub::soft_ref<FrameIstream> gb = gbc->getFrameGrabber();
00103   if (gb.get() == NULL)
00104     LFATAL("You need to select a frame grabber type via the "
00105            "--fg-type=XX command-line option for this program "
00106            "to be useful -- ABORT");
00107  // int w = gb->getWidth(), h = gb->getHeight();
00108 
00109   // let's get all our ModelComponent instances started:
00110   manager.start();
00111 
00112 
00113   // get the frame grabber to start streaming:
00114   gb->startStream();
00115 
00116 
00117   // ########## MAIN LOOP: grab, process, display:
00118   int key = 0;
00119 
00120   double time = 0;
00121 
00122 
00123   int fr = 0;
00124   Image<float> cmap[8];
00125 
00126   CMapThreads cmap_th(orb);
00127 
00128   int cmapFrames[8];
00129   for(int i=0; i<8; i++)
00130           cmapFrames[i]=0;
00131 
00132   std::vector<float> bias[8];
00133   while(key != 24){
00134       // receive conspicuity maps:
00135       // grab an image:
00136 
00137       Image< PixRGB<byte> > ima = gb->readRGB();
00138 
00139 
00140                 Image<byte> lum = luminance(ima);
00141                 Image<byte> rImg, gImg, bImg, yImg;
00142       getRGBY(ima, rImg, gImg, bImg, yImg, (byte)25);
00143 
00144 
00145                 Point2D<int> location = window.getLastMouseClick();
00146                 if (location.isValid()){
00147                         LINFO("Click at at %i %i", location.i, location.j);
00148                         Dims WindowDims = window.getDims();
00149 
00150                         float newi = (float)location.i * (float)ima.getWidth()/(float)WindowDims.w();
00151                         float newj = (float)location.j * (float)ima.getHeight()/(float)WindowDims.h();
00152                         location.i = (int)newi;
00153                         location.j = (int)newj;
00154 
00155                         LINFO("Getting bias from at at %i %i", location.i, location.j);
00156                         bias[0] = cmap_th.getBias(cmap[0], lum,  Gaussian5, 0.0, 1.0, cmapFrames[0], location);
00157                         bias[1] = cmap_th.getBias(cmap[1], rImg, Gaussian5, 0.0, 1.0, cmapFrames[1], location);
00158                         bias[2] = cmap_th.getBias(cmap[2], gImg, Gaussian5, 0.0, 1.0, cmapFrames[2], location);
00159                         bias[3] = cmap_th.getBias(cmap[3], bImg, Gaussian5, 0.0, 1.0, cmapFrames[3], location);
00160 
00161                         bias[4] = cmap_th.getBias(cmap[4], lum, Oriented5, 0.0, 1.0, cmapFrames[4], location);
00162                         bias[5] = cmap_th.getBias(cmap[5], lum, Oriented5, 45.0, 1.0, cmapFrames[5], location);
00163                         bias[6] = cmap_th.getBias(cmap[6], lum, Oriented5, 90.0, 1.0, cmapFrames[6], location);
00164                         bias[7] = cmap_th.getBias(cmap[7], lum, Oriented5, 135.0, 1.0, cmapFrames[7], location);
00165 
00166                 }
00167 
00168 
00169                 // CMapWorkerThread* workth[8];
00170                 LINFO("Bias size %"ZU, bias[0].size());
00171                 if (bias[0].size() == 6){
00172 /*
00173                         workth[0] = cmap_th.newth(cmap[0], lum,  Gaussian5, 0.0, 1.0, cmapFrames[0], bias[0]);
00174                         workth[1] = cmap_th.newth(cmap[1], rImg, Gaussian5, 0.0, 1.0, cmapFrames[1], bias[1]);
00175                         workth[2] = cmap_th.newth(cmap[2], gImg, Gaussian5, 0.0, 1.0, cmapFrames[2], bias[2]);
00176                         workth[3] = cmap_th.newth(cmap[3], bImg, Gaussian5, 0.0, 1.0, cmapFrames[3], bias[3]);
00177                         workth[4] = cmap_th.newth(cmap[4], lum, Oriented5, 0.0, 1.0, cmapFrames[4],  bias[4]);
00178                         workth[5] = cmap_th.newth(cmap[5], lum, Oriented5, 45.0, 1.0, cmapFrames[5], bias[5]);
00179                         workth[6] = cmap_th.newth(cmap[6], lum, Oriented5, 90.0, 1.0, cmapFrames[6], bias[6]);
00180                         workth[7] = cmap_th.newth(cmap[7], lum, Oriented5, 135.0, 1.0, cmapFrames[7],bias[7]);
00181 */
00182                         /*//wait for threads
00183                         for (int i=0; i<1; i++){
00184                                 workth[i]->join(NULL);
00185                         }*/
00186                 }
00187 
00188                 /*cmap_th.newth(cmap[0], lum,  Gaussian5, 0.0, 1.0, cmapFrames[0]);
00189                 cmap_th.newth(cmap[1], rImg, Gaussian5, 0.0, 1.0, cmapFrames[1]);
00190                 cmap_th.newth(cmap[2], gImg, Gaussian5, 0.0, 1.0, cmapFrames[2]);
00191                 cmap_th.newth(cmap[3], bImg, Gaussian5, 0.0, 1.0, cmapFrames[3]);
00192 
00193                 cmap_th.newth(cmap[4], lum, Oriented5, 0.0, 1.0, cmapFrames[4]);
00194                 cmap_th.newth(cmap[5], lum, Oriented5, 45.0, 1.0, cmapFrames[5]);
00195                 cmap_th.newth(cmap[6], lum, Oriented5, 90.0, 1.0, cmapFrames[6]);
00196                 cmap_th.newth(cmap[7], lum, Oriented5, 135.0, 1.0, cmapFrames[7]);*/
00197 
00198 
00199 
00200 
00201                 Image<float> sminput;
00202 
00203                 for (int i=0; i< 8; i++){
00204                         if (cmap[i].initialized()){
00205                                 if (sminput.initialized())
00206                                         sminput += cmap[i];
00207                                 else
00208                                         sminput = cmap[i];
00209                         }
00210                 }
00211 
00212 
00213                 LINFO("Frames %i: %i %i %i %i %i %i %i %i\n",
00214                                 fr, cmapFrames[0], cmapFrames[1],cmapFrames[2],
00215                                 cmapFrames[3],cmapFrames[4],cmapFrames[5],
00216                                 cmapFrames[6],cmapFrames[7]);
00217 
00218                 Point2D<int> winner(-1, -1); float maxval;
00219                 if (sminput.initialized()){
00220                         findMax(sminput, winner, maxval);
00221                         LINFO("Max %f at %i %i\n", maxval, winner.i, winner.j);
00222                         if (winner.isValid())
00223                                 drawDisk(ima, winner, 10, PixRGB<byte>(255, 0, 0));
00224 
00225                         window1.drawImage(rescale(sminput, 256, 256));
00226                 }
00227 
00228 
00229                 window.drawImage(rescale(ima, 256, 256));
00230 
00231                 time += 0.1;
00232                 fr++;
00233   }
00234 
00235 
00236 
00237   // got interrupted; let's cleanup and exit:
00238   manager.stop();
00239   return 0;
00240 }
00241 
00242 
00243 // ######################################################################
00244 /* So things look consistent in everyone's emacs... */
00245 /* Local Variables: */
00246 /* indent-tabs-mode: nil */
00247 /* End: */
Generated on Sun May 8 08:41:17 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3