tesseract  4.0.0-1-g2a2b
picofeat.cpp File Reference
#include "picofeat.h"
#include "classify.h"
#include "featdefs.h"
#include "fpoint.h"
#include "mfoutline.h"
#include "ocrfeatures.h"
#include "params.h"
#include "trainingsample.h"
#include <cmath>
#include <cstdio>

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)

Definition at line 104 of file picofeat.cpp.

106  {
107  FEATURE Feature;
108  float Angle;
109  float Length;
110  int NumFeatures;
111  FPOINT Center;
112  FPOINT Delta;
113  int i;
114 
115  Angle = NormalizedAngleFrom (Start, End, 1.0);
116  Length = DistanceBetween (*Start, *End);
117  NumFeatures = (int) floor (Length / classify_pico_feature_length + 0.5);
118  if (NumFeatures < 1)
119  NumFeatures = 1;
120 
121  /* compute vector for one pico feature */
122  Delta.x = XDelta (*Start, *End) / NumFeatures;
123  Delta.y = YDelta (*Start, *End) / NumFeatures;
124 
125  /* compute position of first pico feature */
126  Center.x = Start->x + Delta.x / 2.0;
127  Center.y = Start->y + Delta.y / 2.0;
128 
129  /* compute each pico feature in segment and add to feature set */
130  for (i = 0; i < NumFeatures; i++) {
131  Feature = NewFeature (&PicoFeatDesc);
132  Feature->Params[PicoFeatDir] = Angle;
133  Feature->Params[PicoFeatX] = Center.x;
134  Feature->Params[PicoFeatY] = Center.y;
135  AddFeature(FeatureSet, Feature);
136 
137  Center.x += Delta.x;
138  Center.y += Delta.y;
139  }
140 } /* ConvertSegmentToPicoFeat */
float DistanceBetween(FPOINT A, FPOINT B)
Definition: fpoint.cpp:28
float NormalizedAngleFrom(FPOINT *Point1, FPOINT *Point2, float FullScale)
Definition: fpoint.cpp:44
Definition: fpoint.h:30
float Params[1]
Definition: ocrfeatures.h:62
double classify_pico_feature_length
Definition: picofeat.cpp:38
#define XDelta(A, B)
Definition: fpoint.h:39
float y
Definition: fpoint.h:31
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
Definition: ocrfeatures.cpp:81
TESS_API const FEATURE_DESC_STRUCT PicoFeatDesc
bool AddFeature(FEATURE_SET FeatureSet, FEATURE Feature)
Definition: ocrfeatures.cpp:41
float x
Definition: fpoint.h:31
#define YDelta(A, B)
Definition: fpoint.h:40

◆ 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)

Definition at line 156 of file picofeat.cpp.

156  {
157  MFOUTLINE Next;
158  MFOUTLINE First;
159  MFOUTLINE Current;
160 
161  if (DegenerateOutline(Outline))
162  return;
163 
164  First = Outline;
165  Current = First;
166  Next = NextPointAfter(Current);
167  do {
168  /* note that an edge is hidden if the ending point of the edge is
169  marked as hidden. This situation happens because the order of
170  the outlines is reversed when they are converted from the old
171  format. In the old format, a hidden edge is marked by the
172  starting point for that edge. */
173  if (!(PointAt(Next)->Hidden))
174  ConvertSegmentToPicoFeat (&(PointAt(Current)->Point),
175  &(PointAt(Next)->Point), FeatureSet);
176 
177  Current = Next;
178  Next = NextPointAfter(Current);
179  }
180  while (Current != First);
181 
182 } /* ConvertToPicoFeatures2 */
#define DegenerateOutline(O)
Definition: mfoutline.h:67
#define PointAt(O)
Definition: mfoutline.h:68
void ConvertSegmentToPicoFeat(FPOINT *Start, FPOINT *End, FEATURE_SET FeatureSet)
Definition: picofeat.cpp:104
#define NextPointAfter(E)
Definition: mfoutline.h:69

◆ 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

Definition at line 195 of file picofeat.cpp.

195  {
196  int i;
197  FEATURE Feature;
198  float Origin = 0.0;
199 
200  for (i = 0; i < FeatureSet->NumFeatures; i++) {
201  Feature = FeatureSet->Features[i];
202  Origin += Feature->Params[PicoFeatX];
203  }
204  Origin /= FeatureSet->NumFeatures;
205 
206  for (i = 0; i < FeatureSet->NumFeatures; i++) {
207  Feature = FeatureSet->Features[i];
208  Feature->Params[PicoFeatX] -= Origin;
209  }
210 } /* NormalizePicoX */
float Params[1]
Definition: ocrfeatures.h:62
FEATURE Features[1]
Definition: ocrfeatures.h:69
uint16_t NumFeatures
Definition: ocrfeatures.h:67

Variable Documentation

◆ classify_pico_feature_length

double classify_pico_feature_length = 0.05

"Pico Feature Length"

Definition at line 38 of file picofeat.cpp.