tesseract  4.00.00dev
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

◆ NormalizeAngle

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

Definition at line 45 of file mfx.cpp.

Function Documentation

◆ BlobMicroFeatures()

MICROFEATURES BlobMicroFeatures ( TBLOB Blob,
const DENORM cn_denorm 
)

This routine extracts micro-features from the specified blob and returns a list of the micro-features. All micro-features are normalized according to the specified line statistics.

Parameters
Blobblob to extract micro-features from
cn_denormcontrol parameter to feature extractor
Returns
List of micro-features extracted from the blob.
Note
Exceptions: none
History: 7/21/89, DSJ, Created.

Definition at line 72 of file mfx.cpp.

72  {
73  MICROFEATURES MicroFeatures = NIL_LIST;
74  LIST Outlines;
75  LIST RemainingOutlines;
76  MFOUTLINE Outline;
77 
78  if (Blob != NULL) {
79  Outlines = ConvertBlob(Blob);
80 
81  RemainingOutlines = Outlines;
82  iterate(RemainingOutlines) {
83  Outline = (MFOUTLINE) first_node (RemainingOutlines);
84  CharNormalizeOutline(Outline, cn_denorm);
85  }
86 
87  RemainingOutlines = Outlines;
88  iterate(RemainingOutlines) {
89  Outline = (MFOUTLINE) first_node(RemainingOutlines);
91  MarkDirectionChanges(Outline);
92  MicroFeatures = ConvertToMicroFeatures(Outline, MicroFeatures);
93  }
94  FreeOutlines(Outlines);
95  }
96  return MicroFeatures;
97 } /* BlobMicroFeatures */
void FindDirectionChanges(MFOUTLINE Outline, FLOAT32 MinSlope, FLOAT32 MaxSlope)
Definition: mfoutline.cpp:121
double classify_min_slope
Definition: mfx.cpp:37
void MarkDirectionChanges(MFOUTLINE Outline)
Definition: mfoutline.cpp:199
void CharNormalizeOutline(MFOUTLINE Outline, const DENORM &cn_denorm)
Definition: mfoutline.cpp:359
LIST ConvertBlob(TBLOB *blob)
Definition: mfoutline.cpp:40
#define NIL_LIST
Definition: oldlist.h:126
LIST MFOUTLINE
Definition: mfoutline.h:33
double classify_max_slope
Definition: mfx.cpp:39
#define first_node(l)
Definition: oldlist.h:139
#define iterate(l)
Definition: oldlist.h:159
void FreeOutlines(LIST Outlines)
Definition: mfoutline.cpp:179
MICROFEATURES ConvertToMicroFeatures(MFOUTLINE Outline, MICROFEATURES MicroFeatures)
Definition: mfx.cpp:140

◆ ComputeOrientation()

FLOAT32 ComputeOrientation ( MFEDGEPT Start,
MFEDGEPT End 
)

This routine computes the orientation parameter of the specified micro-feature. The orientation is the angle of the vector from Start to End. It is normalized to a number between 0 and 1 where 0 corresponds to 0 degrees and 1 corresponds to 360 degrees. The actual range is [0,1), i.e. 1 is excluded from the range (since it is actual the same orientation as 0). This routine assumes that Start and End are not the same point.

Parameters
Startstarting edge point of micro-feature
Endending edge point of micro-feature
Note
Globals: none
Returns
Orientation parameter for the specified micro-feature.
Note
Exceptions: none
History: 7/27/89, DSJ, Created.

Definition at line 120 of file mfx.cpp.

120  {
122 
123  Orientation = NormalizeAngle (AngleFrom (Start->Point, End->Point));
124 
125  /* ensure that round-off errors do not put circular param out of range */
126  if ((Orientation < 0) || (Orientation >= 1))
127  Orientation = 0;
128  return (Orientation);
129 } /* ComputeOrientation */
#define NormalizeAngle(A)
Definition: mfx.cpp:45
#define AngleFrom(A, B)
Definition: fpoint.h:42
float FLOAT32
Definition: host.h:42
FPOINT Point
Definition: mfoutline.h:40

◆ ConvertToMicroFeatures()

MICROFEATURES ConvertToMicroFeatures ( MFOUTLINE  Outline,
MICROFEATURES  MicroFeatures 
)

Convert Outline to MicroFeatures

Parameters
Outlineoutline to extract micro-features from
MicroFeatureslist of micro-features to add to
Returns
List of micro-features with new features added to front.
Note
Globals: none
Exceptions: none
History: 7/26/89, DSJ, Created.

Definition at line 140 of file mfx.cpp.

141  {
142  MFOUTLINE Current;
143  MFOUTLINE Last;
144  MFOUTLINE First;
146 
147  if (DegenerateOutline (Outline))
148  return (MicroFeatures);
149 
150  First = NextExtremity (Outline);
151  Last = First;
152  do {
153  Current = NextExtremity (Last);
154  if (!PointAt(Current)->Hidden) {
155  NewFeature = ExtractMicroFeature (Last, Current);
156  if (NewFeature != NULL)
157  MicroFeatures = push (MicroFeatures, NewFeature);
158  }
159  Last = Current;
160  }
161  while (Last != First);
162 
163  return (MicroFeatures);
164 } /* ConvertToMicroFeatures */
MICROFEATURE ExtractMicroFeature(MFOUTLINE Start, MFOUTLINE End)
Definition: mfx.cpp:183
#define PointAt(O)
Definition: mfoutline.h:67
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
Definition: ocrfeatures.cpp:88
#define DegenerateOutline(O)
Definition: mfoutline.h:66
MFOUTLINE NextExtremity(MFOUTLINE EdgePoint)
Definition: mfoutline.cpp:239
FLOAT32 * MICROFEATURE
Definition: mfdefs.h:33
LIST push(LIST list, void *element)
Definition: oldlist.cpp:317

◆ ExtractMicroFeature()

MICROFEATURE ExtractMicroFeature ( MFOUTLINE  Start,
MFOUTLINE  End 
)

This routine computes the feature parameters which describe the micro-feature that starts and Start and ends at End. A new micro-feature is allocated, filled with the feature parameters, and returned. The routine assumes that Start and End are not the same point. If they are the same point, NULL is returned, a warning message is printed, and the current outline is dumped to stdout.

Parameters
Startstarting point of micro-feature
Endending point of micro-feature
Returns
New micro-feature or NULL if the feature was rejected.
Note
Globals: none
Exceptions: none
History:
  • 7/26/89, DSJ, Created.
  • 11/17/89, DSJ, Added handling for Start and End same point.

Definition at line 183 of file mfx.cpp.

183  {
185  MFEDGEPT *P1, *P2;
186 
187  P1 = PointAt(Start);
188  P2 = PointAt(End);
189 
190  NewFeature = NewMicroFeature ();
191  NewFeature[XPOSITION] = AverageOf(P1->Point.x, P2->Point.x);
192  NewFeature[YPOSITION] = AverageOf(P1->Point.y, P2->Point.y);
193  NewFeature[MFLENGTH] = DistanceBetween(P1->Point, P2->Point);
194  NewFeature[ORIENTATION] = NormalizedAngleFrom(&P1->Point, &P2->Point, 1.0);
195  NewFeature[FIRSTBULGE] = 0.0f; // deprecated
196  NewFeature[SECONDBULGE] = 0.0f; // deprecated
197 
198  return NewFeature;
199 } /* ExtractMicroFeature */
#define XPOSITION
Definition: mfdefs.h:36
#define SECONDBULGE
Definition: mfdefs.h:41
#define AverageOf(A, B)
Definition: mfoutline.h:60
MICROFEATURE NewMicroFeature()
Definition: mfdefs.cpp:35
#define PointAt(O)
Definition: mfoutline.h:67
FLOAT32 NormalizedAngleFrom(FPOINT *Point1, FPOINT *Point2, FLOAT32 FullScale)
Definition: fpoint.cpp:48
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
Definition: ocrfeatures.cpp:88
FLOAT32 y
Definition: fpoint.h:31
#define MFLENGTH
Definition: mfdefs.h:38
FPOINT Point
Definition: mfoutline.h:40
#define ORIENTATION
Definition: mfdefs.h:39
FLOAT32 x
Definition: fpoint.h:31
#define FIRSTBULGE
Definition: mfdefs.h:40
FLOAT32 * MICROFEATURE
Definition: mfdefs.h:33
#define YPOSITION
Definition: mfdefs.h:37
FLOAT32 DistanceBetween(FPOINT A, FPOINT B)
Definition: fpoint.cpp:30

Variable Documentation

◆ classify_max_slope

double classify_max_slope = 2.414213562

"Slope above which lines are called vertical"

Definition at line 39 of file mfx.cpp.

◆ classify_min_slope

double classify_min_slope = 0.414213562

"Slope below which lines are called horizontal"

Definition at line 37 of file mfx.cpp.