tesseract v5.3.3.20231005
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
21#include "blobs.h"
22
23#include <cstdio>
24#include <string> // for std::string
25
26namespace tesseract {
27
28class DENORM;
29
30#undef Min
31#undef Max
32#define FEAT_NAME_SIZE 80
33
34// A character is described by multiple sets of extracted features. Each
35// set contains a number of features of a particular type, for example, a
36// set of bays, or a set of closures, or a set of microfeatures. Each
37// feature consists of a number of parameters. All features within a
38// feature set contain the same number of parameters. All circular
39// parameters are required to be the first parameters in the feature.
40
41struct PARAM_DESC {
42 bool Circular; // true if dimension wraps around
43 bool NonEssential; // true if dimension not used in searches
44 float Min; // low end of range for circular dimensions
45 float Max; // high end of range for circular dimensions
46 float Range; // Max - Min
47 float HalfRange; // (Max - Min)/2
48 float MidRange; // (Max + Min)/2
49};
50
52 uint16_t NumParams; // total # of params
53 const char *ShortName; // short name for feature
54 const PARAM_DESC *ParamDesc; // array - one per param
55};
57
61 FEATURE_STRUCT(const FEATURE_DESC_STRUCT *FeatureDesc) : Type(FeatureDesc), Params(FeatureDesc->NumParams) {
62 }
64 }
65 const FEATURE_DESC_STRUCT *Type; // points to description of feature type
66 std::vector<float> Params; // variable size array - params for feature
67};
69
74 FEATURE_SET_STRUCT(int numFeatures) : NumFeatures(0), MaxNumFeatures(numFeatures), Features(numFeatures) {
75 }
76
78 for (uint16_t i = 0; i < NumFeatures; i++) {
79 delete Features[i];
80 }
81 }
82
83 uint16_t NumFeatures; // number of features in set
84 uint16_t MaxNumFeatures; // maximum size of feature set
85 std::vector<FEATURE_STRUCT *> Features; // variable size array of features
86};
88
89// A generic character description as a char pointer. In reality, it will be
90// a pointer to some data structure. Paired feature extractors/matchers need
91// to agree on the data structure to be used, however, the high level
92// classifier does not need to know the details of this data structure.
93using CHAR_FEATURES = char *;
94
95/*----------------------------------------------------------------------
96 Macros for defining the parameters of a new features
97----------------------------------------------------------------------*/
98#define StartParamDesc(Name) const PARAM_DESC Name[] = {
99#define DefineParam(Circular, NonEssential, Min, Max) \
100 {Circular, \
101 NonEssential, \
102 Min, \
103 Max, \
104 (Max) - (Min), \
105 (((Max) - (Min)) / 2.0), \
106 (((Max) + (Min)) / 2.0)},
107
108#define EndParamDesc \
109 } \
110 ;
111
112/*----------------------------------------------------------------------
113Macro for describing a new feature. The parameters of the macro
114are as follows:
115
116DefineFeature (Name, NumLinear, NumCircular, ShortName, ParamName)
117----------------------------------------------------------------------*/
118#define DefineFeature(Name, NL, NC, SN, PN) \
119 const FEATURE_DESC_STRUCT Name = {((NL) + (NC)), SN, PN};
120
121/*----------------------------------------------------------------------
122 Generic routines that work for all feature types
123----------------------------------------------------------------------*/
124bool AddFeature(FEATURE_SET FeatureSet, FEATURE Feature);
125
126FEATURE_SET ReadFeatureSet(FILE *File, const FEATURE_DESC_STRUCT *FeatureDesc);
127
128void WriteFeatureSet(FEATURE_SET FeatureSet, std::string &str);
129
130} // namespace tesseract
131
132#endif
FEATURE_STRUCT * FEATURE
Definition: ocrfeatures.h:68
FEATURE_SET ReadFeatureSet(FILE *File, const FEATURE_DESC_STRUCT *FeatureDesc)
Definition: ocrfeatures.cpp:82
bool AddFeature(FEATURE_SET FeatureSet, FEATURE Feature)
Definition: ocrfeatures.cpp:40
FEATURE_SET_STRUCT * FEATURE_SET
Definition: ocrfeatures.h:87
char * CHAR_FEATURES
Definition: ocrfeatures.h:93
void WriteFeatureSet(FEATURE_SET FeatureSet, std::string &str)
const PARAM_DESC * ParamDesc
Definition: ocrfeatures.h:54
std::vector< float > Params
Definition: ocrfeatures.h:66
const FEATURE_DESC_STRUCT * Type
Definition: ocrfeatures.h:65
FEATURE_STRUCT(const FEATURE_DESC_STRUCT *FeatureDesc)
Definition: ocrfeatures.h:61
FEATURE_SET_STRUCT(int numFeatures)
Definition: ocrfeatures.h:74
std::vector< FEATURE_STRUCT * > Features
Definition: ocrfeatures.h:85