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