All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
outfeat.cpp File Reference
#include "outfeat.h"
#include "classify.h"
#include "efio.h"
#include "featdefs.h"
#include "mfoutline.h"
#include "ocrfeatures.h"
#include <stdio.h>

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

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
Exceptions: none
History: 11/13/90, DSJ, Created.

Definition at line 93 of file outfeat.cpp.

95  {
96  FEATURE Feature;
97 
98  Feature = NewFeature(&OutlineFeatDesc);
99  Feature->Params[OutlineFeatDir] = NormalizedAngleFrom(Start, End, 1.0);
100  Feature->Params[OutlineFeatX] = AverageOf(Start->x, End->x);
101  Feature->Params[OutlineFeatY] = AverageOf(Start->y, End->y);
102  Feature->Params[OutlineFeatLength] = DistanceBetween(*Start, *End);
103  AddFeature(FeatureSet, Feature);
104 
105 } /* AddOutlineFeatureToSet */
#define AverageOf(A, B)
Definition: mfoutline.h:60
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
Definition: ocrfeatures.cpp:96
FLOAT32 NormalizedAngleFrom(FPOINT *Point1, FPOINT *Point2, FLOAT32 FullScale)
Definition: fpoint.cpp:48
FLOAT32 DistanceBetween(FPOINT A, FPOINT B)
Definition: fpoint.cpp:30
FLOAT32 y
Definition: fpoint.h:31
FLOAT32 Params[1]
Definition: ocrfeatures.h:65
BOOL8 AddFeature(FEATURE_SET FeatureSet, FEATURE Feature)
Definition: ocrfeatures.cpp:44
const FEATURE_DESC_STRUCT OutlineFeatDesc
FLOAT32 x
Definition: fpoint.h:31
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
Exceptions: none
History:
  • 11/13/90, DSJ, Created.
  • 5/24/91, DSJ, Added hidden edge capability.

Definition at line 122 of file outfeat.cpp.

122  {
123  MFOUTLINE Next;
124  MFOUTLINE First;
125  FPOINT FeatureStart;
126  FPOINT FeatureEnd;
127 
128  if (DegenerateOutline (Outline))
129  return;
130 
131  First = Outline;
132  Next = First;
133  do {
134  FeatureStart = PointAt(Next)->Point;
135  Next = NextPointAfter(Next);
136 
137  /* note that an edge is hidden if the ending point of the edge is
138  marked as hidden. This situation happens because the order of
139  the outlines is reversed when they are converted from the old
140  format. In the old format, a hidden edge is marked by the
141  starting point for that edge. */
142  if (!PointAt(Next)->Hidden) {
143  FeatureEnd = PointAt(Next)->Point;
144  AddOutlineFeatureToSet(&FeatureStart, &FeatureEnd, FeatureSet);
145  }
146  }
147  while (Next != First);
148 } /* ConvertToOutlineFeatures */
Definition: fpoint.h:29
#define PointAt(O)
Definition: mfoutline.h:67
#define DegenerateOutline(O)
Definition: mfoutline.h:66
#define NextPointAfter(E)
Definition: mfoutline.h:68
void AddOutlineFeatureToSet(FPOINT *Start, FPOINT *End, FEATURE_SET FeatureSet)
Definition: outfeat.cpp:93
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
Exceptions: none
History: 11/13/90, DSJ, Created.

Definition at line 163 of file outfeat.cpp.

163  {
164  int i;
165  FEATURE Feature;
166  FLOAT32 Length;
167  FLOAT32 TotalX = 0.0;
168  FLOAT32 TotalWeight = 0.0;
169  FLOAT32 Origin;
170 
171  if (FeatureSet->NumFeatures <= 0)
172  return;
173 
174  for (i = 0; i < FeatureSet->NumFeatures; i++) {
175  Feature = FeatureSet->Features[i];
176  Length = Feature->Params[OutlineFeatLength];
177  TotalX += Feature->Params[OutlineFeatX] * Length;
178  TotalWeight += Length;
179  }
180  Origin = TotalX / TotalWeight;
181 
182  for (i = 0; i < FeatureSet->NumFeatures; i++) {
183  Feature = FeatureSet->Features[i];
184  Feature->Params[OutlineFeatX] -= Origin;
185  }
186 } /* NormalizeOutlineX */
float FLOAT32
Definition: host.h:111
FEATURE Features[1]
Definition: ocrfeatures.h:72
FLOAT32 Params[1]
Definition: ocrfeatures.h:65