tesseract 4.1.1
Loading...
Searching...
No Matches
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

namespace  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 103 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 }
139} /* ConvertSegmentToPicoFeat */
TESS_API const FEATURE_DESC_STRUCT PicoFeatDesc
float DistanceBetween(FPOINT A, FPOINT B)
Definition: fpoint.cpp:29
float NormalizedAngleFrom(FPOINT *Point1, FPOINT *Point2, float FullScale)
Definition: fpoint.cpp:44
#define XDelta(A, B)
Definition: fpoint.h:38
#define YDelta(A, B)
Definition: fpoint.h:39
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
Definition: ocrfeatures.cpp:78
bool AddFeature(FEATURE_SET FeatureSet, FEATURE Feature)
Definition: ocrfeatures.cpp:40
double classify_pico_feature_length
Definition: picofeat.cpp:37
@ PicoFeatY
Definition: picofeat.h:44
@ PicoFeatDir
Definition: picofeat.h:44
@ PicoFeatX
Definition: picofeat.h:44
Definition: fpoint.h:29
float y
Definition: fpoint.h:30
float x
Definition: fpoint.h:30
float Params[1]
Definition: ocrfeatures.h:61

◆ 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 155 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
181} /* ConvertToPicoFeatures2 */
void ConvertSegmentToPicoFeat(FPOINT *Start, FPOINT *End, FEATURE_SET FeatureSet)
Definition: picofeat.cpp:103

◆ 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 193 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 }
208} /* NormalizePicoX */
FEATURE Features[1]
Definition: ocrfeatures.h:68
uint16_t NumFeatures
Definition: ocrfeatures.h:66

Variable Documentation

◆ classify_pico_feature_length

double classify_pico_feature_length = 0.05

"Pico Feature Length"

Definition at line 37 of file picofeat.cpp.