tesseract  5.0.0-alpha-619-ge9db
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. Results are placed in FeatureSet. 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

Definition at line 102 of file picofeat.cpp.

105  {
106  FEATURE Feature;
107  float Angle;
108  float Length;
109  int NumFeatures;
110  FPOINT Center;
111  FPOINT Delta;
112  int i;
113 
114  Angle = NormalizedAngleFrom (Start, End, 1.0);
115  Length = DistanceBetween (*Start, *End);
116  NumFeatures = static_cast<int>(floor (Length / classify_pico_feature_length + 0.5));
117  if (NumFeatures < 1)
118  NumFeatures = 1;
119 
120  /* compute vector for one pico feature */
121  Delta.x = XDelta (*Start, *End) / NumFeatures;
122  Delta.y = YDelta (*Start, *End) / NumFeatures;
123 
124  /* compute position of first pico feature */
125  Center.x = Start->x + Delta.x / 2.0;
126  Center.y = Start->y + Delta.y / 2.0;
127 
128  /* compute each pico feature in segment and add to feature set */
129  for (i = 0; i < NumFeatures; i++) {
130  Feature = NewFeature (&PicoFeatDesc);
131  Feature->Params[PicoFeatDir] = Angle;
132  Feature->Params[PicoFeatX] = Center.x;
133  Feature->Params[PicoFeatY] = Center.y;
134  AddFeature(FeatureSet, Feature);
135 
136  Center.x += Delta.x;
137  Center.y += Delta.y;
138  }

◆ 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. Results are returned in FeatureSet.

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

Definition at line 154 of file picofeat.cpp.

155  {
156  MFOUTLINE Next;
157  MFOUTLINE First;
158  MFOUTLINE Current;
159 
160  if (DegenerateOutline(Outline))
161  return;
162 
163  First = Outline;
164  Current = First;
165  Next = NextPointAfter(Current);
166  do {
167  /* note that an edge is hidden if the ending point of the edge is
168  marked as hidden. This situation happens because the order of
169  the outlines is reversed when they are converted from the old
170  format. In the old format, a hidden edge is marked by the
171  starting point for that edge. */
172  if (!(PointAt(Next)->Hidden))
173  ConvertSegmentToPicoFeat (&(PointAt(Current)->Point),
174  &(PointAt(Next)->Point), FeatureSet);
175 
176  Current = Next;
177  Next = NextPointAfter(Current);
178  }
179  while (Current != First);
180 

◆ 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). FeatureSet is changed.

Parameters
FeatureSetpico-features to be normalized

Definition at line 192 of file picofeat.cpp.

193  {
194  int i;
195  FEATURE Feature;
196  float Origin = 0.0;
197 
198  for (i = 0; i < FeatureSet->NumFeatures; i++) {
199  Feature = FeatureSet->Features[i];
200  Origin += Feature->Params[PicoFeatX];
201  }
202  Origin /= FeatureSet->NumFeatures;
203 
204  for (i = 0; i < FeatureSet->NumFeatures; i++) {
205  Feature = FeatureSet->Features[i];
206  Feature->Params[PicoFeatX] -= Origin;
207  }

Variable Documentation

◆ classify_pico_feature_length

double classify_pico_feature_length = 0.05

"Pico Feature Length"

Definition at line 36 of file picofeat.cpp.

AddFeature
bool AddFeature(FEATURE_SET FeatureSet, FEATURE Feature)
Definition: ocrfeatures.cpp:39
FPOINT::y
float y
Definition: fpoint.h:44
list_rec
Definition: oldlist.h:73
NormalizedAngleFrom
float NormalizedAngleFrom(FPOINT *Point1, FPOINT *Point2, float FullScale)
Definition: fpoint.cpp:43
FEATURE_STRUCT
Definition: ocrfeatures.h:58
FPOINT
Definition: fpoint.h:28
PicoFeatY
Definition: picofeat.h:43
FPOINT::x
float x
Definition: fpoint.h:44
PicoFeatX
Definition: picofeat.h:43
PicoFeatDir
Definition: picofeat.h:43
DistanceBetween
float DistanceBetween(FPOINT A, FPOINT B)
Definition: fpoint.cpp:28
FEATURE_SET_STRUCT::Features
FEATURE Features[1]
Definition: ocrfeatures.h:67
YDelta
#define YDelta(A, B)
Definition: fpoint.h:38
classify_pico_feature_length
double classify_pico_feature_length
Definition: picofeat.cpp:36
FEATURE_STRUCT::Params
float Params[1]
Definition: ocrfeatures.h:60
NewFeature
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
Definition: ocrfeatures.cpp:77
PicoFeatDesc
const TESS_API FEATURE_DESC_STRUCT PicoFeatDesc
XDelta
#define XDelta(A, B)
Definition: fpoint.h:37
ConvertSegmentToPicoFeat
void ConvertSegmentToPicoFeat(FPOINT *Start, FPOINT *End, FEATURE_SET FeatureSet)
Definition: picofeat.cpp:102
FEATURE_SET_STRUCT::NumFeatures
uint16_t NumFeatures
Definition: ocrfeatures.h:65