• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "mfdefs.h"
22 #include "mf.h"
23 #include "fxdefs.h"
24 #include "mfx.h"
25 #include <math.h>
26 
27 /**----------------------------------------------------------------------------
28         Global Data Definitions and Declarations
29 ----------------------------------------------------------------------------**/
30 /**----------------------------------------------------------------------------
31               Private Code
32 ----------------------------------------------------------------------------**/
33 /*---------------------------------------------------------------------------*/
ExtractMicros(TBLOB * Blob,LINE_STATS * LineStats)34 FEATURE_SET ExtractMicros(TBLOB *Blob, LINE_STATS *LineStats) {
35 /*
36  **	Parameters:
37  **		Blob		blob to extract micro-features from
38  **		LineStats	statistics on text row blob is in
39  **	Globals: none
40  **	Operation: Call the old micro-feature extractor and then copy
41  **		the features into the new format.  Then deallocate the
42  **		old micro-features.
43  **	Return: Micro-features for Blob.
44  **	Exceptions: none
45  **	History: Wed May 23 18:06:38 1990, DSJ, Created.
46  */
47   int NumFeatures;
48   MICROFEATURES Features, OldFeatures;
49   FEATURE_SET FeatureSet;
50   FEATURE Feature;
51   MICROFEATURE OldFeature;
52 
53   OldFeatures = (MICROFEATURES) BlobMicroFeatures (Blob, LineStats);
54   if (OldFeatures == NULL)
55     return NULL;
56   NumFeatures = count (OldFeatures);
57   FeatureSet = NewFeatureSet (NumFeatures);
58 
59   Features = OldFeatures;
60   iterate(Features) {
61     OldFeature = (MICROFEATURE) first_node (Features);
62     Feature = NewFeature (&MicroFeatureDesc);
63     Feature->Params[MFDirection] = OldFeature[ORIENTATION];
64     Feature->Params[MFXPosition] = OldFeature[XPOSITION];
65     Feature->Params[MFYPosition] = OldFeature[YPOSITION];
66     Feature->Params[MFLength] = OldFeature[MFLENGTH];
67 
68     // Bulge features should not be used
69     // anymore and are therefore set to 0.
70 //     ParamOf (Feature, MFBulge1) = FirstBulgeOf (OldFeature);
71 //     ParamOf (Feature, MFBulge2) = SecondBulgeOf (OldFeature);
72     Feature->Params[MFBulge1] = 0.0f;
73     Feature->Params[MFBulge2] = 0.0f;
74 #ifndef __MSW32__
75     // Assert that feature parameters are well defined.
76     int i;
77     for (i = 0; i < Feature->Type->NumParams; i++) {
78       assert(!isnan(Feature->Params[i]));
79     }
80 #endif
81     AddFeature(FeatureSet, Feature);
82   }
83   FreeMicroFeatures(OldFeatures);
84   return (FeatureSet);
85 
86 }                                /* ExtractMicros */
87