00001
00019 #ifndef FEATURES_H
00020 #define FEATURES_H
00021
00022
00023
00024
00025 #include "funcdefs.h"
00026 #include "tessclas.h"
00027 #include "fxdefs.h"
00028 #include <stdio.h>
00029
00030 #undef Min
00031 #undef Max
00032
00033 #define FEAT_NAME_SIZE 80
00034
00036 #define ILLEGAL_FEATURE_PARAM 1000
00037 #define ILLEGAL_NUM_FEATURES 1001
00038
00056 typedef struct
00057 {
00059 struct fds *Type;
00061 FLOAT32 Params[1];
00062 } FEATURE_STRUCT;
00067 typedef FEATURE_STRUCT *FEATURE;
00068
00080 typedef struct
00081 {
00083 UINT16 NumFeatures;
00085 UINT16 MaxNumFeatures;
00087 FEATURE Features[1];
00088 } FEATURE_SET_STRUCT;
00089
00094 typedef FEATURE_SET_STRUCT *FEATURE_SET;
00095
00096
00097 typedef FEATURE (*FEAT_FUNC) ();
00098 typedef FEATURE_SET (*FX_FUNC) (TBLOB *, LINE_STATS *);
00099 typedef FLOAT32 (*PENALTY_FUNC) ();
00100
00107 typedef struct
00108 {
00110 INT8 Circular;
00112 INT8 NonEssential;
00114 FLOAT32 Min;
00116 FLOAT32 Max;
00118 FLOAT32 Range;
00120 FLOAT32 HalfRange;
00122 FLOAT32 MidRange;
00123 } PARAM_DESC;
00124
00137 typedef struct fds
00138 {
00140 UINT16 NumParams;
00142 UINT8 NumLinearParams;
00144 UINT8 NumCircularParams;
00146 UINT8 MinFeatPerChar;
00148 UINT8 MaxFeatPerChar;
00150 char LongName[FEAT_NAME_SIZE];
00152 char ShortName[FEAT_NAME_SIZE];
00154 PARAM_DESC *ParamDesc;
00155 } FEATURE_DESC_STRUCT;
00156
00163 typedef FEATURE_DESC_STRUCT *FEATURE_DESC;
00164
00172 typedef struct fxs
00173 {
00175 FX_FUNC Extractor;
00177 VOID_FUNC InitExtractorVars;
00178 } FEATURE_EXT_STRUCT;
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00195 #define StartParamDesc(Name) \
00196 static PARAM_DESC Name[] = {
00197
00202 #define DefineParam(Circular, NonEssential, Min, Max) \
00203 {Circular, NonEssential, Min, Max, \
00204 (Max) - (Min), (((Max) - (Min))/2.0), (((Max) + (Min))/2.0)},
00205
00207 #define EndParamDesc };
00208
00225 #define DefineFeature(Name, NL, NC, Min, Max, LN, SN, PN) \
00226 FEATURE_DESC_STRUCT Name = { \
00227 ((NL) + (NC)), NL, NC, Min, Max, LN, SN, PN};
00228 #define DefineFeatureExt(Name, E, IEV) \
00229 FEATURE_EXT_STRUCT Name = {E, IEV};
00230
00231
00232
00233
00235 #define TypeOf(Feature) ((Feature)->Type)
00236
00237 #define ParamOf(Feature, N) ((Feature)->Params[N])
00238
00239 #define NumParamsIn(Feature) (TypeOf (Feature) -> NumParams)
00240
00241
00242
00243
00245 #define NumFeaturesIn(Set) ((Set)->NumFeatures)
00246
00247 #define MaxNumFeaturesIn(Set) ((Set)->MaxNumFeatures)
00248
00249 #define FeatureIn(Set, N) ((Set)->Features[N])
00250
00251
00252
00253
00255 #define ShortNameOf(FeatDesc) ((FeatDesc)->ShortName)
00256
00257 #define LongNameOf(FeatDesc) ((FeatDesc)->LongName)
00258
00259 #define ExtractUsing(FeatDesc) (*(FeatDesc)->Extractor)
00260
00261 #define InitFXVarsUsing(FD) (*(FD)->InitExtractorVars)
00262
00263
00264
00265
00266 BOOL8 AddFeature(FEATURE_SET FeatureSet, FEATURE Feature);
00267
00268 void DefaultInitFXVars();
00269
00270 void FreeFeature(FEATURE Feature);
00271
00272 void FreeFeatureSet(FEATURE_SET FeatureSet);
00273
00274 FEATURE NewFeature(FEATURE_DESC FeatureDesc);
00275
00276 FEATURE_SET NewFeatureSet(int NumFeatures);
00277
00278 FEATURE ReadFeature(FILE *File, FEATURE_DESC FeatureDesc);
00279
00280 FEATURE_SET ReadFeatureSet(FILE *File, FEATURE_DESC FeatureDesc);
00281
00282 void WriteFeature(FILE *File, FEATURE Feature);
00283
00284 void WriteFeatureSet(FILE *File, FEATURE_SET FeatureSet);
00285
00286 void WriteOldParamDesc(FILE *File, FEATURE_DESC FeatureDesc);
00287 #endif