tesseract 3.04.01

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  ******************************************************************************/
00018 /*----------------------------------------------------------------------------
00019           Include Files and Type Defines
00020 ----------------------------------------------------------------------------*/
00021 #include "mf.h"
00022 
00023 #include "featdefs.h"
00024 #include "mfdefs.h"
00025 #include "mfx.h"
00026 
00027 #include <math.h>
00028 
00029 /*----------------------------------------------------------------------------
00030         Global Data Definitions and Declarations
00031 ----------------------------------------------------------------------------*/
00032 /*----------------------------------------------------------------------------
00033               Private Code
00034 ----------------------------------------------------------------------------*/
00045 FEATURE_SET ExtractMicros(TBLOB* Blob, const DENORM& cn_denorm) {
00046   int NumFeatures;
00047   MICROFEATURES Features, OldFeatures;
00048   FEATURE_SET FeatureSet;
00049   FEATURE Feature;
00050   MICROFEATURE OldFeature;
00051 
00052   OldFeatures = BlobMicroFeatures(Blob, cn_denorm);
00053   if (OldFeatures == NULL)
00054     return NULL;
00055   NumFeatures = count (OldFeatures);
00056   FeatureSet = NewFeatureSet (NumFeatures);
00057 
00058   Features = OldFeatures;
00059   iterate(Features) {
00060     OldFeature = (MICROFEATURE) first_node (Features);
00061     Feature = NewFeature (&MicroFeatureDesc);
00062     Feature->Params[MFDirection] = OldFeature[ORIENTATION];
00063     Feature->Params[MFXPosition] = OldFeature[XPOSITION];
00064     Feature->Params[MFYPosition] = OldFeature[YPOSITION];
00065     Feature->Params[MFLength] = OldFeature[MFLENGTH];
00066 
00067     // Bulge features are deprecated and should not be used.  Set to 0.
00068     Feature->Params[MFBulge1] = 0.0f;
00069     Feature->Params[MFBulge2] = 0.0f;
00070 
00071 #ifndef _WIN32
00072     // Assert that feature parameters are well defined.
00073     int i;
00074     for (i = 0; i < Feature->Type->NumParams; i++) {
00075       ASSERT_HOST(!isnan(Feature->Params[i]));
00076     }
00077 #endif
00078 
00079     AddFeature(FeatureSet, Feature);
00080   }
00081   FreeMicroFeatures(OldFeatures);
00082   return FeatureSet;
00083 }                                /* ExtractMicros */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines