tesseract  3.04.00
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)
 
MICROFEATURES BlobMicroFeatures (TBLOB *Blob, const DENORM &cn_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

MICROFEATURES BlobMicroFeatures ( TBLOB Blob,
const DENORM cn_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  LIST Outlines;
78  LIST RemainingOutlines;
79  MFOUTLINE Outline;
80 
81  if (Blob != NULL) {
82  Outlines = ConvertBlob(Blob);
83 
84  RemainingOutlines = Outlines;
85  iterate(RemainingOutlines) {
86  Outline = (MFOUTLINE) first_node (RemainingOutlines);
87  CharNormalizeOutline(Outline, cn_denorm);
88  }
89 
90  RemainingOutlines = Outlines;
91  iterate(RemainingOutlines) {
92  Outline = (MFOUTLINE) first_node(RemainingOutlines);
94  MarkDirectionChanges(Outline);
95  MicroFeatures = ConvertToMicroFeatures(Outline, MicroFeatures);
96  }
97  FreeOutlines(Outlines);
98  }
99  return MicroFeatures;
100 } /* BlobMicroFeatures */
void FindDirectionChanges(MFOUTLINE Outline, FLOAT32 MinSlope, FLOAT32 MaxSlope)
Definition: mfoutline.cpp:105
double classify_max_slope
Definition: mfx.cpp:39
LIST MFOUTLINE
Definition: mfoutline.h:33
void MarkDirectionChanges(MFOUTLINE Outline)
Definition: mfoutline.cpp:191
#define NULL
Definition: host.h:144
LIST ConvertBlob(TBLOB *blob)
Definition: mfoutline.cpp:39
double classify_min_slope
Definition: mfx.cpp:37
#define iterate(l)
Definition: oldlist.h:159
#define NIL_LIST
Definition: oldlist.h:126
void CharNormalizeOutline(MFOUTLINE Outline, const DENORM &cn_denorm)
Definition: mfoutline.cpp:364
MICROFEATURES ConvertToMicroFeatures(MFOUTLINE Outline, MICROFEATURES MicroFeatures)
Definition: mfx.cpp:139
void FreeOutlines(LIST Outlines)
Definition: mfoutline.cpp:175
#define first_node(l)
Definition: oldlist.h:139
FLOAT32 ComputeOrientation ( MFEDGEPT Start,
MFEDGEPT End 
)

Definition at line 108 of file mfx.cpp.

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

Definition at line 139 of file mfx.cpp.

140  {
141 /*
142  ** Parameters:
143  ** Outline outline to extract micro-features from
144  ** MicroFeatures list of micro-features to add to
145  ** Globals: none
146  ** Operation:
147  ** This routine
148  ** Return: List of micro-features with new features added to front.
149  ** Exceptions: none
150  ** History: 7/26/89, DSJ, Created.
151  */
152  MFOUTLINE Current;
153  MFOUTLINE Last;
154  MFOUTLINE First;
156 
157  if (DegenerateOutline (Outline))
158  return (MicroFeatures);
159 
160  First = NextExtremity (Outline);
161  Last = First;
162  do {
163  Current = NextExtremity (Last);
164  if (!PointAt(Current)->Hidden) {
165  NewFeature = ExtractMicroFeature (Last, Current);
166  if (NewFeature != NULL)
167  MicroFeatures = push (MicroFeatures, NewFeature);
168  }
169  Last = Current;
170  }
171  while (Last != First);
172 
173  return (MicroFeatures);
174 } /* ConvertToMicroFeatures */
LIST push(LIST list, void *element)
Definition: oldlist.cpp:323
#define NULL
Definition: host.h:144
FLOAT32 * MICROFEATURE
Definition: mfdefs.h:33
#define PointAt(O)
Definition: mfoutline.h:67
#define DegenerateOutline(O)
Definition: mfoutline.h:66
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
MFOUTLINE NextExtremity(MFOUTLINE EdgePoint)
Definition: mfoutline.cpp:235
MICROFEATURE ExtractMicroFeature(MFOUTLINE Start, MFOUTLINE End)
Definition: mfx.cpp:178
MICROFEATURE ExtractMicroFeature ( MFOUTLINE  Start,
MFOUTLINE  End 
)

Definition at line 178 of file mfx.cpp.

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

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.