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