tesseract  5.0.0-alpha-619-ge9db
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

Definition at line 82 of file outfeat.cpp.

85  {
86  FEATURE Feature;
87 
88  Feature = NewFeature(&OutlineFeatDesc);
89  Feature->Params[OutlineFeatDir] = NormalizedAngleFrom(Start, End, 1.0);
90  Feature->Params[OutlineFeatX] = AverageOf(Start->x, End->x);
91  Feature->Params[OutlineFeatY] = AverageOf(Start->y, End->y);
92  Feature->Params[OutlineFeatLength] = DistanceBetween(*Start, *End);
93  AddFeature(FeatureSet, Feature);
94 

◆ 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. Results are returned in FeatureSet.

Parameters
Outlineoutline to extract outline-features from
FeatureSetset of features to add outline-features to

Definition at line 106 of file outfeat.cpp.

107  {
108  MFOUTLINE Next;
109  MFOUTLINE First;
110  FPOINT FeatureStart;
111  FPOINT FeatureEnd;
112 
113  if (DegenerateOutline (Outline))
114  return;
115 
116  First = Outline;
117  Next = First;
118  do {
119  FeatureStart = PointAt(Next)->Point;
120  Next = NextPointAfter(Next);
121 
122  /* note that an edge is hidden if the ending point of the edge is
123  marked as hidden. This situation happens because the order of
124  the outlines is reversed when they are converted from the old
125  format. In the old format, a hidden edge is marked by the
126  starting point for that edge. */
127  if (!PointAt(Next)->Hidden) {
128  FeatureEnd = PointAt(Next)->Point;
129  AddOutlineFeatureToSet(&FeatureStart, &FeatureEnd, FeatureSet);
130  }
131  }
132  while (Next != First);

◆ 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). FeatureSet is changed.

Parameters
FeatureSetoutline-features to be normalized

Definition at line 144 of file outfeat.cpp.

145  {
146  int i;
147  FEATURE Feature;
148  float Length;
149  float TotalX = 0.0;
150  float TotalWeight = 0.0;
151  float Origin;
152 
153  if (FeatureSet->NumFeatures <= 0)
154  return;
155 
156  for (i = 0; i < FeatureSet->NumFeatures; i++) {
157  Feature = FeatureSet->Features[i];
158  Length = Feature->Params[OutlineFeatLength];
159  TotalX += Feature->Params[OutlineFeatX] * Length;
160  TotalWeight += Length;
161  }
162  Origin = TotalX / TotalWeight;
163 
164  for (i = 0; i < FeatureSet->NumFeatures; i++) {
165  Feature = FeatureSet->Features[i];
166  Feature->Params[OutlineFeatX] -= Origin;
167  }
AddFeature
bool AddFeature(FEATURE_SET FeatureSet, FEATURE Feature)
Definition: ocrfeatures.cpp:39
AddOutlineFeatureToSet
void AddOutlineFeatureToSet(FPOINT *Start, FPOINT *End, FEATURE_SET FeatureSet)
Definition: outfeat.cpp:82
FPOINT::y
float y
Definition: fpoint.h:44
list_rec
Definition: oldlist.h:73
OutlineFeatLength
Definition: outfeat.h:44
NormalizedAngleFrom
float NormalizedAngleFrom(FPOINT *Point1, FPOINT *Point2, float FullScale)
Definition: fpoint.cpp:43
FEATURE_STRUCT
Definition: ocrfeatures.h:58
FPOINT
Definition: fpoint.h:28
FPOINT::x
float x
Definition: fpoint.h:44
OutlineFeatDir
Definition: outfeat.h:45
OutlineFeatDesc
const FEATURE_DESC_STRUCT OutlineFeatDesc
DistanceBetween
float DistanceBetween(FPOINT A, FPOINT B)
Definition: fpoint.cpp:28
FEATURE_SET_STRUCT::Features
FEATURE Features[1]
Definition: ocrfeatures.h:67
OutlineFeatY
Definition: outfeat.h:43
FEATURE_STRUCT::Params
float Params[1]
Definition: ocrfeatures.h:60
NewFeature
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
Definition: ocrfeatures.cpp:77
OutlineFeatX
Definition: outfeat.h:42
FEATURE_SET_STRUCT::NumFeatures
uint16_t NumFeatures
Definition: ocrfeatures.h:65
AverageOf
#define AverageOf(A, B)
Definition: mfoutline.h:67