tesseract  3.03
/usr/local/google/home/jbreiden/tesseract-ocr-read-only/classify/ocrfeatures.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  **     Filename:    features.h
00003  **     Purpose:     Generic definition of a feature.
00004  **     Author:      Dan Johnson
00005  **     History:     Sun May 20 10:28:30 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 #ifndef   FEATURES_H
00019 #define   FEATURES_H
00020 
00024 #include "blobs.h"
00025 
00026 #include <stdio.h>
00027 
00028 class DENORM;
00029 struct INT_FX_RESULT_STRUCT;
00030 
00031 #undef Min
00032 #undef Max
00033 #define FEAT_NAME_SIZE    80
00034 
00035 // define trap errors which can be caused by this module
00036 #define ILLEGAL_FEATURE_PARAM 1000
00037 #define ILLEGAL_NUM_FEATURES  1001
00038 
00039 // A character is described by multiple sets of extracted features.  Each
00040 // set contains a number of features of a particular type, for example, a
00041 // set of bays, or a set of closures, or a set of microfeatures.  Each
00042 // feature consists of a number of parameters.  All features within a
00043 // feature set contain the same number of parameters.  All circular
00044 // parameters are required to be the first parameters in the feature.
00045 
00046 struct PARAM_DESC {
00047   inT8 Circular;                   // TRUE if dimension wraps around
00048   inT8 NonEssential;               // TRUE if dimension not used in searches
00049   FLOAT32 Min;                     // low end of range for circular dimensions
00050   FLOAT32 Max;                     // high end of range for circular dimensions
00051   FLOAT32 Range;                   // Max - Min
00052   FLOAT32 HalfRange;               // (Max - Min)/2
00053   FLOAT32 MidRange;                // (Max + Min)/2
00054 };
00055 
00056 struct FEATURE_DESC_STRUCT {
00057   uinT16 NumParams;                // total # of params
00058   const char *ShortName;           // short name for feature
00059   const PARAM_DESC *ParamDesc;     // array - one per param
00060 };
00061 typedef FEATURE_DESC_STRUCT *FEATURE_DESC;
00062 
00063 struct FEATURE_STRUCT {
00064   const FEATURE_DESC_STRUCT *Type;  // points to description of feature type
00065   FLOAT32 Params[1];                // variable size array - params for feature
00066 };
00067 typedef FEATURE_STRUCT *FEATURE;
00068 
00069 struct FEATURE_SET_STRUCT {
00070   uinT16 NumFeatures;            // number of features in set
00071   uinT16 MaxNumFeatures;         // maximum size of feature set
00072   FEATURE Features[1];           // variable size array of features
00073 };
00074 typedef FEATURE_SET_STRUCT *FEATURE_SET;
00075 
00076 // A generic character description as a char pointer. In reality, it will be
00077 // a pointer to some data structure. Paired feature extractors/matchers need
00078 // to agree on the data structure to be used, however, the high level
00079 // classifier does not need to know the details of this data structure.
00080 typedef char *CHAR_FEATURES;
00081 
00082 typedef FEATURE_SET (*FX_FUNC)(TBLOB *, const DENORM&, const DENORM&,
00083                                const INT_FX_RESULT_STRUCT&);
00084 
00085 struct FEATURE_EXT_STRUCT {
00086   FX_FUNC Extractor;             // func to extract features
00087 };
00088 
00089 /*----------------------------------------------------------------------
00090     Macros for defining the parameters of a new features
00091 ----------------------------------------------------------------------*/
00092 #define StartParamDesc(Name)    \
00093 const PARAM_DESC Name[] = {
00094 
00095 #define DefineParam(Circular, NonEssential, Min, Max)   \
00096         {Circular, NonEssential, Min, Max,                      \
00097         (Max) - (Min), (((Max) - (Min))/2.0), (((Max) + (Min))/2.0)},
00098 
00099 #define EndParamDesc  };
00100 
00101 /*----------------------------------------------------------------------
00102 Macro for describing a new feature.  The parameters of the macro
00103 are as follows:
00104 
00105 DefineFeature (Name, NumLinear, NumCircular, ShortName, ParamName)
00106 ----------------------------------------------------------------------*/
00107 #define DefineFeature(Name, NL, NC, SN, PN)             \
00108 const FEATURE_DESC_STRUCT Name = {                              \
00109         ((NL) + (NC)), SN, PN};
00110 
00111 /*----------------------------------------------------------------------
00112         Generic routines that work for all feature types
00113 ----------------------------------------------------------------------*/
00114 BOOL8 AddFeature(FEATURE_SET FeatureSet, FEATURE Feature);
00115 
00116 void FreeFeature(FEATURE Feature);
00117 
00118 void FreeFeatureSet(FEATURE_SET FeatureSet);
00119 
00120 FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc);
00121 
00122 FEATURE_SET NewFeatureSet(int NumFeatures);
00123 
00124 FEATURE ReadFeature(FILE *File, const FEATURE_DESC_STRUCT *FeatureDesc);
00125 
00126 FEATURE_SET ReadFeatureSet(FILE *File, const FEATURE_DESC_STRUCT *FeatureDesc);
00127 
00128 void WriteFeature(FILE *File, FEATURE Feature);
00129 
00130 void WriteFeatureSet(FILE *File, FEATURE_SET FeatureSet);
00131 
00132 void WriteOldParamDesc(FILE *File, const FEATURE_DESC_STRUCT *FeatureDesc);
00133 
00134 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines