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 #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
00067 #define BOOSTBLURFACTOR 90.0
00068
00069 #define TOL 2.0e-4
00070 #define ITMAX 200
00071
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
00078 #define GOLD 1.618034
00079 #define GLIMIT 100.0
00080 #define TINY 1.0e-20
00081
00082
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
00097 #define FREE_ARG char*
00098
00099
00100 #include "BeoSub/CannyModel.H"
00101
00102
00103
00104
00105 class BeoSubCanny : public ModelComponent
00106 {
00107 public:
00108
00109
00110
00111
00112
00113 BeoSubCanny(OptionManager& mgr,
00114 const std::string& descrName = "BeoSubCanny",
00115 const std::string& tagName = "BeoSubCanny");
00116
00117
00118 ~BeoSubCanny();
00119
00120
00121
00122
00123
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);
00142
00143
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
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];
00166 char composedfname[128];
00167 unsigned char *edge;
00168 float sigma,
00169 tlow,
00170 thigh;
00171
00172
00173
00174
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
00187 std::vector<float> color;
00188
00189 int ncom;
00190 double *pcom,*xicom;
00191 bool hasSetup;
00192
00193 };
00194
00195
00196 #endif