00001 #ifndef _RAC_DETECT_H
00002 #define _RAC_DETECT_H
00003
00004 #include <ds/list.h>
00005 #include "ds/arrayold.h"
00006
00007 #ifndef NULL
00008 #define NULL 0
00009 #endif
00010
00011 #ifndef BYTE
00012 #define BYTE unsigned char
00013 #endif
00014
00015 #ifndef ROUND
00016 #define ROUND(x) (int) ( (x>0) ? (x+=0.5) : (x-=0.5) )
00017 #endif
00018
00022 struct RacPixel
00023 {
00024 int x;
00025 int y;
00026 };
00027
00029 typedef DsArrayOld<RacPixel*> RacPixelArray;
00030
00036 struct RacLabel
00037 {
00038 bool draw;
00039 int nPixel;
00040 int nVertices;
00041 int labelId;
00042 RacPixelArray *pixelArray;
00043 RacPixelArray *verticesArray;
00044
00045 RacPixel vertices[4];
00046 };
00047
00048
00050 typedef DsPList<RacLabel> RacLabelList;
00051
00053 typedef DsPListIterator<RacLabel> RacLabelListItr;
00054
00060 class Rac
00061 {
00062 public:
00063
00064 Rac();
00065 ~Rac();
00066
00071 void setSize(const int width, const int height);
00072
00074 void find(BYTE *imgSrc);
00075
00077 void findVertices();
00078
00080 void reset();
00081
00082 RacLabelList labelList;
00083 int *imgLabel;
00084 bool ok;
00085
00086 private:
00087
00094 void findRecur(int x, int y, int label, unsigned int depth);
00095
00102 int chainHull( RacPixelArray &P, int n, RacPixelArray &H);
00103
00104 int isLeft( RacPixel P0, RacPixel P1, RacPixel P2 );
00105
00111 bool filterVertices(RacPixelArray &verticesArray, int size, RacPixel *vertices);
00112
00114 float dot(RacPixel &a, RacPixel &b, RacPixel &c);
00115 static int label;
00116 int width;
00117 int height;
00118 BYTE *img;
00119
00120 RacLabelListItr *labelItr;
00121
00122 unsigned int nextPoolPixel;
00123 RacPixelArray pool;
00124 };
00125
00126 #endif