All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  ** History: 7/21/89, DSJ, Created.
6  **
7  ** (c) Copyright Hewlett-Packard Company, 1988.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  ******************************************************************************/
18 /*----------------------------------------------------------------------------
19  Include Files and Type Defines
20 ----------------------------------------------------------------------------*/
21 #include "mfdefs.h"
22 #include "mfoutline.h"
23 #include "clusttool.h" //NEEDED
24 #include "const.h"
25 #include "intfx.h"
26 #include "normalis.h"
27 #include "params.h"
28 
29 #include <math.h>
30 
31 /*----------------------------------------------------------------------------
32  Variables
33 ----------------------------------------------------------------------------*/
34 
35 /* old numbers corresponded to 10.0 degrees and 80.0 degrees */
36 double_VAR(classify_min_slope, 0.414213562,
37  "Slope below which lines are called horizontal");
38 double_VAR(classify_max_slope, 2.414213562,
39  "Slope above which lines are called vertical");
40 
41 /*----------------------------------------------------------------------------
42  Macros
43 ----------------------------------------------------------------------------*/
44 /* miscellaneous macros */
45 #define NormalizeAngle(A) ( (((A)<0)?((A)+2*PI):(A)) / (2*PI) )
46 
47 /*----------------------------------------------------------------------------
48  Private Function Prototypes
49 -----------------------------------------------------------------------------*/
51 
53  MICROFEATURES MicroFeatures);
54 
56 
57 /*----------------------------------------------------------------------------
58  Public Code
59 ----------------------------------------------------------------------------*/
60 
72 MICROFEATURES BlobMicroFeatures(TBLOB* Blob, const DENORM& cn_denorm) {
73  MICROFEATURES MicroFeatures = NIL_LIST;
74  LIST Outlines;
75  LIST RemainingOutlines;
76  MFOUTLINE Outline;
77 
78  if (Blob != NULL) {
79  Outlines = ConvertBlob(Blob);
80 
81  RemainingOutlines = Outlines;
82  iterate(RemainingOutlines) {
83  Outline = (MFOUTLINE) first_node (RemainingOutlines);
84  CharNormalizeOutline(Outline, cn_denorm);
85  }
86 
87  RemainingOutlines = Outlines;
88  iterate(RemainingOutlines) {
89  Outline = (MFOUTLINE) first_node(RemainingOutlines);
91  MarkDirectionChanges(Outline);
92  MicroFeatures = ConvertToMicroFeatures(Outline, MicroFeatures);
93  }
94  FreeOutlines(Outlines);
95  }
96  return MicroFeatures;
97 } /* BlobMicroFeatures */
98 
99 
100 /*---------------------------------------------------------------------------
101  Private Code
102 ---------------------------------------------------------------------------*/
103 
122 
123  Orientation = NormalizeAngle (AngleFrom (Start->Point, End->Point));
124 
125  /* ensure that round-off errors do not put circular param out of range */
126  if ((Orientation < 0) || (Orientation >= 1))
127  Orientation = 0;
128  return (Orientation);
129 } /* ComputeOrientation */
130 
131 
142  MICROFEATURES MicroFeatures) {
143  MFOUTLINE Current;
144  MFOUTLINE Last;
145  MFOUTLINE First;
147 
148  if (DegenerateOutline (Outline))
149  return (MicroFeatures);
150 
151  First = NextExtremity (Outline);
152  Last = First;
153  do {
154  Current = NextExtremity (Last);
155  if (!PointAt(Current)->Hidden) {
156  NewFeature = ExtractMicroFeature (Last, Current);
157  if (NewFeature != NULL)
158  MicroFeatures = push (MicroFeatures, NewFeature);
159  }
160  Last = Current;
161  }
162  while (Last != First);
163 
164  return (MicroFeatures);
165 } /* ConvertToMicroFeatures */
166 
167 
187  MFEDGEPT *P1, *P2;
188 
189  P1 = PointAt(Start);
190  P2 = PointAt(End);
191 
192  NewFeature = NewMicroFeature ();
193  NewFeature[XPOSITION] = AverageOf(P1->Point.x, P2->Point.x);
194  NewFeature[YPOSITION] = AverageOf(P1->Point.y, P2->Point.y);
195  NewFeature[MFLENGTH] = DistanceBetween(P1->Point, P2->Point);
196  NewFeature[ORIENTATION] = NormalizedAngleFrom(&P1->Point, &P2->Point, 1.0);
197  NewFeature[FIRSTBULGE] = 0.0f; // deprecated
198  NewFeature[SECONDBULGE] = 0.0f; // deprecated
199 
200  return NewFeature;
201 } /* ExtractMicroFeature */
Definition: blobs.h:261
#define NormalizeAngle(A)
Definition: mfx.cpp:45
float FLOAT32
Definition: host.h:111
#define FIRSTBULGE
Definition: mfdefs.h:40
void CharNormalizeOutline(MFOUTLINE Outline, const DENORM &cn_denorm)
Definition: mfoutline.cpp:359
#define double_VAR(name, val, comment)
Definition: params.h:286
#define AverageOf(A, B)
Definition: mfoutline.h:60
#define NIL_LIST
Definition: oldlist.h:126
#define XPOSITION
Definition: mfdefs.h:36
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
Definition: ocrfeatures.cpp:96
#define YPOSITION
Definition: mfdefs.h:37
FLOAT32 NormalizedAngleFrom(FPOINT *Point1, FPOINT *Point2, FLOAT32 FullScale)
Definition: fpoint.cpp:48
double classify_min_slope
Definition: mfx.cpp:37
FLOAT32 * MICROFEATURE
Definition: mfdefs.h:33
MFOUTLINE NextExtremity(MFOUTLINE EdgePoint)
Definition: mfoutline.cpp:238
#define SECONDBULGE
Definition: mfdefs.h:41
void FindDirectionChanges(MFOUTLINE Outline, FLOAT32 MinSlope, FLOAT32 MaxSlope)
Definition: mfoutline.cpp:120
MICROFEATURE NewMicroFeature()
Definition: mfdefs.cpp:35
#define AngleFrom(A, B)
Definition: fpoint.h:42
LIST ConvertBlob(TBLOB *blob)
Definition: mfoutline.cpp:39
#define PointAt(O)
Definition: mfoutline.h:67
void FreeOutlines(LIST Outlines)
Definition: mfoutline.cpp:178
FLOAT32 DistanceBetween(FPOINT A, FPOINT B)
Definition: fpoint.cpp:30
FLOAT32 y
Definition: fpoint.h:31
#define first_node(l)
Definition: oldlist.h:139
#define iterate(l)
Definition: oldlist.h:159
#define DegenerateOutline(O)
Definition: mfoutline.h:66
MICROFEATURES BlobMicroFeatures(TBLOB *Blob, const DENORM &cn_denorm)
Definition: mfx.cpp:72
void MarkDirectionChanges(MFOUTLINE Outline)
Definition: mfoutline.cpp:198
FLOAT32 ComputeOrientation(MFEDGEPT *Start, MFEDGEPT *End)
Definition: mfx.cpp:120
#define ORIENTATION
Definition: mfdefs.h:39
#define NULL
Definition: host.h:144
MICROFEATURES ConvertToMicroFeatures(MFOUTLINE Outline, MICROFEATURES MicroFeatures)
Definition: mfx.cpp:141
FPOINT Point
Definition: mfoutline.h:40
double classify_max_slope
Definition: mfx.cpp:39
MICROFEATURE ExtractMicroFeature(MFOUTLINE Start, MFOUTLINE End)
Definition: mfx.cpp:185
LIST MFOUTLINE
Definition: mfoutline.h:33
FLOAT32 x
Definition: fpoint.h:31
LIST push(LIST list, void *element)
Definition: oldlist.cpp:323
#define MFLENGTH
Definition: mfdefs.h:38