tesseract  3.04.00
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 
)

Private Code

Definition at line 78 of file outfeat.cpp.

80  {
81 /*
82  ** Parameters:
83  ** Start starting point of outline-feature
84  ** End ending point of outline-feature
85  ** FeatureSet set to add outline-feature to
86  ** Globals: none
87  ** Operation: This routine computes the midpoint between Start and
88  ** End to obtain the x,y position of the outline-feature. It
89  ** also computes the direction from Start to End as the
90  ** direction of the outline-feature and the distance from
91  ** Start to End as the length of the outline-feature.
92  ** This feature is then
93  ** inserted into the next feature slot in FeatureSet.
94  ** Return: none (results are placed in FeatureSet)
95  ** Exceptions: none
96  ** History: 11/13/90, DSJ, Created.
97  */
98  FEATURE Feature;
99 
100  Feature = NewFeature(&OutlineFeatDesc);
101  Feature->Params[OutlineFeatDir] = NormalizedAngleFrom(Start, End, 1.0);
102  Feature->Params[OutlineFeatX] = AverageOf(Start->x, End->x);
103  Feature->Params[OutlineFeatY] = AverageOf(Start->y, End->y);
104  Feature->Params[OutlineFeatLength] = DistanceBetween(*Start, *End);
105  AddFeature(FeatureSet, Feature);
106 
107 } /* AddOutlineFeatureToSet */
FLOAT32 y
Definition: fpoint.h:31
BOOL8 AddFeature(FEATURE_SET FeatureSet, FEATURE Feature)
Definition: ocrfeatures.cpp:35
const FEATURE_DESC_STRUCT OutlineFeatDesc
FLOAT32 DistanceBetween(FPOINT A, FPOINT B)
Definition: fpoint.cpp:31
FLOAT32 x
Definition: fpoint.h:31
FLOAT32 NormalizedAngleFrom(FPOINT *Point1, FPOINT *Point2, FLOAT32 FullScale)
Definition: fpoint.cpp:39
FLOAT32 Params[1]
Definition: ocrfeatures.h:65
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
#define AverageOf(A, B)
Definition: mfoutline.h:60
void ConvertToOutlineFeatures ( MFOUTLINE  Outline,
FEATURE_SET  FeatureSet 
)

Definition at line 111 of file outfeat.cpp.

111  {
112 /*
113  ** Parameters:
114  ** Outline outline to extract outline-features from
115  ** FeatureSet set of features to add outline-features to
116  ** Globals: none
117  ** Operation:
118  ** This routine steps converts each section in the specified
119  ** outline to a feature described by its x,y position, length
120  ** and angle.
121  ** Return: none (results are returned in FeatureSet)
122  ** Exceptions: none
123  ** History: 11/13/90, DSJ, Created.
124  ** 5/24/91, DSJ, Added hidden edge capability.
125  */
126  MFOUTLINE Next;
127  MFOUTLINE First;
128  FPOINT FeatureStart;
129  FPOINT FeatureEnd;
130 
131  if (DegenerateOutline (Outline))
132  return;
133 
134  First = Outline;
135  Next = First;
136  do {
137  FeatureStart = PointAt(Next)->Point;
138  Next = NextPointAfter(Next);
139 
140  /* note that an edge is hidden if the ending point of the edge is
141  marked as hidden. This situation happens because the order of
142  the outlines is reversed when they are converted from the old
143  format. In the old format, a hidden edge is marked by the
144  starting point for that edge. */
145  if (!PointAt(Next)->Hidden) {
146  FeatureEnd = PointAt(Next)->Point;
147  AddOutlineFeatureToSet(&FeatureStart, &FeatureEnd, FeatureSet);
148  }
149  }
150  while (Next != First);
151 } /* ConvertToOutlineFeatures */
#define NextPointAfter(E)
Definition: mfoutline.h:68
Definition: fpoint.h:29
void AddOutlineFeatureToSet(FPOINT *Start, FPOINT *End, FEATURE_SET FeatureSet)
Definition: outfeat.cpp:78
#define PointAt(O)
Definition: mfoutline.h:67
#define DegenerateOutline(O)
Definition: mfoutline.h:66
void NormalizeOutlineX ( FEATURE_SET  FeatureSet)

Definition at line 155 of file outfeat.cpp.

155  {
156 /*
157  ** Parameters:
158  ** FeatureSet outline-features to be normalized
159  ** Globals: none
160  ** Operation: This routine computes the weighted average x position
161  ** over all of the outline-features in FeatureSet and then
162  ** renormalizes the outline-features to force this average
163  ** to be the x origin (i.e. x=0).
164  ** Return: none (FeatureSet is changed)
165  ** Exceptions: none
166  ** History: 11/13/90, DSJ, Created.
167  */
168  int i;
169  FEATURE Feature;
170  FLOAT32 Length;
171  FLOAT32 TotalX = 0.0;
172  FLOAT32 TotalWeight = 0.0;
173  FLOAT32 Origin;
174 
175  if (FeatureSet->NumFeatures <= 0)
176  return;
177 
178  for (i = 0; i < FeatureSet->NumFeatures; i++) {
179  Feature = FeatureSet->Features[i];
180  Length = Feature->Params[OutlineFeatLength];
181  TotalX += Feature->Params[OutlineFeatX] * Length;
182  TotalWeight += Length;
183  }
184  Origin = TotalX / TotalWeight;
185 
186  for (i = 0; i < FeatureSet->NumFeatures; i++) {
187  Feature = FeatureSet->Features[i];
188  Feature->Params[OutlineFeatX] -= Origin;
189  }
190 } /* NormalizeOutlineX */
FEATURE Features[1]
Definition: ocrfeatures.h:72
FLOAT32 Params[1]
Definition: ocrfeatures.h:65
float FLOAT32
Definition: host.h:111