00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef BEOSUBCANNY_H_DEFINED
00039 #define BEOSUBCANNY_H_DEFINED
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
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
00077 #define BOOSTBLURFACTOR 90.0
00078
00079 #define TOL 2.0e-4
00080 #define ITMAX 200
00081
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
00088 #define GOLD 1.618034
00089 #define GLIMIT 100.0
00090 #define TINY 1.0e-20
00091
00092
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
00107 #define FREE_ARG char*
00108
00109
00110 #include "BeoSub/CannyModel.H"
00111
00112
00113
00114
00115 class BeoSubCanny : public ModelComponent
00116 {
00117 public:
00118
00119
00120
00121
00122
00123 BeoSubCanny(OptionManager& mgr,
00124 const std::string& descrName = "BeoSubCanny",
00125 const std::string& tagName = "BeoSubCanny");
00126
00127
00128 ~BeoSubCanny();
00129
00130
00131
00132
00133
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);
00152
00153
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
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];
00176 char composedfname[128];
00177 unsigned char *edge;
00178 float sigma,
00179 tlow,
00180 thigh;
00181
00182
00183
00184
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
00197 std::vector<float> color;
00198
00199 int ncom;
00200 double *pcom,*xicom;
00201 bool hasSetup;
00202
00203 };
00204
00205
00206 #endif