tesseract
3.03
|
00001 /****************************************************************************** 00002 ** Filename: mf.c 00003 ** Purpose: Micro-feature interface to flexible feature extractor. 00004 ** Author: Dan Johnson 00005 ** History: Thu May 24 09:08:38 1990, DSJ, Created. 00006 ** 00007 ** (c) Copyright Hewlett-Packard Company, 1988. 00008 ** Licensed under the Apache License, Version 2.0 (the "License"); 00009 ** you may not use this file except in compliance with the License. 00010 ** You may obtain a copy of the License at 00011 ** http://www.apache.org/licenses/LICENSE-2.0 00012 ** Unless required by applicable law or agreed to in writing, software 00013 ** distributed under the License is distributed on an "AS IS" BASIS, 00014 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 ** See the License for the specific language governing permissions and 00016 ** limitations under the License. 00017 ******************************************************************************/ 00021 #include "mf.h" 00022 00023 #include "featdefs.h" 00024 #include "mfdefs.h" 00025 #include "mfx.h" 00026 00027 #include <math.h> 00028 00035 /*---------------------------------------------------------------------------*/ 00036 FEATURE_SET ExtractMicros(TBLOB *Blob, const DENORM& bl_denorm, 00037 const DENORM& cn_denorm, 00038 const INT_FX_RESULT_STRUCT& fx_info) { 00039 /* 00040 ** Parameters: 00041 ** Blob blob to extract micro-features from 00042 ** denorm control parameter to feature extractor. 00043 ** Globals: none 00044 ** Operation: Call the old micro-feature extractor and then copy 00045 ** the features into the new format. Then deallocate the 00046 ** old micro-features. 00047 ** Return: Micro-features for Blob. 00048 ** Exceptions: none 00049 ** History: Wed May 23 18:06:38 1990, DSJ, Created. 00050 */ 00051 int NumFeatures; 00052 MICROFEATURES Features, OldFeatures; 00053 FEATURE_SET FeatureSet; 00054 FEATURE Feature; 00055 MICROFEATURE OldFeature; 00056 00057 OldFeatures = (MICROFEATURES)BlobMicroFeatures(Blob, bl_denorm, cn_denorm, 00058 fx_info); 00059 if (OldFeatures == NULL) 00060 return NULL; 00061 NumFeatures = count (OldFeatures); 00062 FeatureSet = NewFeatureSet (NumFeatures); 00063 00064 Features = OldFeatures; 00065 iterate(Features) { 00066 OldFeature = (MICROFEATURE) first_node (Features); 00067 Feature = NewFeature (&MicroFeatureDesc); 00068 Feature->Params[MFDirection] = OldFeature[ORIENTATION]; 00069 Feature->Params[MFXPosition] = OldFeature[XPOSITION]; 00070 Feature->Params[MFYPosition] = OldFeature[YPOSITION]; 00071 Feature->Params[MFLength] = OldFeature[MFLENGTH]; 00072 00073 // Bulge features are deprecated and should not be used. Set to 0. 00074 Feature->Params[MFBulge1] = 0.0f; 00075 Feature->Params[MFBulge2] = 0.0f; 00076 00077 #ifndef _WIN32 00078 // Assert that feature parameters are well defined. 00079 int i; 00080 for (i = 0; i < Feature->Type->NumParams; i++) { 00081 ASSERT_HOST(!isnan(Feature->Params[i])); 00082 } 00083 #endif 00084 00085 AddFeature(FeatureSet, Feature); 00086 } 00087 FreeMicroFeatures(OldFeatures); 00088 return FeatureSet; 00089 } /* ExtractMicros */