tesseract  4.0.0-1-g2a2b
outfeat.cpp File Reference
#include "outfeat.h"
#include "classify.h"
#include "featdefs.h"
#include "mfoutline.h"
#include "ocrfeatures.h"
#include <cstdio>

Go to the source code of this file.

Namespaces

 tesseract
 

Functions

void AddOutlineFeatureToSet (FPOINT *Start, FPOINT *End, FEATURE_SET FeatureSet)
 
void ConvertToOutlineFeatures (MFOUTLINE Outline, FEATURE_SET FeatureSet)
 
void NormalizeOutlineX (FEATURE_SET FeatureSet)
 

Function Documentation

◆ AddOutlineFeatureToSet()

void AddOutlineFeatureToSet ( FPOINT Start,
FPOINT End,
FEATURE_SET  FeatureSet 
)

This routine computes the midpoint between Start and End to obtain the x,y position of the outline-feature. It also computes the direction from Start to End as the direction of the outline-feature and the distance from Start to End as the length of the outline-feature. This feature is then inserted into the next feature slot in FeatureSet.

Parameters
Startstarting point of outline-feature
Endending point of outline-feature
FeatureSetset to add outline-feature to
Returns
none (results are placed in FeatureSet)
Note
Globals: none

Definition at line 86 of file outfeat.cpp.

88  {
89  FEATURE Feature;
90 
91  Feature = NewFeature(&OutlineFeatDesc);
92  Feature->Params[OutlineFeatDir] = NormalizedAngleFrom(Start, End, 1.0);
93  Feature->Params[OutlineFeatX] = AverageOf(Start->x, End->x);
94  Feature->Params[OutlineFeatY] = AverageOf(Start->y, End->y);
95  Feature->Params[OutlineFeatLength] = DistanceBetween(*Start, *End);
96  AddFeature(FeatureSet, Feature);
97 
98 } /* AddOutlineFeatureToSet */
float DistanceBetween(FPOINT A, FPOINT B)
Definition: fpoint.cpp:28
float NormalizedAngleFrom(FPOINT *Point1, FPOINT *Point2, float FullScale)
Definition: fpoint.cpp:44
float Params[1]
Definition: ocrfeatures.h:62
const FEATURE_DESC_STRUCT OutlineFeatDesc
float y
Definition: fpoint.h:31
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
Definition: ocrfeatures.cpp:81
#define AverageOf(A, B)
Definition: mfoutline.h:61
bool AddFeature(FEATURE_SET FeatureSet, FEATURE Feature)
Definition: ocrfeatures.cpp:41
float x
Definition: fpoint.h:31

◆ ConvertToOutlineFeatures()

void ConvertToOutlineFeatures ( MFOUTLINE  Outline,
FEATURE_SET  FeatureSet 
)

This routine steps converts each section in the specified outline to a feature described by its x,y position, length and angle.

Parameters
Outlineoutline to extract outline-features from
FeatureSetset of features to add outline-features to
Returns
none (results are returned in FeatureSet)
Note
Globals: none

Definition at line 111 of file outfeat.cpp.

111  {
112  MFOUTLINE Next;
113  MFOUTLINE First;
114  FPOINT FeatureStart;
115  FPOINT FeatureEnd;
116 
117  if (DegenerateOutline (Outline))
118  return;
119 
120  First = Outline;
121  Next = First;
122  do {
123  FeatureStart = PointAt(Next)->Point;
124  Next = NextPointAfter(Next);
125 
126  /* note that an edge is hidden if the ending point of the edge is
127  marked as hidden. This situation happens because the order of
128  the outlines is reversed when they are converted from the old
129  format. In the old format, a hidden edge is marked by the
130  starting point for that edge. */
131  if (!PointAt(Next)->Hidden) {
132  FeatureEnd = PointAt(Next)->Point;
133  AddOutlineFeatureToSet(&FeatureStart, &FeatureEnd, FeatureSet);
134  }
135  }
136  while (Next != First);
137 } /* ConvertToOutlineFeatures */
#define DegenerateOutline(O)
Definition: mfoutline.h:67
Definition: fpoint.h:30
#define PointAt(O)
Definition: mfoutline.h:68
void AddOutlineFeatureToSet(FPOINT *Start, FPOINT *End, FEATURE_SET FeatureSet)
Definition: outfeat.cpp:86
#define NextPointAfter(E)
Definition: mfoutline.h:69

◆ NormalizeOutlineX()

void NormalizeOutlineX ( FEATURE_SET  FeatureSet)

This routine computes the weighted average x position over all of the outline-features in FeatureSet and then renormalizes the outline-features to force this average to be the x origin (i.e. x=0).

Parameters
FeatureSetoutline-features to be normalized
Returns
none (FeatureSet is changed)
Note
Globals: none

Definition at line 150 of file outfeat.cpp.

150  {
151  int i;
152  FEATURE Feature;
153  float Length;
154  float TotalX = 0.0;
155  float TotalWeight = 0.0;
156  float Origin;
157 
158  if (FeatureSet->NumFeatures <= 0)
159  return;
160 
161  for (i = 0; i < FeatureSet->NumFeatures; i++) {
162  Feature = FeatureSet->Features[i];
163  Length = Feature->Params[OutlineFeatLength];
164  TotalX += Feature->Params[OutlineFeatX] * Length;
165  TotalWeight += Length;
166  }
167  Origin = TotalX / TotalWeight;
168 
169  for (i = 0; i < FeatureSet->NumFeatures; i++) {
170  Feature = FeatureSet->Features[i];
171  Feature->Params[OutlineFeatX] -= Origin;
172  }
173 } /* NormalizeOutlineX */
float Params[1]
Definition: ocrfeatures.h:62
FEATURE Features[1]
Definition: ocrfeatures.h:69
uint16_t NumFeatures
Definition: ocrfeatures.h:67