Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mfx.cpp File Reference
#include "mfdefs.h"
#include "mfoutline.h"
#include "clusttool.h"
#include "const.h"
#include "intfx.h"
#include "normalis.h"
#include "params.h"
#include <math.h>

Go to the source code of this file.

Macros

#define NormalizeAngle(A)   ( (((A)<0)?((A)+2*PI):(A)) / (2*PI) )
 

Functions

FLOAT32 ComputeOrientation (MFEDGEPT *Start, MFEDGEPT *End)
 
MICROFEATURES ConvertToMicroFeatures (MFOUTLINE Outline, MICROFEATURES MicroFeatures)
 
MICROFEATURE ExtractMicroFeature (MFOUTLINE Start, MFOUTLINE End)
 
CHAR_FEATURES BlobMicroFeatures (TBLOB *Blob, const DENORM &denorm)
 

Variables

double classify_min_slope = 0.414213562
 
double classify_max_slope = 2.414213562
 

Macro Definition Documentation

#define NormalizeAngle (   A)    ( (((A)<0)?((A)+2*PI):(A)) / (2*PI) )

Macros

Definition at line 45 of file mfx.cpp.

Function Documentation

CHAR_FEATURES BlobMicroFeatures ( TBLOB Blob,
const DENORM denorm 
)

Public Code

Definition at line 62 of file mfx.cpp.

62  {
63 /*
64  ** Parameters:
65  ** Blob blob to extract micro-features from
66  ** denorm control parameter to feature extractor
67  ** Operation:
68  ** This routine extracts micro-features from the specified
69  ** blob and returns a list of the micro-features. All
70  ** micro-features are normalized according to the specified
71  ** line statistics.
72  ** Return: List of micro-features extracted from the blob.
73  ** Exceptions: none
74  ** History: 7/21/89, DSJ, Created.
75  */
76  MICROFEATURES MicroFeatures = NIL_LIST;
77  FLOAT32 XScale, YScale;
78  LIST Outlines;
79  LIST RemainingOutlines;
80  MFOUTLINE Outline;
81  INT_FEATURE_ARRAY blfeatures;
82  INT_FEATURE_ARRAY cnfeatures;
83  INT_FX_RESULT_STRUCT results;
84 
85  if (Blob != NULL) {
86  Outlines = ConvertBlob (Blob);
87  if (!ExtractIntFeat(Blob, denorm, blfeatures, cnfeatures, &results))
88  return NULL;
89  XScale = 0.2f / results.Ry;
90  YScale = 0.2f / results.Rx;
91 
92  RemainingOutlines = Outlines;
93  iterate(RemainingOutlines) {
94  Outline = (MFOUTLINE) first_node (RemainingOutlines);
95  CharNormalizeOutline (Outline,
96  results.Xmean, results.Ymean,
97  XScale, YScale);
98  }
99 
100  RemainingOutlines = Outlines;
101  iterate(RemainingOutlines) {
102  Outline = (MFOUTLINE) first_node (RemainingOutlines);
104  MarkDirectionChanges(Outline);
105  MicroFeatures = ConvertToMicroFeatures (Outline, MicroFeatures);
106  }
107  FreeOutlines(Outlines);
108  }
109  return ((CHAR_FEATURES) MicroFeatures);
110 } /* BlobMicroFeatures */
void FindDirectionChanges(MFOUTLINE Outline, FLOAT32 MinSlope, FLOAT32 MaxSlope)
Definition: mfoutline.cpp:157
void CharNormalizeOutline(MFOUTLINE Outline, FLOAT32 XCenter, FLOAT32 YCenter, FLOAT32 XScale, FLOAT32 YScale)
Definition: mfoutline.cpp:439
#define NIL_LIST
Definition: oldlist.h:126
#define NULL
Definition: host.h:144
void MarkDirectionChanges(MFOUTLINE Outline)
Definition: mfoutline.cpp:243
float FLOAT32
Definition: host.h:111
char * CHAR_FEATURES
Definition: ocrfeatures.h:79
void FreeOutlines(LIST Outlines)
Definition: mfoutline.cpp:227
double classify_max_slope
Definition: mfx.cpp:39
LIST ConvertBlob(TBLOB *blob)
Definition: mfoutline.cpp:41
INT_FEATURE_STRUCT INT_FEATURE_ARRAY[MAX_NUM_INT_FEATURES]
Definition: baseapi.h:66
int ExtractIntFeat(TBLOB *Blob, const DENORM &denorm, INT_FEATURE_ARRAY BLFeat, INT_FEATURE_ARRAY CNFeat, INT_FX_RESULT_STRUCT *Results, inT32 *FeatureOutlineArray)
Definition: intfx.cpp:143
MICROFEATURES ConvertToMicroFeatures(MFOUTLINE Outline, MICROFEATURES MicroFeatures)
Definition: mfx.cpp:149
LIST MFOUTLINE
Definition: mfoutline.h:33
double classify_min_slope
Definition: mfx.cpp:37
#define iterate(l)
Definition: oldlist.h:159
#define first_node(l)
Definition: oldlist.h:139
FLOAT32 ComputeOrientation ( MFEDGEPT Start,
MFEDGEPT End 
)

Definition at line 118 of file mfx.cpp.

118  {
119 /*
120  ** Parameters:
121  ** Start starting edge point of micro-feature
122  ** End ending edge point of micro-feature
123  ** Globals: none
124  ** Operation:
125  ** This routine computes the orientation parameter of the
126  ** specified micro-feature. The orientation is the angle of
127  ** the vector from Start to End. It is normalized to a number
128  ** between 0 and 1 where 0 corresponds to 0 degrees and 1
129  ** corresponds to 360 degrees. The actual range is [0,1), i.e.
130  ** 1 is excluded from the range (since it is actual the
131  ** same orientation as 0). This routine assumes that Start
132  ** and End are not the same point.
133  ** Return: Orientation parameter for the specified micro-feature.
134  ** Exceptions: none
135  ** History: 7/27/89, DSJ, Created.
136  */
138 
139  Orientation = NormalizeAngle (AngleFrom (Start->Point, End->Point));
140 
141  /* ensure that round-off errors do not put circular param out of range */
142  if ((Orientation < 0) || (Orientation >= 1))
143  Orientation = 0;
144  return (Orientation);
145 } /* ComputeOrientation */
#define NormalizeAngle(A)
Definition: mfx.cpp:45
float FLOAT32
Definition: host.h:111
FPOINT Point
Definition: mfoutline.h:40
#define AngleFrom(A, B)
Definition: fpoint.h:42
MICROFEATURES ConvertToMicroFeatures ( MFOUTLINE  Outline,
MICROFEATURES  MicroFeatures 
)

Definition at line 149 of file mfx.cpp.

150  {
151 /*
152  ** Parameters:
153  ** Outline outline to extract micro-features from
154  ** MicroFeatures list of micro-features to add to
155  ** Globals: none
156  ** Operation:
157  ** This routine
158  ** Return: List of micro-features with new features added to front.
159  ** Exceptions: none
160  ** History: 7/26/89, DSJ, Created.
161  */
162  MFOUTLINE Current;
163  MFOUTLINE Last;
164  MFOUTLINE First;
166 
167  if (DegenerateOutline (Outline))
168  return (MicroFeatures);
169 
170  First = NextExtremity (Outline);
171  Last = First;
172  do {
173  Current = NextExtremity (Last);
174  if (!PointAt(Current)->Hidden) {
175  NewFeature = ExtractMicroFeature (Last, Current);
176  if (NewFeature != NULL)
177  MicroFeatures = push (MicroFeatures, NewFeature);
178  }
179  Last = Current;
180  }
181  while (Last != First);
182 
183  return (MicroFeatures);
184 } /* ConvertToMicroFeatures */
#define NULL
Definition: host.h:144
LIST push(LIST list, void *element)
Definition: oldlist.cpp:323
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
#define DegenerateOutline(O)
Definition: mfoutline.h:74
MICROFEATURE ExtractMicroFeature(MFOUTLINE Start, MFOUTLINE End)
Definition: mfx.cpp:188
#define PointAt(O)
Definition: mfoutline.h:75
FLOAT32 * MICROFEATURE
Definition: mfdefs.h:34
MFOUTLINE NextExtremity(MFOUTLINE EdgePoint)
Definition: mfoutline.cpp:287
MICROFEATURE ExtractMicroFeature ( MFOUTLINE  Start,
MFOUTLINE  End 
)

Definition at line 188 of file mfx.cpp.

188  {
189 /*
190  ** Parameters:
191  ** Start starting point of micro-feature
192  ** End ending point of micro-feature
193  ** Globals: none
194  ** Operation:
195  ** This routine computes the feature parameters which describe
196  ** the micro-feature that starts and Start and ends at End.
197  ** A new micro-feature is allocated, filled with the feature
198  ** parameters, and returned. The routine assumes that
199  ** Start and End are not the same point. If they are the
200  ** same point, NULL is returned, a warning message is
201  ** printed, and the current outline is dumped to stdout.
202  ** Return: New micro-feature or NULL if the feature was rejected.
203  ** Exceptions: none
204  ** History: 7/26/89, DSJ, Created.
205  ** 11/17/89, DSJ, Added handling for Start and End same point.
206  */
208  MFEDGEPT *P1, *P2;
209 
210  P1 = PointAt(Start);
211  P2 = PointAt(End);
212 
213  NewFeature = NewMicroFeature ();
214  NewFeature[XPOSITION] = AverageOf(P1->Point.x, P2->Point.x);
215  NewFeature[YPOSITION] = AverageOf(P1->Point.y, P2->Point.y);
216  NewFeature[MFLENGTH] = DistanceBetween(P1->Point, P2->Point);
217  NewFeature[ORIENTATION] = NormalizedAngleFrom(&P1->Point, &P2->Point, 1.0);
218  NewFeature[FIRSTBULGE] = 0.0f; // deprecated
219  NewFeature[SECONDBULGE] = 0.0f; // deprecated
220 
221  return NewFeature;
222 } /* ExtractMicroFeature */
FLOAT32 x
Definition: fpoint.h:31
#define XPOSITION
Definition: mfdefs.h:37
#define YPOSITION
Definition: mfdefs.h:38
#define AverageOf(A, B)
Definition: mfoutline.h:68
FLOAT32 NormalizedAngleFrom(FPOINT *Point1, FPOINT *Point2, FLOAT32 FullScale)
Definition: fpoint.cpp:39
#define SECONDBULGE
Definition: mfdefs.h:42
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
FLOAT32 DistanceBetween(FPOINT A, FPOINT B)
Definition: fpoint.cpp:31
FLOAT32 y
Definition: fpoint.h:31
FPOINT Point
Definition: mfoutline.h:40
#define MFLENGTH
Definition: mfdefs.h:39
#define ORIENTATION
Definition: mfdefs.h:40
MICROFEATURE NewMicroFeature()
Definition: mfdefs.cpp:29
#define FIRSTBULGE
Definition: mfdefs.h:41
#define PointAt(O)
Definition: mfoutline.h:75
FLOAT32 * MICROFEATURE
Definition: mfdefs.h:34

Variable Documentation

double classify_max_slope = 2.414213562

"Slope above which lines are called vertical"

Definition at line 39 of file mfx.cpp.

double classify_min_slope = 0.414213562

Include Files and Type Defines

Variables

"Slope below which lines are called horizontal"

Definition at line 37 of file mfx.cpp.