tesseract  4.0.0-1-g2a2b
mfx.cpp File Reference
#include "mfx.h"
#include "mfdefs.h"
#include "mfoutline.h"
#include "clusttool.h"
#include "intfx.h"
#include "normalis.h"
#include "params.h"
#include <cmath>

Go to the source code of this file.

Macros

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

Functions

float 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 * M_PI) : (A)) / (2 * M_PI))

Definition at line 44 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.

Definition at line 69 of file mfx.cpp.

69  {
70  MICROFEATURES MicroFeatures = NIL_LIST;
71  LIST Outlines;
72  LIST RemainingOutlines;
73  MFOUTLINE Outline;
74 
75  if (Blob != nullptr) {
76  Outlines = ConvertBlob(Blob);
77 
78  RemainingOutlines = Outlines;
79  iterate(RemainingOutlines) {
80  Outline = (MFOUTLINE) first_node (RemainingOutlines);
81  CharNormalizeOutline(Outline, cn_denorm);
82  }
83 
84  RemainingOutlines = Outlines;
85  iterate(RemainingOutlines) {
86  Outline = (MFOUTLINE) first_node(RemainingOutlines);
88  MarkDirectionChanges(Outline);
89  MicroFeatures = ConvertToMicroFeatures(Outline, MicroFeatures);
90  }
91  FreeOutlines(Outlines);
92  }
93  return MicroFeatures;
94 } /* BlobMicroFeatures */
void MarkDirectionChanges(MFOUTLINE Outline)
Definition: mfoutline.cpp:190
MICROFEATURES ConvertToMicroFeatures(MFOUTLINE Outline, MICROFEATURES MicroFeatures)
Definition: mfx.cpp:130
void FreeOutlines(LIST Outlines)
Definition: mfoutline.cpp:172
void FindDirectionChanges(MFOUTLINE Outline, float MinSlope, float MaxSlope)
Definition: mfoutline.cpp:118
double classify_min_slope
Definition: mfx.cpp:36
LIST ConvertBlob(TBLOB *blob)
Definition: mfoutline.cpp:39
double classify_max_slope
Definition: mfx.cpp:38
#define first_node(l)
Definition: oldlist.h:141
#define NIL_LIST
Definition: oldlist.h:127
void CharNormalizeOutline(MFOUTLINE Outline, const DENORM &cn_denorm)
Definition: mfoutline.cpp:339
#define iterate(l)
Definition: oldlist.h:161
LIST MFOUTLINE
Definition: mfoutline.h:34

◆ ComputeOrientation()

float 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.

Definition at line 114 of file mfx.cpp.

114  {
115  float Orientation = NormalizeAngle(AngleFrom(Start->Point, End->Point));
116 
117  /* ensure that round-off errors do not put circular param out of range */
118  if ((Orientation < 0) || (Orientation >= 1))
119  Orientation = 0;
120  return (Orientation);
121 } /* ComputeOrientation */
#define NormalizeAngle(A)
Definition: mfx.cpp:44
#define AngleFrom(A, B)
Definition: fpoint.h:42
FPOINT Point
Definition: mfoutline.h:41

◆ 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

Definition at line 130 of file mfx.cpp.

131  {
132  MFOUTLINE Current;
133  MFOUTLINE Last;
134  MFOUTLINE First;
136 
137  if (DegenerateOutline (Outline))
138  return (MicroFeatures);
139 
140  First = NextExtremity (Outline);
141  Last = First;
142  do {
143  Current = NextExtremity (Last);
144  if (!PointAt(Current)->Hidden) {
145  NewFeature = ExtractMicroFeature (Last, Current);
146  if (NewFeature != nullptr)
147  MicroFeatures = push (MicroFeatures, NewFeature);
148  }
149  Last = Current;
150  }
151  while (Last != First);
152 
153  return (MicroFeatures);
154 } /* ConvertToMicroFeatures */
MFOUTLINE NextExtremity(MFOUTLINE EdgePoint)
Definition: mfoutline.cpp:227
#define DegenerateOutline(O)
Definition: mfoutline.h:67
LIST push(LIST list, void *element)
Definition: oldlist.cpp:283
MICROFEATURE ExtractMicroFeature(MFOUTLINE Start, MFOUTLINE End)
Definition: mfx.cpp:169
#define PointAt(O)
Definition: mfoutline.h:68
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
Definition: ocrfeatures.cpp:81
float * MICROFEATURE
Definition: mfdefs.h:33

◆ 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, nullptr 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 nullptr if the feature was rejected.
Note
Globals: none

Definition at line 169 of file mfx.cpp.

169  {
171  MFEDGEPT *P1, *P2;
172 
173  P1 = PointAt(Start);
174  P2 = PointAt(End);
175 
177  NewFeature[XPOSITION] = AverageOf(P1->Point.x, P2->Point.x);
178  NewFeature[YPOSITION] = AverageOf(P1->Point.y, P2->Point.y);
181  NewFeature[FIRSTBULGE] = 0.0f; // deprecated
182  NewFeature[SECONDBULGE] = 0.0f; // deprecated
183 
184  return NewFeature;
185 } /* ExtractMicroFeature */
#define SECONDBULGE
Definition: mfdefs.h:41
#define MFLENGTH
Definition: mfdefs.h:38
float DistanceBetween(FPOINT A, FPOINT B)
Definition: fpoint.cpp:28
float NormalizedAngleFrom(FPOINT *Point1, FPOINT *Point2, float FullScale)
Definition: fpoint.cpp:44
#define PointAt(O)
Definition: mfoutline.h:68
#define FIRSTBULGE
Definition: mfdefs.h:40
float y
Definition: fpoint.h:31
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
Definition: ocrfeatures.cpp:81
float * MICROFEATURE
Definition: mfdefs.h:33
#define AverageOf(A, B)
Definition: mfoutline.h:61
FPOINT Point
Definition: mfoutline.h:41
#define ORIENTATION
Definition: mfdefs.h:39
MICROFEATURE NewMicroFeature()
Definition: mfdefs.cpp:34
float x
Definition: fpoint.h:31
#define YPOSITION
Definition: mfdefs.h:37
#define XPOSITION
Definition: mfdefs.h:36

Variable Documentation

◆ classify_max_slope

double classify_max_slope = 2.414213562

"Slope above which lines are called vertical"

Definition at line 38 of file mfx.cpp.

◆ classify_min_slope

double classify_min_slope = 0.414213562

"Slope below which lines are called horizontal"

Definition at line 36 of file mfx.cpp.