00001 #ifndef _DLELLIPSEDETECT_H_
00002 #define _DLELLIPSEDETECT_H_
00003
00015 #include "DLImage.h"
00016 #include "DLZone.h"
00017 #include "DLComponent.h"
00018
00019 #include <list>
00020 #include <stdio.h>
00021 #include <math.h>
00022
00023 using namespace std;
00024
00025 #define RESIZE_FILTER_WIDTH 3
00026 #define AXIS_RATIO_MAX 3.0
00027 #define BIG_LAM 1000.0
00028 #define SMALL_LAM exp(-3.0)
00029 #define MAX_AREA 1.0
00030 #define MAX_DATARUN_LENGTH 50
00031 #define PERCENGAGE_SCORES_THRESHOLD 0.10
00032 #define MIN_SPATIAL_DENSITY 0.20
00033 #define MIN_SCORE_THRESHOLD 8000
00034
00035
00036 #define MIN_CC_AREA 10
00037 #define MAX_CC_ROW_LENGTH 500
00038 #define MAX_CC_COL_LENGTH 500
00039 #define MIN_CC_ROW_LENGTH 20
00040 #define MIN_CC_COL_LENGTH 20
00041 #define MIN_ANGLE_DIFF 0.393
00042 #define MIN_MISSING_PIXELS 8
00043 #define MAX_MISSING_PIXELS 100
00044
00045 #define max(x,y) ( ((x) > (y)) ? (x) : (y) )
00046 #define min(x,y) ( ((x) < (y)) ? (x) : (y) )
00047
00048
00049 struct DLEllipseCandidate
00050 {
00051
00052 DLZone ellipseRegion;
00053 DLZone ccRegion;
00054 string sourceImageName;
00055 bool tested;
00056 int scores;
00057 double confidenceValue;
00058 string type;
00059 };
00060
00061
00062 struct DL3DBin
00063 {
00064 int indexI;
00065 int indexJ;
00066 int indexK;
00067 int scores;
00068 };
00069
00070 class DLEllipseDetect
00071 {
00072 public:
00073
00077 DLEllipseDetect() { initialized=0; };
00078
00117 DLEllipseDetect(DLImage &image, DL_BYTE mag_thres, double image_shrink_ratio,
00118 int area_min_pixel, int area_max_pixel, float axis_ratio_max,
00119 float y_center0=0, float y_center1=1.0, float x_center0=0, float x_center1=1.0,
00120 int ny_center=100, int nx_center=100, int narea=100);
00121
00125 virtual ~DLEllipseDetect() {};
00126
00134 void dlDrawEllipseRegion(DLImage &outputImage, DL3DBin *bins, int binIndex, enum DLColorMapValue markerColor=DL_RED1);
00135
00140 list <DLEllipseCandidate> dlGetDetectedEllipses() { return ellipseList; };
00141
00142 private:
00143
00144 bool initialized;
00145
00146
00147 int rows, cols;
00148
00149
00150 double resize_ratio;
00151
00152 list <DLEllipseCandidate> ellipseList;
00153
00154 DL3DBin *bins;
00155
00156
00157 int ny_center, nx_center, narea;
00158
00190 void dlPopulateBins(DLImage &magImage, DLImage &oriImage, DL_BYTE mag_thres, int area_min_pixel, int area_max_pixel, float axis_ratio_max,
00191 float y_center0, float y_center1, float x_center0, float x_center1, int *score);
00192
00197 void dlComputeParameters(float x1,float y1,float p1,float q1, float x2,float y2,float p2,float q2,
00198 float lambda,float *a,float *b,float *c,float *f,float *g,float *h);
00199
00205 float dlFindLambdaRange(float x1,float y1,float p1,float q1,float x2,float y2,float p2,float q2);
00206
00211 void dlComputeCenter(float *x0,float *y0,float a,float b,float c,float f,float g,float h);
00212
00217 float dlComputeArea(float a,float b,float c,float f,float g,float h);
00218
00222 void dlComputeEigenValue(float *lam1,float *lam2,float a,float b,float h);
00223
00228 float dlComputeOrientation(float a,float b,float c,float f,float g,float h);
00229
00234 float dlComputeMajorMinorRatio(float a,float b,float c,float f,float g,float h);
00235
00240 bool dlCheckMajorMinorRatio(float a,float b,float c,float f,float g,float h,float axis_ratio_max);
00241
00242 void dlRemoveLongJunctions(DLImage &magImage, DL_BYTE mag_thres);
00243
00247 void dlRemoveShortJunctions(DLImage &magImage, DL_BYTE mag_thres);
00248
00252 void dlRemoveVerticalStrip(DL_BYTE* magData, int juncRow, int juncCol, DL_BYTE mag_thres);
00253
00257 void dlRemoveHorizontalStrip(DL_BYTE* magData, int juncRow, int juncCol, DL_BYTE mag_thres);
00258
00262 void dlFilterLargeCC(DLImage &magImage, DL_BYTE edgeThresold);
00263
00267 void dlRemoveCC(DLImage &magImage, DLComponent &largeC);
00268
00272 void dlVerifyEllipseCandidates(DLImage &image);
00273
00277 void dlLocateCCBoundary(DLImage &magImage, DLEllipseCandidate &detectedEllipse, DL_BYTE edge_thres);
00278
00279
00280 };
00281
00282 #endif //_DLELLIPSEDETECT_H_