tesseract  5.0.0
mfx.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  ** Filename: mfx.c
3  ** Purpose: Micro feature extraction routines
4  ** Author: Dan Johnson
5  **
6  ** (c) Copyright Hewlett-Packard Company, 1988.
7  ** Licensed under the Apache License, Version 2.0 (the "License");
8  ** you may not use this file except in compliance with the License.
9  ** You may obtain a copy of the License at
10  ** http://www.apache.org/licenses/LICENSE-2.0
11  ** Unless required by applicable law or agreed to in writing, software
12  ** distributed under the License is distributed on an "AS IS" BASIS,
13  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  ** See the License for the specific language governing permissions and
15  ** limitations under the License.
16  *****************************************************************************/
17 
18 #include "mfx.h"
19 
20 #include "clusttool.h" //NEEDED
21 #include "intfx.h"
22 #include "mfdefs.h"
23 #include "mfoutline.h"
24 #include "normalis.h"
25 #include "params.h"
26 
27 namespace tesseract {
28 
29 /* old numbers corresponded to 10.0 degrees and 80.0 degrees */
30 double_VAR(classify_min_slope, 0.414213562, "Slope below which lines are called horizontal");
31 double_VAR(classify_max_slope, 2.414213562, "Slope above which lines are called vertical");
32 
33 /*----------------------------------------------------------------------------
34  Private Function Prototypes
35 -----------------------------------------------------------------------------*/
36 
38 
40 
41 /*----------------------------------------------------------------------------
42  Public Code
43 ----------------------------------------------------------------------------*/
44 
54 MICROFEATURES BlobMicroFeatures(TBLOB *Blob, const DENORM &cn_denorm) {
55  MICROFEATURES MicroFeatures;
56  LIST Outlines;
57  LIST RemainingOutlines;
58 
59  if (Blob != nullptr) {
60  Outlines = ConvertBlob(Blob);
61 
62  RemainingOutlines = Outlines;
63  iterate(RemainingOutlines) {
64  auto Outline = static_cast<MFOUTLINE>(RemainingOutlines->first_node());
65  CharNormalizeOutline(Outline, cn_denorm);
66  }
67 
68  RemainingOutlines = Outlines;
69  iterate(RemainingOutlines) {
70  auto Outline = static_cast<MFOUTLINE>(RemainingOutlines->first_node());
72  MarkDirectionChanges(Outline);
73  MicroFeatures = ConvertToMicroFeatures(Outline, MicroFeatures);
74  }
75  FreeOutlines(Outlines);
76  }
77  return MicroFeatures;
78 } /* BlobMicroFeatures */
79 
80 /*---------------------------------------------------------------------------
81  Private Code
82 ---------------------------------------------------------------------------*/
83 
92  MFOUTLINE Current;
93  MFOUTLINE Last;
94  MFOUTLINE First;
95 
96  if (DegenerateOutline(Outline)) {
97  return (MicroFeatures);
98  }
99 
100  First = NextExtremity(Outline);
101  Last = First;
102  do {
103  Current = NextExtremity(Last);
104  if (!PointAt(Current)->Hidden) {
105  auto NewFeature = ExtractMicroFeature(Last, Current);
106  MicroFeatures.push_front(NewFeature);
107  }
108  Last = Current;
109  } while (Last != First);
110 
111  return MicroFeatures;
112 } /* ConvertToMicroFeatures */
113 
128  MFEDGEPT *P1, *P2;
129 
130  P1 = PointAt(Start);
131  P2 = PointAt(End);
132 
133  MicroFeature NewFeature;
134  NewFeature[(int)MicroFeatureParameter::MFXPosition] = AverageOf(P1->Point.x, P2->Point.x);
135  NewFeature[(int)MicroFeatureParameter::MFYPosition] = AverageOf(P1->Point.y, P2->Point.y);
136  NewFeature[(int)MicroFeatureParameter::MFLength] = DistanceBetween(P1->Point, P2->Point);
137  NewFeature[(int)MicroFeatureParameter::MFDirection] = NormalizedAngleFrom(&P1->Point, &P2->Point, 1.0);
138  NewFeature[(int)MicroFeatureParameter::MFBulge1] = 0.0f; // deprecated
139  NewFeature[(int)MicroFeatureParameter::MFBulge2] = 0.0f; // deprecated
140 
141  return NewFeature;
142 } /* ExtractMicroFeature */
143 
144 } // namespace tesseract
#define double_VAR(name, val, comment)
Definition: params.h:365
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:58
#define iterate(l)
Definition: oldlist.h:91
MicroFeature ExtractMicroFeature(MFOUTLINE Start, MFOUTLINE End)
Definition: mfx.cpp:127
MICROFEATURES BlobMicroFeatures(TBLOB *Blob, const DENORM &cn_denorm)
Definition: mfx.cpp:54
void FreeOutlines(LIST Outlines)
Definition: mfoutline.cpp:151
void MarkDirectionChanges(MFOUTLINE Outline)
Definition: mfoutline.cpp:166
double classify_max_slope
Definition: mfx.cpp:31
LIST ConvertBlob(TBLOB *blob)
Definition: mfoutline.cpp:34
void CharNormalizeOutline(MFOUTLINE Outline, const DENORM &cn_denorm)
Definition: mfoutline.cpp:298
std::array< float,(int) MicroFeatureParameter::MFCount > MicroFeature
Definition: mfdefs.h:36
MFOUTLINE NextExtremity(MFOUTLINE EdgePoint)
Definition: mfoutline.cpp:196
MICROFEATURES ConvertToMicroFeatures(MFOUTLINE Outline, MICROFEATURES MicroFeatures)
Definition: mfx.cpp:91
double classify_min_slope
Definition: mfx.cpp:30
std::forward_list< MicroFeature > MICROFEATURES
Definition: mfdefs.h:37
void FindDirectionChanges(MFOUTLINE Outline, float MinSlope, float MaxSlope)
Definition: mfoutline.cpp:104
float y
Definition: fpoint.h:30
float x
Definition: fpoint.h:30
list_rec * first_node()
Definition: oldlist.h:107