tesseract  4.00.00dev
ocrfeatures.h
Go to the documentation of this file.
1 /******************************************************************************
2  ** Filename: features.h
3  ** Purpose: Generic definition of a feature.
4  ** Author: Dan Johnson
5  ** History: Sun May 20 10:28:30 1990, DSJ, Created.
6  **
7  ** (c) Copyright Hewlett-Packard Company, 1988.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  ******************************************************************************/
18 #ifndef FEATURES_H
19 #define FEATURES_H
20 
24 #include "blobs.h"
25 
26 #include <stdio.h>
27 
28 class DENORM;
30 
31 #undef Min
32 #undef Max
33 #define FEAT_NAME_SIZE 80
34 
35 // define trap errors which can be caused by this module
36 #define ILLEGAL_FEATURE_PARAM 1000
37 #define ILLEGAL_NUM_FEATURES 1001
38 
39 // A character is described by multiple sets of extracted features. Each
40 // set contains a number of features of a particular type, for example, a
41 // set of bays, or a set of closures, or a set of microfeatures. Each
42 // feature consists of a number of parameters. All features within a
43 // feature set contain the same number of parameters. All circular
44 // parameters are required to be the first parameters in the feature.
45 
46 struct PARAM_DESC {
47  inT8 Circular; // TRUE if dimension wraps around
48  inT8 NonEssential; // TRUE if dimension not used in searches
49  FLOAT32 Min; // low end of range for circular dimensions
50  FLOAT32 Max; // high end of range for circular dimensions
51  FLOAT32 Range; // Max - Min
52  FLOAT32 HalfRange; // (Max - Min)/2
53  FLOAT32 MidRange; // (Max + Min)/2
54 };
55 
57  uinT16 NumParams; // total # of params
58  const char *ShortName; // short name for feature
59  const PARAM_DESC *ParamDesc; // array - one per param
60 };
62 
64  const FEATURE_DESC_STRUCT *Type; // points to description of feature type
65  FLOAT32 Params[1]; // variable size array - params for feature
66 };
68 
70  uinT16 NumFeatures; // number of features in set
71  uinT16 MaxNumFeatures; // maximum size of feature set
72  FEATURE Features[1]; // variable size array of features
73 };
75 
76 // A generic character description as a char pointer. In reality, it will be
77 // a pointer to some data structure. Paired feature extractors/matchers need
78 // to agree on the data structure to be used, however, the high level
79 // classifier does not need to know the details of this data structure.
80 typedef char *CHAR_FEATURES;
81 
82 /*----------------------------------------------------------------------
83  Macros for defining the parameters of a new features
84 ----------------------------------------------------------------------*/
85 #define StartParamDesc(Name) \
86 const PARAM_DESC Name[] = {
87 
88 #define DefineParam(Circular, NonEssential, Min, Max) \
89  {Circular, NonEssential, Min, Max, \
90  (Max) - (Min), (((Max) - (Min))/2.0), (((Max) + (Min))/2.0)},
91 
92 #define EndParamDesc };
93 
94 /*----------------------------------------------------------------------
95 Macro for describing a new feature. The parameters of the macro
96 are as follows:
97 
98 DefineFeature (Name, NumLinear, NumCircular, ShortName, ParamName)
99 ----------------------------------------------------------------------*/
100 #define DefineFeature(Name, NL, NC, SN, PN) \
101 const FEATURE_DESC_STRUCT Name = { \
102  ((NL) + (NC)), SN, PN};
103 
104 /*----------------------------------------------------------------------
105  Generic routines that work for all feature types
106 ----------------------------------------------------------------------*/
107 BOOL8 AddFeature(FEATURE_SET FeatureSet, FEATURE Feature);
108 
109 void FreeFeature(FEATURE Feature);
110 
111 void FreeFeatureSet(FEATURE_SET FeatureSet);
112 
113 FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc);
114 
115 FEATURE_SET NewFeatureSet(int NumFeatures);
116 
117 FEATURE ReadFeature(FILE *File, const FEATURE_DESC_STRUCT *FeatureDesc);
118 
119 FEATURE_SET ReadFeatureSet(FILE *File, const FEATURE_DESC_STRUCT *FeatureDesc);
120 
121 void WriteFeature(FEATURE Feature, STRING* str);
122 
123 void WriteFeatureSet(FEATURE_SET FeatureSet, STRING* str);
124 
125 #endif
FEATURE ReadFeature(FILE *File, const FEATURE_DESC_STRUCT *FeatureDesc)
FEATURE_SET NewFeatureSet(int NumFeatures)
FEATURE_SET ReadFeatureSet(FILE *File, const FEATURE_DESC_STRUCT *FeatureDesc)
FLOAT32 MidRange
Definition: ocrfeatures.h:53
const char * ShortName
Definition: ocrfeatures.h:58
const PARAM_DESC * ParamDesc
Definition: ocrfeatures.h:59
FLOAT32 Range
Definition: ocrfeatures.h:51
const FEATURE_DESC_STRUCT * Type
Definition: ocrfeatures.h:64
inT8 Circular
Definition: ocrfeatures.h:47
FLOAT32 Min
Definition: ocrfeatures.h:49
char * CHAR_FEATURES
Definition: ocrfeatures.h:80
inT8 NonEssential
Definition: ocrfeatures.h:48
FEATURE_STRUCT * FEATURE
Definition: ocrfeatures.h:67
unsigned char BOOL8
Definition: host.h:44
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
Definition: ocrfeatures.cpp:88
Definition: strngs.h:45
void WriteFeatureSet(FEATURE_SET FeatureSet, STRING *str)
FEATURE_SET_STRUCT * FEATURE_SET
Definition: ocrfeatures.h:74
void FreeFeatureSet(FEATURE_SET FeatureSet)
Definition: ocrfeatures.cpp:71
float FLOAT32
Definition: host.h:42
int8_t inT8
Definition: host.h:34
FLOAT32 Max
Definition: ocrfeatures.h:50
FEATURE_DESC_STRUCT * FEATURE_DESC
Definition: ocrfeatures.h:61
uint16_t uinT16
Definition: host.h:37
BOOL8 AddFeature(FEATURE_SET FeatureSet, FEATURE Feature)
Definition: ocrfeatures.cpp:43
void WriteFeature(FEATURE Feature, STRING *str)
void FreeFeature(FEATURE Feature)
Definition: ocrfeatures.cpp:59
FLOAT32 HalfRange
Definition: ocrfeatures.h:52