tesseract 4.1.1
Loading...
Searching...
No Matches
outfeat.cpp File Reference
#include "outfeat.h"
#include "classify.h"
#include "featdefs.h"
#include "mfoutline.h"
#include "ocrfeatures.h"
#include <cstdio>

Go to the source code of this file.

Namespaces

namespace  tesseract
 

Functions

void AddOutlineFeatureToSet (FPOINT *Start, FPOINT *End, FEATURE_SET FeatureSet)
 
void ConvertToOutlineFeatures (MFOUTLINE Outline, FEATURE_SET FeatureSet)
 
void NormalizeOutlineX (FEATURE_SET FeatureSet)
 

Function Documentation

◆ AddOutlineFeatureToSet()

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

This routine computes the midpoint between Start and End to obtain the x,y position of the outline-feature. It also computes the direction from Start to End as the direction of the outline-feature and the distance from Start to End as the length of the outline-feature. This feature is then inserted into the next feature slot in FeatureSet.

Parameters
Startstarting point of outline-feature
Endending point of outline-feature
FeatureSetset to add outline-feature to

Definition at line 83 of file outfeat.cpp.

85 {
86 FEATURE Feature;
87
88 Feature = NewFeature(&OutlineFeatDesc);
89 Feature->Params[OutlineFeatDir] = NormalizedAngleFrom(Start, End, 1.0);
90 Feature->Params[OutlineFeatX] = AverageOf(Start->x, End->x);
91 Feature->Params[OutlineFeatY] = AverageOf(Start->y, End->y);
92 Feature->Params[OutlineFeatLength] = DistanceBetween(*Start, *End);
93 AddFeature(FeatureSet, Feature);
94
95} /* AddOutlineFeatureToSet */
const FEATURE_DESC_STRUCT OutlineFeatDesc
float DistanceBetween(FPOINT A, FPOINT B)
Definition: fpoint.cpp:29
float NormalizedAngleFrom(FPOINT *Point1, FPOINT *Point2, float FullScale)
Definition: fpoint.cpp:44
#define AverageOf(A, B)
Definition: mfoutline.h:68
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
Definition: ocrfeatures.cpp:78
bool AddFeature(FEATURE_SET FeatureSet, FEATURE Feature)
Definition: ocrfeatures.cpp:40
@ OutlineFeatDir
Definition: outfeat.h:32
@ OutlineFeatX
Definition: outfeat.h:29
@ OutlineFeatY
Definition: outfeat.h:30
@ OutlineFeatLength
Definition: outfeat.h:31
float y
Definition: fpoint.h:30
float x
Definition: fpoint.h:30
float Params[1]
Definition: ocrfeatures.h:61

◆ ConvertToOutlineFeatures()

void ConvertToOutlineFeatures ( MFOUTLINE  Outline,
FEATURE_SET  FeatureSet 
)

This routine steps converts each section in the specified outline to a feature described by its x,y position, length and angle. Results are returned in FeatureSet.

Parameters
Outlineoutline to extract outline-features from
FeatureSetset of features to add outline-features to

Definition at line 107 of file outfeat.cpp.

107 {
108 MFOUTLINE Next;
109 MFOUTLINE First;
110 FPOINT FeatureStart;
111 FPOINT FeatureEnd;
112
113 if (DegenerateOutline (Outline))
114 return;
115
116 First = Outline;
117 Next = First;
118 do {
119 FeatureStart = PointAt(Next)->Point;
120 Next = NextPointAfter(Next);
121
122 /* note that an edge is hidden if the ending point of the edge is
123 marked as hidden. This situation happens because the order of
124 the outlines is reversed when they are converted from the old
125 format. In the old format, a hidden edge is marked by the
126 starting point for that edge. */
127 if (!PointAt(Next)->Hidden) {
128 FeatureEnd = PointAt(Next)->Point;
129 AddOutlineFeatureToSet(&FeatureStart, &FeatureEnd, FeatureSet);
130 }
131 }
132 while (Next != First);
133} /* ConvertToOutlineFeatures */
void AddOutlineFeatureToSet(FPOINT *Start, FPOINT *End, FEATURE_SET FeatureSet)
Definition: outfeat.cpp:83
Definition: fpoint.h:29

◆ NormalizeOutlineX()

void NormalizeOutlineX ( FEATURE_SET  FeatureSet)

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

Parameters
FeatureSetoutline-features to be normalized

Definition at line 145 of file outfeat.cpp.

145 {
146 int i;
147 FEATURE Feature;
148 float Length;
149 float TotalX = 0.0;
150 float TotalWeight = 0.0;
151 float Origin;
152
153 if (FeatureSet->NumFeatures <= 0)
154 return;
155
156 for (i = 0; i < FeatureSet->NumFeatures; i++) {
157 Feature = FeatureSet->Features[i];
158 Length = Feature->Params[OutlineFeatLength];
159 TotalX += Feature->Params[OutlineFeatX] * Length;
160 TotalWeight += Length;
161 }
162 Origin = TotalX / TotalWeight;
163
164 for (i = 0; i < FeatureSet->NumFeatures; i++) {
165 Feature = FeatureSet->Features[i];
166 Feature->Params[OutlineFeatX] -= Origin;
167 }
168} /* NormalizeOutlineX */
FEATURE Features[1]
Definition: ocrfeatures.h:68
uint16_t NumFeatures
Definition: ocrfeatures.h:66