All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
mf.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  ** Filename: mf.c
3  ** Purpose: Micro-feature interface to flexible feature extractor.
4  ** Author: Dan Johnson
5  ** History: Thu May 24 09:08:38 1990, 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 "mf.h"
22 
23 #include "featdefs.h"
24 #include "mfdefs.h"
25 #include "mfx.h"
26 
27 #include <math.h>
28 
29 /*----------------------------------------------------------------------------
30  Global Data Definitions and Declarations
31 ----------------------------------------------------------------------------*/
32 /*----------------------------------------------------------------------------
33  Private Code
34 ----------------------------------------------------------------------------*/
47 FEATURE_SET ExtractMicros(TBLOB *Blob, const DENORM& bl_denorm,
48  const DENORM& cn_denorm,
49  const INT_FX_RESULT_STRUCT& fx_info) {
50  int NumFeatures;
51  MICROFEATURES Features, OldFeatures;
52  FEATURE_SET FeatureSet;
53  FEATURE Feature;
54  MICROFEATURE OldFeature;
55 
56  OldFeatures = BlobMicroFeatures(Blob, cn_denorm);
57  if (OldFeatures == NULL)
58  return NULL;
59  NumFeatures = count (OldFeatures);
60  FeatureSet = NewFeatureSet (NumFeatures);
61 
62  Features = OldFeatures;
63  iterate(Features) {
64  OldFeature = (MICROFEATURE) first_node (Features);
65  Feature = NewFeature (&MicroFeatureDesc);
66  Feature->Params[MFDirection] = OldFeature[ORIENTATION];
67  Feature->Params[MFXPosition] = OldFeature[XPOSITION];
68  Feature->Params[MFYPosition] = OldFeature[YPOSITION];
69  Feature->Params[MFLength] = OldFeature[MFLENGTH];
70 
71  // Bulge features are deprecated and should not be used. Set to 0.
72  Feature->Params[MFBulge1] = 0.0f;
73  Feature->Params[MFBulge2] = 0.0f;
74 
75 #ifndef _WIN32
76  // Assert that feature parameters are well defined.
77  int i;
78  for (i = 0; i < Feature->Type->NumParams; i++) {
79  ASSERT_HOST(!isnan(Feature->Params[i]));
80  }
81 #endif
82 
83  AddFeature(FeatureSet, Feature);
84  }
85  FreeMicroFeatures(OldFeatures);
86  return FeatureSet;
87 } /* ExtractMicros */
Definition: blobs.h:261
#define isnan(x)
Definition: mathfix.h:31
FEATURE_SET ExtractMicros(TBLOB *Blob, const DENORM &bl_denorm, const DENORM &cn_denorm, const INT_FX_RESULT_STRUCT &fx_info)
Definition: mf.cpp:47
#define XPOSITION
Definition: mfdefs.h:36
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
Definition: ocrfeatures.cpp:96
FEATURE_SET NewFeatureSet(int NumFeatures)
#define YPOSITION
Definition: mfdefs.h:37
Definition: mf.h:29
Definition: mf.h:29
FLOAT32 * MICROFEATURE
Definition: mfdefs.h:33
const FEATURE_DESC_STRUCT * Type
Definition: ocrfeatures.h:64
void FreeMicroFeatures(MICROFEATURES MicroFeatures)
Definition: mfdefs.cpp:48
#define ASSERT_HOST(x)
Definition: errcode.h:84
Definition: mf.h:29
Definition: mf.h:28
#define first_node(l)
Definition: oldlist.h:139
#define iterate(l)
Definition: oldlist.h:159
MICROFEATURES BlobMicroFeatures(TBLOB *Blob, const DENORM &cn_denorm)
Definition: mfx.cpp:72
FLOAT32 Params[1]
Definition: ocrfeatures.h:65
Definition: mf.h:28
int count(LIST var_list)
Definition: oldlist.cpp:108
BOOL8 AddFeature(FEATURE_SET FeatureSet, FEATURE Feature)
Definition: ocrfeatures.cpp:44
Definition: mf.h:29
#define ORIENTATION
Definition: mfdefs.h:39
#define NULL
Definition: host.h:144
const FEATURE_DESC_STRUCT MicroFeatureDesc
#define MFLENGTH
Definition: mfdefs.h:38