tesseract  3.04.00
picofeat.cpp File Reference
#include "picofeat.h"
#include "classify.h"
#include "efio.h"
#include "featdefs.h"
#include "fpoint.h"
#include "mfoutline.h"
#include "ocrfeatures.h"
#include "params.h"
#include "trainingsample.h"
#include <math.h>
#include <stdio.h>

Go to the source code of this file.

Namespaces

 tesseract
 

Functions

void ConvertSegmentToPicoFeat (FPOINT *Start, FPOINT *End, FEATURE_SET FeatureSet)
 
void ConvertToPicoFeatures2 (MFOUTLINE Outline, FEATURE_SET FeatureSet)
 
void NormalizePicoX (FEATURE_SET FeatureSet)
 

Variables

double classify_pico_feature_length = 0.05
 

Function Documentation

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

Private Code

Definition at line 95 of file picofeat.cpp.

97  {
98 /*
99  ** Parameters:
100  ** Start starting point of pico-feature
101  ** End ending point of pico-feature
102  ** FeatureSet set to add pico-feature to
103  ** Globals:
104  ** classify_pico_feature_length length of a single pico-feature
105  ** Operation: This routine converts an entire segment of an outline
106  ** into a set of pico features which are added to
107  ** FeatureSet. The length of the segment is rounded to the
108  ** nearest whole number of pico-features. The pico-features
109  ** are spaced evenly over the entire segment.
110  ** Return: none (results are placed in FeatureSet)
111  ** Exceptions: none
112  ** History: Tue Apr 30 15:44:34 1991, DSJ, Created.
113  */
114  FEATURE Feature;
115  FLOAT32 Angle;
116  FLOAT32 Length;
117  int NumFeatures;
118  FPOINT Center;
119  FPOINT Delta;
120  int i;
121 
122  Angle = NormalizedAngleFrom (Start, End, 1.0);
123  Length = DistanceBetween (*Start, *End);
124  NumFeatures = (int) floor (Length / classify_pico_feature_length + 0.5);
125  if (NumFeatures < 1)
126  NumFeatures = 1;
127 
128  /* compute vector for one pico feature */
129  Delta.x = XDelta (*Start, *End) / NumFeatures;
130  Delta.y = YDelta (*Start, *End) / NumFeatures;
131 
132  /* compute position of first pico feature */
133  Center.x = Start->x + Delta.x / 2.0;
134  Center.y = Start->y + Delta.y / 2.0;
135 
136  /* compute each pico feature in segment and add to feature set */
137  for (i = 0; i < NumFeatures; i++) {
138  Feature = NewFeature (&PicoFeatDesc);
139  Feature->Params[PicoFeatDir] = Angle;
140  Feature->Params[PicoFeatX] = Center.x;
141  Feature->Params[PicoFeatY] = Center.y;
142  AddFeature(FeatureSet, Feature);
143 
144  Center.x += Delta.x;
145  Center.y += Delta.y;
146  }
147 } /* ConvertSegmentToPicoFeat */
Definition: fpoint.h:29
FLOAT32 y
Definition: fpoint.h:31
#define YDelta(A, B)
Definition: fpoint.h:40
#define XDelta(A, B)
Definition: fpoint.h:39
const FEATURE_DESC_STRUCT PicoFeatDesc
BOOL8 AddFeature(FEATURE_SET FeatureSet, FEATURE Feature)
Definition: ocrfeatures.cpp:35
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)
float FLOAT32
Definition: host.h:111
double classify_pico_feature_length
Definition: picofeat.cpp:39
void ConvertToPicoFeatures2 ( MFOUTLINE  Outline,
FEATURE_SET  FeatureSet 
)

Definition at line 151 of file picofeat.cpp.

151  {
152 /*
153  ** Parameters:
154  ** Outline outline to extract micro-features from
155  ** FeatureSet set of features to add pico-features to
156  ** Globals:
157  ** classify_pico_feature_length
158  ** length of features to be extracted
159  ** Operation:
160  ** This routine steps thru the specified outline and cuts it
161  ** up into pieces of equal length. These pieces become the
162  ** desired pico-features. Each segment in the outline
163  ** is converted into an integral number of pico-features.
164  ** Return: none (results are returned in FeatureSet)
165  ** Exceptions: none
166  ** History: 4/30/91, DSJ, Adapted from ConvertToPicoFeatures().
167  */
168  MFOUTLINE Next;
169  MFOUTLINE First;
170  MFOUTLINE Current;
171 
172  if (DegenerateOutline(Outline))
173  return;
174 
175  First = Outline;
176  Current = First;
177  Next = NextPointAfter(Current);
178  do {
179  /* note that an edge is hidden if the ending point of the edge is
180  marked as hidden. This situation happens because the order of
181  the outlines is reversed when they are converted from the old
182  format. In the old format, a hidden edge is marked by the
183  starting point for that edge. */
184  if (!(PointAt(Next)->Hidden))
185  ConvertSegmentToPicoFeat (&(PointAt(Current)->Point),
186  &(PointAt(Next)->Point), FeatureSet);
187 
188  Current = Next;
189  Next = NextPointAfter(Current);
190  }
191  while (Current != First);
192 
193 } /* ConvertToPicoFeatures2 */
#define NextPointAfter(E)
Definition: mfoutline.h:68
#define PointAt(O)
Definition: mfoutline.h:67
#define DegenerateOutline(O)
Definition: mfoutline.h:66
void ConvertSegmentToPicoFeat(FPOINT *Start, FPOINT *End, FEATURE_SET FeatureSet)
Definition: picofeat.cpp:95
void NormalizePicoX ( FEATURE_SET  FeatureSet)

Definition at line 197 of file picofeat.cpp.

197  {
198 /*
199  ** Parameters:
200  ** FeatureSet pico-features to be normalized
201  ** Globals: none
202  ** Operation: This routine computes the average x position over all
203  ** of the pico-features in FeatureSet and then renormalizes
204  ** the pico-features to force this average to be the x origin
205  ** (i.e. x=0).
206  ** Return: none (FeatureSet is changed)
207  ** Exceptions: none
208  ** History: Tue Sep 4 16:50:08 1990, DSJ, Created.
209  */
210  int i;
211  FEATURE Feature;
212  FLOAT32 Origin = 0.0;
213 
214  for (i = 0; i < FeatureSet->NumFeatures; i++) {
215  Feature = FeatureSet->Features[i];
216  Origin += Feature->Params[PicoFeatX];
217  }
218  Origin /= FeatureSet->NumFeatures;
219 
220  for (i = 0; i < FeatureSet->NumFeatures; i++) {
221  Feature = FeatureSet->Features[i];
222  Feature->Params[PicoFeatX] -= Origin;
223  }
224 } /* NormalizePicoX */
FEATURE Features[1]
Definition: ocrfeatures.h:72
FLOAT32 Params[1]
Definition: ocrfeatures.h:65
float FLOAT32
Definition: host.h:111

Variable Documentation

double classify_pico_feature_length = 0.05

Include Files and Type Defines

"Pico Feature Length"

Definition at line 39 of file picofeat.cpp.