Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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;
29
30 #undef Min
31 #undef Max
32 #define FEAT_NAME_SIZE 80
33
34 // define trap errors which can be caused by this module
35 #define ILLEGAL_FEATURE_PARAM 1000
36 #define ILLEGAL_NUM_FEATURES 1001
37
38 // A character is described by multiple sets of extracted features. Each
39 // set contains a number of features of a particular type, for example, a
40 // set of bays, or a set of closures, or a set of microfeatures. Each
41 // feature consists of a number of parameters. All features within a
42 // feature set contain the same number of parameters. All circular
43 // parameters are required to be the first parameters in the feature.
44
45 struct PARAM_DESC {
46 inT8 Circular; // TRUE if dimension wraps around
47 inT8 NonEssential; // TRUE if dimension not used in searches
48 FLOAT32 Min; // low end of range for circular dimensions
49 FLOAT32 Max; // high end of range for circular dimensions
50 FLOAT32 Range; // Max - Min
51 FLOAT32 HalfRange; // (Max - Min)/2
52 FLOAT32 MidRange; // (Max + Min)/2
53 };
54
55 struct FEATURE_DESC_STRUCT {
56 uinT16 NumParams; // total # of params
57 const char *ShortName; // short name for feature
58 const PARAM_DESC *ParamDesc; // array - one per param
59 };
60 typedef FEATURE_DESC_STRUCT *FEATURE_DESC;
61
62 struct FEATURE_STRUCT {
63 const FEATURE_DESC_STRUCT *Type; // points to description of feature type
64 FLOAT32 Params[1]; // variable size array - params for feature
65 };
66 typedef FEATURE_STRUCT *FEATURE;
67
68 struct FEATURE_SET_STRUCT {
69 uinT16 NumFeatures; // number of features in set
70 uinT16 MaxNumFeatures; // maximum size of feature set
71 FEATURE Features[1]; // variable size array of features
72 };
73 typedef FEATURE_SET_STRUCT *FEATURE_SET;
74
75 // A generic character description as a char pointer. In reality, it will be
76 // a pointer to some data structure. Paired feature extractors/matchers need
77 // to agree on the data structure to be used, however, the high level
78 // classifier does not need to know the details of this data structure.
79 typedef char *CHAR_FEATURES;
80
81 typedef FEATURE_SET (*FX_FUNC) (TBLOB *, const DENORM&);
82
83 struct FEATURE_EXT_STRUCT {
84 FX_FUNC Extractor; // func to extract features
85 };
86
87 /*----------------------------------------------------------------------
88 Macros for defining the parameters of a new features
89 ----------------------------------------------------------------------*/
90 #define StartParamDesc(Name) \
91 const PARAM_DESC Name[] = {
92
93 #define DefineParam(Circular, NonEssential, Min, Max) \
94 {Circular, NonEssential, Min, Max, \
95 (Max) - (Min), (((Max) - (Min))/2.0), (((Max) + (Min))/2.0)},
96
97 #define EndParamDesc };
98
99 /*----------------------------------------------------------------------
100 Macro for describing a new feature. The parameters of the macro
101 are as follows:
102
103 DefineFeature (Name, NumLinear, NumCircular, ShortName, ParamName)
104 ----------------------------------------------------------------------*/
105 #define DefineFeature(Name, NL, NC, SN, PN) \
106 const FEATURE_DESC_STRUCT Name = { \
107 ((NL) + (NC)), SN, PN};
108
109 /*----------------------------------------------------------------------
110 Generic routines that work for all feature types
111 ----------------------------------------------------------------------*/
112 BOOL8 AddFeature(FEATURE_SET FeatureSet, FEATURE Feature);
113
114 void FreeFeature(FEATURE Feature);
115
116 void FreeFeatureSet(FEATURE_SET FeatureSet);
117
118 FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc);
119
120 FEATURE_SET NewFeatureSet(int NumFeatures);
121
122 FEATURE ReadFeature(FILE *File, const FEATURE_DESC_STRUCT *FeatureDesc);
123
124 FEATURE_SET ReadFeatureSet(FILE *File, const FEATURE_DESC_STRUCT *FeatureDesc);
125
126 void WriteFeature(FILE *File, FEATURE Feature);
127
128 void WriteFeatureSet(FILE *File, FEATURE_SET FeatureSet);
129
130 void WriteOldParamDesc(FILE *File, const FEATURE_DESC_STRUCT *FeatureDesc);
131
132 #endif