tesseract  4.00.00dev
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

◆ ConvertSegmentToPicoFeat()

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

This routine converts an entire segment of an outline into a set of pico features which are added to FeatureSet. The length of the segment is rounded to the nearest whole number of pico-features. The pico-features are spaced evenly over the entire segment. Globals:

  • classify_pico_feature_length length of a single pico-feature
    Parameters
    Startstarting point of pico-feature
    Endending point of pico-feature
    FeatureSetset to add pico-feature to
    Returns
    none (results are placed in FeatureSet)
    Note
    Exceptions: none
    History: Tue Apr 30 15:44:34 1991, DSJ, Created.

Definition at line 109 of file picofeat.cpp.

111  {
112  FEATURE Feature;
113  FLOAT32 Angle;
114  FLOAT32 Length;
115  int NumFeatures;
116  FPOINT Center;
117  FPOINT Delta;
118  int i;
119 
120  Angle = NormalizedAngleFrom (Start, End, 1.0);
121  Length = DistanceBetween (*Start, *End);
122  NumFeatures = (int) floor (Length / classify_pico_feature_length + 0.5);
123  if (NumFeatures < 1)
124  NumFeatures = 1;
125 
126  /* compute vector for one pico feature */
127  Delta.x = XDelta (*Start, *End) / NumFeatures;
128  Delta.y = YDelta (*Start, *End) / NumFeatures;
129 
130  /* compute position of first pico feature */
131  Center.x = Start->x + Delta.x / 2.0;
132  Center.y = Start->y + Delta.y / 2.0;
133 
134  /* compute each pico feature in segment and add to feature set */
135  for (i = 0; i < NumFeatures; i++) {
136  Feature = NewFeature (&PicoFeatDesc);
137  Feature->Params[PicoFeatDir] = Angle;
138  Feature->Params[PicoFeatX] = Center.x;
139  Feature->Params[PicoFeatY] = Center.y;
140  AddFeature(FeatureSet, Feature);
141 
142  Center.x += Delta.x;
143  Center.y += Delta.y;
144  }
145 } /* ConvertSegmentToPicoFeat */
Definition: fpoint.h:29
#define XDelta(A, B)
Definition: fpoint.h:39
#define YDelta(A, B)
Definition: fpoint.h:40
FLOAT32 NormalizedAngleFrom(FPOINT *Point1, FPOINT *Point2, FLOAT32 FullScale)
Definition: fpoint.cpp:48
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
Definition: ocrfeatures.cpp:88
FLOAT32 y
Definition: fpoint.h:31
float FLOAT32
Definition: host.h:42
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
FLOAT32 x
Definition: fpoint.h:31
double classify_pico_feature_length
Definition: picofeat.cpp:39
FLOAT32 Params[1]
Definition: ocrfeatures.h:65
FLOAT32 DistanceBetween(FPOINT A, FPOINT B)
Definition: fpoint.cpp:30
TESS_API const FEATURE_DESC_STRUCT PicoFeatDesc
BOOL8 AddFeature(FEATURE_SET FeatureSet, FEATURE Feature)
Definition: ocrfeatures.cpp:43

◆ ConvertToPicoFeatures2()

void ConvertToPicoFeatures2 ( MFOUTLINE  Outline,
FEATURE_SET  FeatureSet 
)

This routine steps through the specified outline and cuts it up into pieces of equal length. These pieces become the desired pico-features. Each segment in the outline is converted into an integral number of pico-features.

Globals:

  • classify_pico_feature_length length of features to be extracted
    Parameters
    Outlineoutline to extract micro-features from
    FeatureSetset of features to add pico-features to
    Returns
    none (results are returned in FeatureSet)
    Note
    Exceptions: none
    History: 4/30/91, DSJ, Adapted from ConvertToPicoFeatures().

Definition at line 163 of file picofeat.cpp.

163  {
164  MFOUTLINE Next;
165  MFOUTLINE First;
166  MFOUTLINE Current;
167 
168  if (DegenerateOutline(Outline))
169  return;
170 
171  First = Outline;
172  Current = First;
173  Next = NextPointAfter(Current);
174  do {
175  /* note that an edge is hidden if the ending point of the edge is
176  marked as hidden. This situation happens because the order of
177  the outlines is reversed when they are converted from the old
178  format. In the old format, a hidden edge is marked by the
179  starting point for that edge. */
180  if (!(PointAt(Next)->Hidden))
181  ConvertSegmentToPicoFeat (&(PointAt(Current)->Point),
182  &(PointAt(Next)->Point), FeatureSet);
183 
184  Current = Next;
185  Next = NextPointAfter(Current);
186  }
187  while (Current != First);
188 
189 } /* ConvertToPicoFeatures2 */
#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:109
#define NextPointAfter(E)
Definition: mfoutline.h:68

◆ NormalizePicoX()

void NormalizePicoX ( FEATURE_SET  FeatureSet)

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

Parameters
FeatureSetpico-features to be normalized
Returns
none (FeatureSet is changed)
Note
Globals: none
Exceptions: none
History: Tue Sep 4 16:50:08 1990, DSJ, Created.

Definition at line 204 of file picofeat.cpp.

204  {
205  int i;
206  FEATURE Feature;
207  FLOAT32 Origin = 0.0;
208 
209  for (i = 0; i < FeatureSet->NumFeatures; i++) {
210  Feature = FeatureSet->Features[i];
211  Origin += Feature->Params[PicoFeatX];
212  }
213  Origin /= FeatureSet->NumFeatures;
214 
215  for (i = 0; i < FeatureSet->NumFeatures; i++) {
216  Feature = FeatureSet->Features[i];
217  Feature->Params[PicoFeatX] -= Origin;
218  }
219 } /* NormalizePicoX */
FEATURE Features[1]
Definition: ocrfeatures.h:72
float FLOAT32
Definition: host.h:42
FLOAT32 Params[1]
Definition: ocrfeatures.h:65

Variable Documentation

◆ classify_pico_feature_length

double classify_pico_feature_length = 0.05

"Pico Feature Length"

Definition at line 39 of file picofeat.cpp.