tesseract  v4.0.0-17-g361f3264
Open Source OCR Engine
ocrfeatures.h
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 
19 #ifndef FEATURES_H
20 #define FEATURES_H
21 
25 #include "blobs.h"
26 
27 #include <cstdio>
28 
29 class DENORM;
31 
32 #undef Min
33 #undef Max
34 #define FEAT_NAME_SIZE 80
35 
36 // A character is described by multiple sets of extracted features. Each
37 // set contains a number of features of a particular type, for example, a
38 // set of bays, or a set of closures, or a set of microfeatures. Each
39 // feature consists of a number of parameters. All features within a
40 // feature set contain the same number of parameters. All circular
41 // parameters are required to be the first parameters in the feature.
42 
43 struct PARAM_DESC {
44  int8_t Circular; // TRUE if dimension wraps around
45  int8_t NonEssential; // TRUE if dimension not used in searches
46  float Min; // low end of range for circular dimensions
47  float Max; // high end of range for circular dimensions
48  float Range; // Max - Min
49  float HalfRange; // (Max - Min)/2
50  float MidRange; // (Max + Min)/2
51 };
52 
54  uint16_t NumParams; // total # of params
55  const char* ShortName; // short name for feature
56  const PARAM_DESC* ParamDesc; // array - one per param
57 };
59 
61  const FEATURE_DESC_STRUCT* Type; // points to description of feature type
62  float Params[1]; // variable size array - params for feature
63 };
64 using FEATURE = FEATURE_STRUCT*;
65 
67  uint16_t NumFeatures; // number of features in set
68  uint16_t MaxNumFeatures; // maximum size of feature set
69  FEATURE Features[1]; // variable size array of features
70 };
72 
73 // A generic character description as a char pointer. In reality, it will be
74 // a pointer to some data structure. Paired feature extractors/matchers need
75 // to agree on the data structure to be used, however, the high level
76 // classifier does not need to know the details of this data structure.
77 using CHAR_FEATURES = char*;
78 
79 /*----------------------------------------------------------------------
80  Macros for defining the parameters of a new features
81 ----------------------------------------------------------------------*/
82 #define StartParamDesc(Name) const PARAM_DESC Name[] = {
83 #define DefineParam(Circular, NonEssential, Min, Max) \
84  {Circular, \
85  NonEssential, \
86  Min, \
87  Max, \
88  (Max) - (Min), \
89  (((Max) - (Min)) / 2.0), \
90  (((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 = {((NL) + (NC)), SN, PN};
102 
103 /*----------------------------------------------------------------------
104  Generic routines that work for all feature types
105 ----------------------------------------------------------------------*/
106 bool AddFeature(FEATURE_SET FeatureSet, FEATURE Feature);
107 
108 void FreeFeature(FEATURE Feature);
109 
110 void FreeFeatureSet(FEATURE_SET FeatureSet);
111 
112 FEATURE NewFeature(const FEATURE_DESC_STRUCT* FeatureDesc);
113 
114 FEATURE_SET NewFeatureSet(int NumFeatures);
115 
116 FEATURE ReadFeature(FILE* File, const FEATURE_DESC_STRUCT* FeatureDesc);
117 
118 FEATURE_SET ReadFeatureSet(FILE* File, const FEATURE_DESC_STRUCT* FeatureDesc);
119 
120 void WriteFeature(FEATURE Feature, STRING* str);
121 
122 void WriteFeatureSet(FEATURE_SET FeatureSet, STRING* str);
123 
124 #endif
Definition: ocrfeatures.h:53
const PARAM_DESC * ParamDesc
Definition: ocrfeatures.h:56
Definition: intfx.h:35
uint16_t MaxNumFeatures
Definition: ocrfeatures.h:68
const FEATURE_DESC_STRUCT * Type
Definition: ocrfeatures.h:61
float Min
Definition: ocrfeatures.h:46
Definition: ocrfeatures.h:60
float HalfRange
Definition: ocrfeatures.h:49
float MidRange
Definition: ocrfeatures.h:50
int8_t Circular
Definition: ocrfeatures.h:44
const char * ShortName
Definition: ocrfeatures.h:55
Definition: strngs.h:45
int8_t NonEssential
Definition: ocrfeatures.h:45
float Max
Definition: ocrfeatures.h:47
Definition: normalis.h:50
Definition: ocrfeatures.h:66
uint16_t NumFeatures
Definition: ocrfeatures.h:67
float Range
Definition: ocrfeatures.h:48
Definition: ocrfeatures.h:43
uint16_t NumParams
Definition: ocrfeatures.h:54