Tesseract  3.02
tesseract-ocr/classify/mf.cpp
Go to the documentation of this file.
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& denorm) {
00037 /*
00038  **     Parameters:
00039  **             Blob            blob to extract micro-features from
00040  **             denorm  control parameter to feature extractor.
00041  **     Globals: none
00042  **     Operation: Call the old micro-feature extractor and then copy
00043  **             the features into the new format.  Then deallocate the
00044  **             old micro-features.
00045  **     Return: Micro-features for Blob.
00046  **     Exceptions: none
00047  **     History: Wed May 23 18:06:38 1990, DSJ, Created.
00048  */
00049   int NumFeatures;
00050   MICROFEATURES Features, OldFeatures;
00051   FEATURE_SET FeatureSet;
00052   FEATURE Feature;
00053   MICROFEATURE OldFeature;
00054 
00055   OldFeatures = (MICROFEATURES)BlobMicroFeatures(Blob, denorm);
00056   if (OldFeatures == NULL)
00057     return NULL;
00058   NumFeatures = count (OldFeatures);
00059   FeatureSet = NewFeatureSet (NumFeatures);
00060 
00061   Features = OldFeatures;
00062   iterate(Features) {
00063     OldFeature = (MICROFEATURE) first_node (Features);
00064     Feature = NewFeature (&MicroFeatureDesc);
00065     Feature->Params[MFDirection] = OldFeature[ORIENTATION];
00066     Feature->Params[MFXPosition] = OldFeature[XPOSITION];
00067     Feature->Params[MFYPosition] = OldFeature[YPOSITION];
00068     Feature->Params[MFLength] = OldFeature[MFLENGTH];
00069 
00070     // Bulge features are deprecated and should not be used.  Set to 0.
00071     Feature->Params[MFBulge1] = 0.0f;
00072     Feature->Params[MFBulge2] = 0.0f;
00073 
00074 #ifndef _WIN32
00075     // Assert that feature parameters are well defined.
00076     int i;
00077     for (i = 0; i < Feature->Type->NumParams; i++) {
00078       assert (!isnan(Feature->Params[i]));
00079     }
00080 #endif
00081 
00082     AddFeature(FeatureSet, Feature);
00083   }
00084   FreeMicroFeatures(OldFeatures);
00085   return (FeatureSet);
00086 
00087 }                                /* ExtractMicros */