00001 /*!@file BeoSub/BeoSubCanny.H A class for the vision(ported from test-canny) */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2003 // 00005 // by the 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: Zack Gossman <gossman@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/BeoSub/BeoSubCanny.H $ 00035 // $Id: BeoSubCanny.H 8491 2007-06-13 23:51:45Z beobot $ 00036 // 00037 00038 #ifndef BEOSUBCANNY_H_DEFINED 00039 #define BEOSUBCANNY_H_DEFINED 00040 00041 00042 /**************************TODO************************* -NOTE: 00043 switching to std vectors BREAKS powell, even if changed 00044 throughout. Note sure why 00045 00046 -MAKE a tester executable to spool camera values (similar to 00047 those displayed at the start of test-multigrab) continually, 00048 checking white balance, exposure and gain in order to manually 00049 calibrate the cameras at wet test time. Auto set is not working 00050 well. NOTE that every color setting is currently rcognizing 00051 white! this is bad! something wrong with the V range? <-seems 00052 fixable using a mix of changing V and hardware stuff 00053 00054 -SUGGESTION: instead of returning final recognized position data 00055 using a struct, inseat store data in shape class and return using 00056 reference. (allows shapes with different dimensions to return 00057 useful data, unlike current standard 5 dims) 00058 *******************************************************/ 00059 00060 #include <math.h> 00061 #include <stdio.h> 00062 #include <stdlib.h> 00063 00064 #include "BeoSub/hysteresis.H" 00065 #include "GUI/XWindow.H" 00066 #include "Image/ColorOps.H" 00067 #include "Image/DrawOps.H" 00068 #include "Image/FilterOps.H" 00069 #include "Image/Image.H" 00070 #include "Image/MathOps.H" 00071 #include "Image/Transforms.H" 00072 #include "Raster/Raster.H" 00073 #include "VFAT/segmentImageTrackMC.H" 00074 #include "rutz/shared_ptr.h" 00075 00076 //canny 00077 #define BOOSTBLURFACTOR 90.0 00078 //powell 00079 #define TOL 2.0e-4 00080 #define ITMAX 200 00081 //brent... 00082 #define ITMAXB 100 00083 #define CGOLD 0.3819660 00084 #define ZEPS 1.0e-10 00085 #define SHFT(a,b,c,d) (a)=(b);(b)=(c);(c)=(d); 00086 #define SIGN(a,b) ((b)>=0.0?fabs(a):-fabs(a)) 00087 //mnbrak 00088 #define GOLD 1.618034 00089 #define GLIMIT 100.0 00090 #define TINY 1.0e-20 00091 00092 //CAMERA STUFF 00093 00094 #include "Component/ModelManager.H" 00095 #include "Devices/IEEE1394grabber.H" 00096 #include "Devices/V4Lgrabber.H" 00097 #include "Transport/FrameIstream.H" 00098 #include "Util/Timer.H" 00099 #include "Util/Types.H" 00100 #include "Util/log.H" 00101 00102 #include <cstdio> 00103 #include <cstdlib> 00104 #include <cstring> 00105 00106 //nrutil 00107 #define FREE_ARG char* 00108 00109 //SHAPE STUFF 00110 #include "BeoSub/CannyModel.H" 00111 00112 //! Definition and access functions for the BeoSubCanny 00113 /*! BeoSubCanny is the vision class for submarine. It implements 00114 the Canny algorithm and can track shape and color*/ 00115 class BeoSubCanny : public ModelComponent 00116 { 00117 public: 00118 // ###################################################################### 00119 /*! @name Constructors and Destructors */ 00120 //@{ 00121 00122 //! Constructor 00123 BeoSubCanny(OptionManager& mgr, 00124 const std::string& descrName = "BeoSubCanny", 00125 const std::string& tagName = "BeoSubCanny"); 00126 00127 //! Destructor 00128 ~BeoSubCanny(); 00129 00130 //@} 00131 00132 // ###################################################################### 00133 /*! @name member functions */ 00134 //@{ 00135 int canny(unsigned char *image, int rows, int cols, float sigma, 00136 float tlow, float thigh, unsigned char **edge, char *fname); 00137 void gaussian_smooth(unsigned char *image, int rows, int cols, float sigma, 00138 short int **smoothedim); 00139 void make_gaussian_kernel(float sigma, float **kernel, int *windowsize); 00140 void derrivative_x_y(short int *smoothedim, int rows, int cols, 00141 short int **delta_x, short int **delta_y); 00142 void magnitude_x_y(short int *delta_x, short int *delta_y, int rows, int cols, 00143 short int **magnitude); 00144 void radian_direction(short int *delta_x, short int *delta_y, int rows, 00145 int cols, float **dir_radians, int xdirtag, int ydirtag); 00146 double angle_radians(double x, double y); 00147 void grabImage(Image<PixRGB<byte> >* image); 00148 00149 void setupCanny(const char* colorArg, Image< PixRGB<byte> > image, bool debug); 00150 00151 bool runCanny(rutz::shared_ptr<ShapeModel>& shapeArg); //FIX: change later so this returns struct with found info (position, etc) 00152 00153 //From Numerical Recipes 00154 bool powell(double p[], double **xi, int n, double ftol, 00155 int *iter, double *fret, rutz::shared_ptr<ShapeModel>& optimizee); 00156 double brent(double ax, double bx, double cx, double tol, 00157 double *xmin, rutz::shared_ptr<ShapeModel>& shape); 00158 void mnbrak(double *ax, double *bx, double *cx, double *fa, double *fb, 00159 double *fc, rutz::shared_ptr<ShapeModel>& shape); 00160 double f1dim(double x, rutz::shared_ptr<ShapeModel>& shape); 00161 void linmin(double p[], double xi[], int n, double *fret, 00162 rutz::shared_ptr<ShapeModel>& optimizee); 00163 //nrutil stuff 00164 double *nrVector(long nl, long nh); 00165 void free_nrVector(double *v, long nl, long nh); 00166 00167 //@} 00168 00169 private: 00170 00171 Image<float> distMap; 00172 rutz::shared_ptr<XWindow> xwin, win; 00173 bool debugmode; 00174 00175 char outfilename[128]; /* Name of the output "edge" image */ 00176 char composedfname[128]; /* Name of the output "direction" image */ 00177 unsigned char *edge; /* The output edge image */ 00178 float sigma, /* Standard deviation of the gaussian kernel. */ 00179 tlow, /* Fraction of the high threshold in hysteresis. */ 00180 thigh; /* High hysteresis threshold control. The actual 00181 threshold is the (100 * thigh) percentage point 00182 in the histogram of the magnitude of the 00183 gradient image that passes non-maximal 00184 suppression. */ 00185 int imgW, imgH, ww, hh; 00186 Image< PixRGB<byte> > colorImg; 00187 Image<byte> grayImg; 00188 00189 Image< PixRGB<byte> > display; 00190 Image<byte> temp; 00191 Image<PixRGB<byte> > Aux; 00192 Image<PixH2SV2<float> > H2SVimage; 00193 00194 segmentImageTrackMC<float,unsigned int,4> *segmenter; 00195 00196 //! Mean color to track 00197 std::vector<float> color; 00198 00199 int ncom; 00200 double *pcom,*xicom; 00201 bool hasSetup; 00202 00203 }; 00204 00205 00206 #endif