tesseract  5.0.0-alpha-619-ge9db
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 Files and Type Defines
19 ----------------------------------------------------------------------------*/
20 
21 #include "mfx.h"
22 #include "mfdefs.h"
23 #include "mfoutline.h"
24 #include "clusttool.h" //NEEDED
25 #include "intfx.h"
26 #include "normalis.h"
27 #include "params.h"
28 
29 /*----------------------------------------------------------------------------
30  Variables
31 ----------------------------------------------------------------------------*/
32 
33 /* old numbers corresponded to 10.0 degrees and 80.0 degrees */
35  "Slope below which lines are called horizontal");
37  "Slope above which lines are called vertical");
38 
39 /*----------------------------------------------------------------------------
40  Private Function Prototypes
41 -----------------------------------------------------------------------------*/
42 
44  MICROFEATURES MicroFeatures);
45 
47 
48 /*----------------------------------------------------------------------------
49  Public Code
50 ----------------------------------------------------------------------------*/
51 
61 MICROFEATURES BlobMicroFeatures(TBLOB* Blob, const DENORM& cn_denorm) {
62  MICROFEATURES MicroFeatures = NIL_LIST;
63  LIST Outlines;
64  LIST RemainingOutlines;
65  MFOUTLINE Outline;
66 
67  if (Blob != nullptr) {
68  Outlines = ConvertBlob(Blob);
69 
70  RemainingOutlines = Outlines;
71  iterate(RemainingOutlines) {
72  Outline = static_cast<MFOUTLINE>first_node (RemainingOutlines);
73  CharNormalizeOutline(Outline, cn_denorm);
74  }
75 
76  RemainingOutlines = Outlines;
77  iterate(RemainingOutlines) {
78  Outline = static_cast<MFOUTLINE>first_node(RemainingOutlines);
80  MarkDirectionChanges(Outline);
81  MicroFeatures = ConvertToMicroFeatures(Outline, MicroFeatures);
82  }
83  FreeOutlines(Outlines);
84  }
85  return MicroFeatures;
86 } /* BlobMicroFeatures */
87 
88 /*---------------------------------------------------------------------------
89  Private Code
90 ---------------------------------------------------------------------------*/
91 
100  MICROFEATURES MicroFeatures) {
101  MFOUTLINE Current;
102  MFOUTLINE Last;
103  MFOUTLINE First;
105 
106  if (DegenerateOutline (Outline))
107  return (MicroFeatures);
108 
109  First = NextExtremity (Outline);
110  Last = First;
111  do {
112  Current = NextExtremity (Last);
113  if (!PointAt(Current)->Hidden) {
114  NewFeature = ExtractMicroFeature (Last, Current);
115  if (NewFeature != nullptr)
116  MicroFeatures = push (MicroFeatures, NewFeature);
117  }
118  Last = Current;
119  }
120  while (Last != First);
121 
122  return (MicroFeatures);
123 } /* ConvertToMicroFeatures */
124 
140  MFEDGEPT *P1, *P2;
141 
142  P1 = PointAt(Start);
143  P2 = PointAt(End);
144 
146  NewFeature[XPOSITION] = AverageOf(P1->Point.x, P2->Point.x);
147  NewFeature[YPOSITION] = AverageOf(P1->Point.y, P2->Point.y);
150  NewFeature[FIRSTBULGE] = 0.0f; // deprecated
151  NewFeature[SECONDBULGE] = 0.0f; // deprecated
152 
153  return NewFeature;
154 } /* ExtractMicroFeature */
mfx.h
mfdefs.h
normalis.h
MFEDGEPT::Point
FPOINT Point
Definition: mfoutline.h:52
intfx.h
first_node
#define first_node(l)
Definition: oldlist.h:84
FPOINT::y
float y
Definition: fpoint.h:44
list_rec
Definition: oldlist.h:73
mfoutline.h
params.h
NormalizedAngleFrom
float NormalizedAngleFrom(FPOINT *Point1, FPOINT *Point2, float FullScale)
Definition: fpoint.cpp:43
MarkDirectionChanges
void MarkDirectionChanges(MFOUTLINE Outline)
Definition: mfoutline.cpp:182
CharNormalizeOutline
void CharNormalizeOutline(MFOUTLINE Outline, const DENORM &cn_denorm)
Definition: mfoutline.cpp:326
FIRSTBULGE
#define FIRSTBULGE
Definition: mfdefs.h:39
FPOINT::x
float x
Definition: fpoint.h:44
NIL_LIST
#define NIL_LIST
Definition: oldlist.h:68
XPOSITION
#define XPOSITION
Definition: mfdefs.h:35
classify_max_slope
double classify_max_slope
Definition: mfx.cpp:36
FindDirectionChanges
void FindDirectionChanges(MFOUTLINE Outline, float MinSlope, float MaxSlope)
Definition: mfoutline.cpp:114
ConvertToMicroFeatures
MICROFEATURES ConvertToMicroFeatures(MFOUTLINE Outline, MICROFEATURES MicroFeatures)
Definition: mfx.cpp:98
DistanceBetween
float DistanceBetween(FPOINT A, FPOINT B)
Definition: fpoint.cpp:28
ConvertBlob
LIST ConvertBlob(TBLOB *blob)
Definition: mfoutline.cpp:36
classify_min_slope
double classify_min_slope
Definition: mfx.cpp:34
ORIENTATION
#define ORIENTATION
Definition: mfdefs.h:38
push
LIST push(LIST list, void *element)
Definition: oldlist.cpp:172
double_VAR
#define double_VAR(name, val, comment)
Definition: params.h:309
NewFeature
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
Definition: ocrfeatures.cpp:77
FreeOutlines
void FreeOutlines(LIST Outlines)
Definition: mfoutline.cpp:166
YPOSITION
#define YPOSITION
Definition: mfdefs.h:36
TBLOB
Definition: blobs.h:282
MFEDGEPT
Definition: mfoutline.h:41
iterate
#define iterate(l)
Definition: oldlist.h:92
BlobMicroFeatures
MICROFEATURES BlobMicroFeatures(TBLOB *Blob, const DENORM &cn_denorm)
Definition: mfx.cpp:60
ExtractMicroFeature
MICROFEATURE ExtractMicroFeature(MFOUTLINE Start, MFOUTLINE End)
Definition: mfx.cpp:137
NewMicroFeature
MICROFEATURE NewMicroFeature()
Definition: mfdefs.cpp:32
MFLENGTH
#define MFLENGTH
Definition: mfdefs.h:37
NextExtremity
MFOUTLINE NextExtremity(MFOUTLINE EdgePoint)
Definition: mfoutline.cpp:219
AverageOf
#define AverageOf(A, B)
Definition: mfoutline.h:67
clusttool.h
SECONDBULGE
#define SECONDBULGE
Definition: mfdefs.h:40
MICROFEATURE
float * MICROFEATURE
Definition: mfdefs.h:32
DENORM
Definition: normalis.h:49