00001 /*!@file VFAT/segmentImageMerge.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/segmentImageMerge.H $ 00035 // $Id: segmentImageMerge.H 4663 2005-06-23 17:47:28Z rjpeters $ 00036 // 00037 00038 #include "Devices/cameraConf.H" 00039 #include "Image/Image.H" 00040 #include "Util/Timer.H" 00041 #include "Util/Types.H" 00042 #include "Util/log.H" 00043 #include "Util/stats.H" 00044 #include "VFAT/PointClasses.H" 00045 #include "VFAT/segmentImageTrack.H" 00046 #include <math.h> 00047 00048 class segmentImageMerge 00049 { 00050 // create a billion vectors for holding everything we need 00051 // this is lazy, but RAM is cheap ;) 00052 private: 00053 segmentImage *segment; 00054 stats<float> Stats; 00055 cameraConf camera; 00056 int instanceNumber; 00057 int mergeGotoX; 00058 int mergeGotoY; 00059 bool fast; 00060 float moveMeanNormal; 00061 float moveStdNormal; 00062 00063 std::vector<float> H; 00064 std::vector<float> S; 00065 std::vector<float> V; 00066 std::vector<float> Hstd; 00067 std::vector<float> Sstd; 00068 std::vector<float> Vstd; 00069 std::vector<float> HA; 00070 std::vector<float> SA; 00071 std::vector<float> VA; 00072 std::vector<float> HU; 00073 std::vector<float> SU; 00074 std::vector<float> VU; 00075 std::vector<float> HL; 00076 std::vector<float> SL; 00077 std::vector<float> VL; 00078 std::vector<float> delay; 00079 std::vector<float> cameraMovePan; 00080 std::vector<float> cameraMoveTilt; 00081 std::vector<float> cameraGotoPan; 00082 std::vector<float> cameraGotoTilt; 00083 std::vector<float> cameraMu; 00084 std::vector<float> cameraSigma; 00085 std::vector<float> meanMove; 00086 std::vector<float> stdMove; 00087 std::vector<std::vector< float> > moveRecord; 00088 std::vector<std::vector< float> > moveRecordGrad; 00089 00090 00091 std::vector<int> LOTcount; 00092 std::vector<int> height; 00093 std::vector<int> width; 00094 std::vector<int> gotoX; 00095 std::vector<int> gotoY; 00096 std::vector<int> circleRed; 00097 std::vector<int> circleGreen; 00098 std::vector<int> circleBlue; 00099 std::vector<int> boxRed; 00100 std::vector<int> boxGreen; 00101 std::vector<int> boxBlue; 00102 std::vector<int> didCircleColor; 00103 std::vector<int> didBoxColor; 00104 std::vector<int> didTrackColor; 00105 std::vector<int> recordCounter; 00106 00107 std::vector<bool> adpt; 00108 std::vector<bool> HASTD; 00109 std::vector<bool> SASTD; 00110 std::vector<bool> VASTD; 00111 std::vector<bool> moveCamera; 00112 std::vector<Timer> tim; 00113 std::vector<segmentImageTrack> track; 00114 std::vector<Image<byte> > temp; 00115 void colorProcessBlobs(int instance); 00116 Image<PixRGB<byte> > *imageHold; 00117 Image<PixRGB<byte> > *auxHold; 00118 Image<PixRGB<float> > *fimaHold; 00119 public: 00120 //! default constructor, also sets up number of tracker instances 00121 segmentImageMerge(int instances); 00122 ~segmentImageMerge(); 00123 00124 //! set the tracking color for mass circle 00125 /*! 00126 @param r this is the red color for the output circle 00127 @param g this is the green color for the output circle 00128 @param b this is the blue color for the output circle 00129 @param instance this is the tracker to apply these settings to 00130 */ 00131 void setCircleColor(int r, int g, int b, int instance); 00132 00133 //! set the tracking colot for the bounding box 00134 //! set the tracking color for mass circle 00135 /*! 00136 @param r this is the red color for the output bounding box 00137 @param g this is the green color for the output bounding box 00138 @param b this is the blue color for the output bounding box 00139 @param instance this is the tracker to apply these settings to 00140 */ 00141 void setBoxColor(int r, int g, int b, int instance); 00142 00143 //! set default tracking color values 00144 /*! 00145 @param h initial hue value 00146 @param hstd initial boundary in standard deviation for h 00147 @param s initial satuaration value 00148 @param sstd initial boundary in standard deviation for s 00149 @param v initial intensity value 00150 @param vstd initial boundary in standard deviation for v 00151 @param instance which tracker instance to apply these settings too 00152 @param adapt tells if you want these values to adapt 00153 */ 00154 void setTrackColor(float h, float hstd, 00155 float s, float sstd, 00156 float v, float vstd, 00157 int instance, bool adapt, int avg); 00158 00159 //! set initial adaptive color thresholds for tracking 00160 void setAdapt(float ha, bool haSTD, float sa, bool saSTD, 00161 float va, bool vaSTD, int instance); 00162 00163 //! set up hard bounds for color adaptation 00164 /*! 00165 @param Hupper upper bound for adaptive hue 00166 @param Hlower lower bound for adaptive hue 00167 @param Supper upper bound for adaptive saturation 00168 @param Slower lower bound for adaptive saturation 00169 @param Vupper upper bound for adaptive intensity 00170 @param Vlower lower bound for adaptive intensity 00171 @param instance Which tracker to apply these settings to 00172 */ 00173 void setAdaptBound(float Hupper, float Hlower, 00174 float Supper, float Slower, 00175 float Vupper, float Vlower, 00176 int instance); 00177 00178 //! tell this method the pan and tilt postition the camera is moving to 00179 void setCameraPosition(float pan, float tilt, int instance 00180 , bool stats = false); 00181 00182 //! set frame size for color tracker 00183 void setFrame(int x1, int y1, int x2, int y2,int realX, int realY, 00184 int instance); 00185 00186 //! Put image one at a time into tracker and get back tracker image output 00187 /*! 00188 @param input this is the raw input image 00189 @param image this is a pointer to the output image 00190 @param outputI this is a pointer the the candidate pixel image 00191 @param instance This is the image instance to which you are using 00192 @param auxImage this is a pointer to the HSV threshold bar image 00193 */ 00194 void trackImage(Image<PixRGB<byte> > input, 00195 Image<PixRGB<byte> > *image, int instance, 00196 Image<PixRGB<byte> > *auxImage, bool fast = false); 00197 00198 //! put image set into tracker and let it sort all this stuff out 00199 /*! 00200 this method will track over multiple stereo pair linked cameras and 00201 produce blobs to track that agree with assumptions of stereo tracking 00202 for instance vergance and spacial locality. 00203 @param input this is the raw input image 00204 @param image this is a pointer to the output image 00205 @param outputI this is a pointer the the candidate pixel image 00206 @param instance This is the image instance to which you are using 00207 @param auxImage this is a pointer to the HSV threshold bar image 00208 */ 00209 void trackImageMulti( 00210 std::vector<Image<PixRGB<byte> > > *image, 00211 int instances); 00212 //! merge qualities of images if needed 00213 void mergeImages(Image<PixRGB<byte> > *image); 00214 //! update the vergance distance if needed for cameras 00215 /*! feed in the new distance to target and extact P over expected 00216 vergance 00217 @param distance is a measure in inches (sorry) 00218 */ 00219 void updateVergance(float distance, float gaussBase = 36); 00220 00221 //! apply probabalistic model over multiple stereo cameras for vergance 00222 /*! This method will calculate the most likely blob from a set of blobs based 00223 upon the vergance of the cameras. That is, joined stereo pairs should. 00224 experiance vergance to a target. This method creates virtual springs to 00225 pull the cameras into vergance with each other based upon the probability 00226 that a target will bring a camera into vergance with the other cameras. 00227 To use this method you must have defined a probabalistic model over 00228 vergance in the cameras. 00229 @param instance this is the instance of the track, in this case the camera 00230 @param doTracked this is true if you wish to apply to cameras that \ 00231 are not currently in loss of track (LOT) 00232 */ 00233 void verganceSpring(int instance, int current, bool doTracked); 00234 //! get back X and Y coords for tracking 00235 void getImageTrackXY(int *x, int *y, int instance); 00236 //! get back X and Y coords for tracking 00237 void getImageTrackXY2(int *x, int *y, int instance); 00238 //! get back merged X and Y coords for tracking 00239 void getImageTrackXYMerge(int *x, int *y); 00240 //! return true if loss of track 00241 bool returnLOT(int instance); 00242 //! return the P of a good track 00243 float returnCameraProb(int instance); 00244 //! return if camera should move based upon maximum LOT's 00245 bool doMoveCamera(int instance, float *doPan, float *doTilt); 00246 //! return the image of candidate pixels 00247 Image<byte> returnCandidateImage(int instance); 00248 //!Project corresponding points in 3D 00249 bool StereoMatch(PixelPoint points[2], CameraParams params[2], 00250 Point3D* retPoint); 00251 00252 };