|
tesseract 3.04.01
|
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 /*---------------------------------------------------------------------- 00083 Macros for defining the parameters of a new features 00084 ----------------------------------------------------------------------*/ 00085 #define StartParamDesc(Name) \ 00086 const PARAM_DESC Name[] = { 00087 00088 #define DefineParam(Circular, NonEssential, Min, Max) \ 00089 {Circular, NonEssential, Min, Max, \ 00090 (Max) - (Min), (((Max) - (Min))/2.0), (((Max) + (Min))/2.0)}, 00091 00092 #define EndParamDesc }; 00093 00094 /*---------------------------------------------------------------------- 00095 Macro for describing a new feature. The parameters of the macro 00096 are as follows: 00097 00098 DefineFeature (Name, NumLinear, NumCircular, ShortName, ParamName) 00099 ----------------------------------------------------------------------*/ 00100 #define DefineFeature(Name, NL, NC, SN, PN) \ 00101 const FEATURE_DESC_STRUCT Name = { \ 00102 ((NL) + (NC)), SN, PN}; 00103 00104 /*---------------------------------------------------------------------- 00105 Generic routines that work for all feature types 00106 ----------------------------------------------------------------------*/ 00107 BOOL8 AddFeature(FEATURE_SET FeatureSet, FEATURE Feature); 00108 00109 void FreeFeature(FEATURE Feature); 00110 00111 void FreeFeatureSet(FEATURE_SET FeatureSet); 00112 00113 FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc); 00114 00115 FEATURE_SET NewFeatureSet(int NumFeatures); 00116 00117 FEATURE ReadFeature(FILE *File, const FEATURE_DESC_STRUCT *FeatureDesc); 00118 00119 FEATURE_SET ReadFeatureSet(FILE *File, const FEATURE_DESC_STRUCT *FeatureDesc); 00120 00121 void WriteFeature(FEATURE Feature, STRING* str); 00122 00123 void WriteFeatureSet(FEATURE_SET FeatureSet, STRING* str); 00124 00125 #endif