00001 #ifndef _DLSIGNATUREDETECT_H_
00002 #define _DLSIGNATUREDETECT_H_
00003
00004 #include "DLImage.h"
00005 #include "getLines.h"
00006 #include "DLConnectedComponents.h"
00007 #include "DLBitsPerPixelConverter.h"
00008 #include "DLZone.h"
00009 #include "DLConst.h"
00010 #include "DLLogger.h"
00011
00012 #include <list>
00013
00014 using namespace std;
00015
00017 #define RESIZE_FILTER_WIDTH 3.0
00019 #define EDGE_MAG_THRE 50
00021 #define MIN_ORIENTATION_DIFF 8
00023 #define MAX_SIG_SPACING 37
00025 #define MAX_SIG_HEIGHT 600
00027 #define MAX_DATARUN_LENGTH 50
00029 #define LAMBDA_UPPER 10.0
00031 #define SMALL_EPSILON 0.01
00033 #define ORTHOGAL_LOWER 58
00035 #define ORTHOGAL_UPPER 68
00037 #define ORI_BINS 32
00039 #define CC_DIMENSION_RATIO_LOWER 0.15
00041 #define CC_DIMENSION_RATIO_UPPER 5.0
00043 #define SIG_DIMENSION_RATIO_LOWER 0.17
00045 #define SIG_DIMENSION_RATIO_UPPER 1.33
00047 #define MAX_CC_DENSITY 0.5
00049 #define MAX_CC_PER_REGION 50
00050
00054 struct DLSignatureCandidate
00055 {
00057 DLZone sigRegion;
00059 string sourceImageName;
00061 unsigned long scores;
00063 int largestNeighScore;
00065 bool tested;
00067 string type;
00068 };
00069
00070
00074 int comp (const void *entry1, const void *entry2);
00075
00094 class DLSignatureDetect
00095 {
00096 public:
00097
00101 enum PARAMETERSET
00102 {
00103 DL_ENGLISH_PRINT = 1,
00104 DL_ARABIC_HANDWRITING = 2
00105 };
00106
00115 DLSignatureDetect(const char *fname, PARAMETERSET parameterSet=DL_ENGLISH_PRINT, double resizeRatio=2.0, bool useContext=true);
00116
00126 DLSignatureDetect(const DLImage &srcImage, const char *fname, PARAMETERSET parameterSet=DL_ENGLISH_PRINT, double resizeRatio=2.0, bool useContext=true);
00127
00131 ~DLSignatureDetect();
00132
00137 list <DLSignatureCandidate> dlGetDetectedSignatures() { return sigList; };
00138
00143 bool dlGotSignatures() { return !sigList.empty(); };
00144
00145
00146 private:
00147
00151 struct DLSignatureDetectParameters
00152 {
00154 unsigned long lowScoreThreshold;
00156 unsigned long highScoreThreshold;
00158 unsigned long ultraHighScoreThreshold;
00160 unsigned long minCCScore;
00162 int maxSignaturePerPage;
00164 int maxCCHeight;
00166 int maxCCWidth;
00168 int minCCMass;
00170 double maxSigDensity;
00171 };
00172
00178 void dlInitializeSignatureDetect(DLSignatureDetect::PARAMETERSET parameterSet);
00179
00184 void dlDetectSignatures();
00185
00191 void dlLocatePageFooter();
00192
00199 void dlAnalyzeOriHistogram(DL_BYTE* magImageData, DL_BYTE* oriImageData, DLComponent &cComponent);
00200
00205 double dlCalcAvgVerLineSeparation();
00206
00214 void dlRemoveVerticalStrip(DL_BYTE* magImageData, int juncRow, int juncCol, DL_BYTE mag_thres);
00215
00223 void dlRemoveHorizontalStrip(DL_BYTE* magImageData, int juncRow, int juncCol, DL_BYTE mag_thres);
00224
00232 void dlFilterLargeCC(DLImage &magImage, DLImage &oriImage, DL_BYTE edgeThresold);
00233
00239 void dlRemoveCC(DL_BYTE *magImageData, DLComponent &cComponent);
00240
00254 double dlFindLambdaRange(float x1,float y1,float p1,float q1,float x2,float y2,float p2,float q2);
00255
00262 double dlComputeDensity(DLImage &grayImage, DL_BYTE pixelValue);
00263
00265 DLImage sourceImage;
00266
00268 string sourceImageName;
00269
00271 list <DLSignatureCandidate> sigList;
00272
00274 list <DLSignatureCandidate> ccSigList;
00275
00277 DLSignatureDetectParameters sigDetectParameters;
00278
00280 bool useContext;
00281
00283 bool resKnown;
00284
00286 double hRes;
00287
00289 double vRes;
00290
00292 double resolutionScale;
00293
00295 double resizeRatio;
00296
00298 int pageWidth;
00299
00301 int rows;
00302
00304 int cols;
00305
00307 DLConnectedComponents *cc;
00308
00310 getLines *lineOjects;
00311
00313 DLlineInfo *lineInfo;
00314
00316 double avgLineHeight;
00317
00319 double avgLineSeparation;
00320
00322 int widthAverage;
00323
00325 int widthLongestLine;
00326
00330 int fromTop;
00331
00334 int leftMargin;
00335
00336 };
00337
00338 #endif //_DLSIGDETECT_H_
00339