segmentImageMerge2.H

Go to the documentation of this file.
00001 /*!@file VFAT/segmentImageMerge2.H Basic image segmenter blob finder using color */
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: T. Nathan Mundhenk <mundhenk@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/VFAT/segmentImageMerge2.H $
00035 // $Id: segmentImageMerge2.H 4663 2005-06-23 17:47:28Z rjpeters $
00036 //
00037 
00038 #ifndef SEGMENTIMAGEMERGE2_H
00039 #define SEGMENTIMAGEMERGE2_H
00040 
00041 
00042 #include "Devices/cameraConf.H"
00043 #include "Image/Image.H"
00044 #include "Util/Timer.H"
00045 #include "Util/Types.H"
00046 #include "Util/log.H"
00047 #include "Util/readConfig.H"
00048 #include "Util/stats.H"
00049 #include "VFAT/NPclassify2.H"
00050 #include "VFAT/PointClasses.H"
00051 #include "VFAT/segmentImageTrack2.H"
00052 #include <math.h>
00053 
00054 class segmentImageMerge2
00055 {
00056   // create a billion vectors for holding everything we need
00057   // this is lazy, but RAM is cheap ;)
00058 private:
00059   segmentImage2 *SIM_segment;
00060   NPclassify2<float> SIM_NP;
00061   stats<float> SIM_Stats;
00062   cameraConf SIM_camera;
00063   blobProp SIM_blobProp;
00064   int SIM_instanceNumber;
00065   int SIM_mergeGotoX;
00066   int SIM_mergeGotoY;
00067   int SIM_winningClass;
00068   float SIM_Hweight, SIM_Sweight, SIM_Vweight;
00069   bool SIM_fast;
00070   bool SIM_clusterSet;
00071   float SIM_moveMeanNormal;
00072   float SIM_moveStdNormal;
00073   float SIM_winningScore;
00074 
00075   std::vector<float> SIM_H;
00076   std::vector<float> SIM_S;
00077   std::vector<float> SIM_V;
00078   std::vector<float> SIM_Hstd;
00079   std::vector<float> SIM_Sstd;
00080   std::vector<float> SIM_Vstd;
00081   std::vector<float> SIM_HA;
00082   std::vector<float> SIM_SA;
00083   std::vector<float> SIM_VA;
00084   std::vector<float> SIM_HU;
00085   std::vector<float> SIM_SU;
00086   std::vector<float> SIM_VU;
00087   std::vector<float> SIM_HL;
00088   std::vector<float> SIM_SL;
00089   std::vector<float> SIM_VL;
00090   std::vector<float> SIM_delay;
00091   std::vector<float> SIM_cameraMovePan;
00092   std::vector<float> SIM_cameraMoveTilt;
00093   std::vector<float> SIM_cameraGotoPan;
00094   std::vector<float> SIM_cameraGotoTilt;
00095   std::vector<float> SIM_cameraMu;
00096   std::vector<float> SIM_cameraSigma;
00097   std::vector<float> SIM_meanMove;
00098   std::vector<float> SIM_stdMove;
00099 
00100   std::vector<std::vector< float> > SIM_moveRecord;
00101   std::vector<std::vector< float> > SIM_moveRecordGrad;
00102   std::vector<std::vector< float> > SIM_imageVecIter;
00103   std::vector<std::vector< double> > SIM_meanH;
00104   std::vector<std::vector< double> > SIM_meanS;
00105   std::vector<std::vector< double> > SIM_meanV;
00106   std::vector<std::vector< double> > SIM_stdH;
00107   std::vector<std::vector< double> > SIM_stdS;
00108   std::vector<std::vector< double> > SIM_stdV;
00109   std::vector<std::vector< float> > SIM_score;
00110 
00111   std::vector<std::vector< float> > SIM_vectorizedImage;
00112 
00113   std::vector<int> SIM_LOTcount;
00114   std::vector<int> SIM_height;
00115   std::vector<int> SIM_width;
00116   std::vector<int> SIM_gotoX;
00117   std::vector<int> SIM_gotoY;
00118   std::vector<int> SIM_circleRed;
00119   std::vector<int> SIM_circleGreen;
00120   std::vector<int> SIM_circleBlue;
00121   std::vector<int> SIM_boxRed;
00122   std::vector<int> SIM_boxGreen;
00123   std::vector<int> SIM_boxBlue;
00124   std::vector<int> SIM_didCircleColor;
00125   std::vector<int> SIM_didBoxColor;
00126   std::vector<int> SIM_didTrackColor;
00127   std::vector<int> SIM_recordCounter;
00128   std::vector<int> SIM_item;
00129 
00130   std::vector<bool> SIM_adpt;
00131   std::vector<bool> SIM_HASTD;
00132   std::vector<bool> SIM_SASTD;
00133   std::vector<bool> SIM_VASTD;
00134   std::vector<bool> SIM_moveCamera;
00135   std::vector<bool> SIM_useCluster;
00136 
00137   std::vector<Timer> SIM_tim;
00138   std::vector<segmentImageTrack2> SIM_track;
00139   std::vector<Image<byte> > SIM_temp;
00140   void SIMcolorProcessBlobs(int instance);
00141   void SIMresetColor(int instance);
00142   Image<PixRGB<byte> > *SIM_imageHold;
00143   Image<PixRGB<byte> > *SIM_auxHold;
00144   Image<PixRGB<float> > *SIM_fimaHold;
00145   readConfig configIn;
00146   readConfig polySet;
00147   readConfig blobConf;
00148 public:
00149 
00150 
00151   //! default constructor, also sets up number of tracker instances
00152   segmentImageMerge2(int instances);
00153   ~segmentImageMerge2();
00154 
00155         void resetAll(int instances);
00156 
00157   //! set the tracking color for mass circle
00158   /*!
00159     @param r this is the red color for the output circle
00160     @param g this is the green color for the output circle
00161     @param b this is the blue color for the output circle
00162     @param instance this is the tracker to apply these settings to
00163   */
00164   void SIMsetCircleColor(int r, int g, int b, int instance);
00165 
00166   //! set the tracking colot for the bounding box
00167   //! set the tracking color for mass circle
00168   /*!
00169     @param r this is the red color for the output bounding box
00170     @param g this is the green color for the output bounding box
00171     @param b this is the blue color for the output bounding box
00172     @param instance this is the tracker to apply these settings to
00173   */
00174   void SIMsetBoxColor(int r, int g, int b, int instance);
00175 
00176   //! set default tracking color values
00177   /*!
00178     @param h initial hue value
00179     @param hstd initial boundary in standard deviation for h
00180     @param s initial satuaration value
00181     @param sstd initial boundary in standard deviation for s
00182     @param v initial intensity value
00183     @param vstd initial boundary in standard deviation for v
00184     @param instance which tracker instance to apply these settings too
00185     @param adapt tells if you want these values to adapt
00186   */
00187   void SIMsetTrackColor(float h, float hstd,
00188                      float s, float sstd,
00189                      float v, float vstd,
00190                      int instance, bool adapt, int avg);
00191 
00192   //! set initial adaptive color thresholds for tracking
00193   void SIMsetAdapt(float ha, bool haSTD, float sa, bool saSTD,
00194                 float va, bool vaSTD, int instance, bool useCluster);
00195 
00196   //! set up hard bounds for color adaptation
00197   /*!
00198     @param Hupper upper bound for adaptive hue
00199     @param Hlower lower bound for adaptive hue
00200     @param Supper upper bound for adaptive saturation
00201     @param Slower lower bound for adaptive saturation
00202     @param Vupper upper bound for adaptive intensity
00203     @param Vlower lower bound for adaptive intensity
00204     @param instance Which tracker to apply these settings to
00205   */
00206   void SIMsetAdaptBound(float Hupper, float Hlower,
00207                      float Supper, float Slower,
00208                      float Vupper, float Vlower,
00209                      int instance);
00210 
00211   //! tell this method the pan and tilt postition the camera is moving to
00212   void SIMsetCameraPosition(float pan, float tilt, int instance
00213                          , bool stats = false);
00214 
00215   //! set frame size for color tracker
00216   void SIMsetFrame(int x1, int y1, int x2, int y2,int realX, int realY,
00217                 int instance);
00218 
00219   //! Put image one at a time into tracker and get back tracker image output
00220   /*!
00221     @param input this is the raw input image
00222     @param image this is a pointer to the output image
00223     @param outputI this is a pointer the the candidate pixel image
00224     @param instance This is the image instance to which you are using
00225     @param auxImage this is a pointer to the HSV threshold bar image
00226   */
00227   void SIMtrackImage(Image<PixRGB<byte> > input,
00228                   Image<PixRGB<byte> > *image, int instance,
00229                   Image<PixRGB<byte> > *auxImage, bool fast = false);
00230 
00231   //! put image set into tracker and let it sort all this stuff out
00232   /*!
00233     this method will track over multiple stereo pair linked cameras and
00234     produce blobs to track that agree with assumptions of stereo tracking
00235     for instance vergance and spacial locality.
00236     @param input this is the raw input image
00237     @param image this is a pointer to the output image
00238     @param outputI this is a pointer the the candidate pixel image
00239     @param instance This is the image instance to which you are using
00240     @param auxImage this is a pointer to the HSV threshold bar image
00241   */
00242   void SIMtrackImageMulti(
00243                        std::vector<Image<PixRGB<byte> > > *image,
00244                        int instances);
00245   //! merge qualities of images if needed
00246   void SIMmergeImages(Image<PixRGB<byte> > *image);
00247   //! update the vergance distance if needed for cameras
00248   /*! feed in the new distance to target and extact P over expected
00249      vergance
00250      @param distance is a measure in inches (sorry)
00251   */
00252   void SIMupdateVergance(float distance, float gaussBase = 36);
00253 
00254   //! apply probabalistic model over multiple stereo cameras for vergance
00255   /*! This method will calculate the most likely blob from a set of blobs based
00256     upon the vergance of the cameras. That is, joined stereo pairs should.
00257     experiance vergance to a target. This method creates virtual springs to
00258     pull the cameras into vergance with each other based upon the probability
00259     that a target will bring a camera into vergance with the other cameras.
00260     To use this method you must have defined a probabalistic model over
00261     vergance in the cameras.
00262     @param instance this is the instance of the track, in this case the camera
00263     @param doTracked this is true if you wish to apply to cameras that \
00264     are not currently in loss of track (LOT)
00265   */
00266   void SIMverganceSpring(int instance, int current, bool doTracked);
00267   //! get back X and Y coords for tracking
00268   void SIMgetImageTrackXY(int *x, int *y, int instance);
00269   //! get back X and Y coords for tracking
00270   void SIMgetImageTrackXY2(int *x, int *y, int instance);
00271   //! get back merged X and Y coords for tracking
00272   void SIMgetImageTrackXYMerge(int *x, int *y);
00273   //! return true if loss of track
00274   bool SIMreturnLOT(int instance);
00275   //! return the P of a good track
00276   float SIMreturnCameraProb(int instance);
00277   //! return if camera should move based upon maximum LOT's
00278   bool SIMdoMoveCamera(int instance, float *doPan, float *doTilt);
00279   //! return the image of candidate pixels
00280   Image<byte> SIMreturnCandidateImage(int instance);
00281   //! Set up color clustering for tracker
00282   /*! Call this method before calling SIMclsuterColor to set it up. Do
00283     this only once.
00284     @param sizeX This is the width of the image to be processed
00285     @param sizeY this is the height of the image to be processed
00286     @param instances How many tracker instances are being used
00287     @param hweight this is the weight to be given to hue in analysis
00288     @param sweight this is the weight to be given to saturation in analysis
00289     @param vweight this is the weight to be given to luminance in analysis
00290   */
00291   void SIMSetCluster(int sizeX, int sizeY, int instances,
00292                      float hweight, float sweight,
00293                      float vweight);
00294   //! find object in scene that's a best match using clustering
00295   /*! run this to find out which color to use for tracking.This will
00296     take and image and cluster it looking for the best color match
00297     in the image to track
00298   */
00299   void SIMclusterColor(Image<PixRGB<float> > image, int instance);
00300   //!Project corresponding points in 3D
00301   bool SIMstereoMatch(PixelPoint points[2],
00302                    CameraParams params[2],Point3D* retPoint);
00303   //! return the probability of X given Xbar and std using gaussian
00304   double SIMPgauss(double X, double Xbar, double std);
00305 
00306 };
00307 
00308 #endif
Generated on Sun May 8 08:07:04 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3