tesseract 4.1.1
Loading...
Searching...
No Matches
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
28class 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
42struct 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};
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.
76using 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/*----------------------------------------------------------------------
94Macro for describing a new feature. The parameters of the macro
95are as follows:
96
97DefineFeature (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----------------------------------------------------------------------*/
105bool AddFeature(FEATURE_SET FeatureSet, FEATURE Feature);
106
107void FreeFeature(FEATURE Feature);
108
109void FreeFeatureSet(FEATURE_SET FeatureSet);
110
111FEATURE NewFeature(const FEATURE_DESC_STRUCT* FeatureDesc);
112
113FEATURE_SET NewFeatureSet(int NumFeatures);
114
115FEATURE_SET ReadFeatureSet(FILE* File, const FEATURE_DESC_STRUCT* FeatureDesc);
116
117void WriteFeatureSet(FEATURE_SET FeatureSet, STRING* str);
118
119#endif
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
Definition: ocrfeatures.cpp:78
void WriteFeatureSet(FEATURE_SET FeatureSet, STRING *str)
void FreeFeatureSet(FEATURE_SET FeatureSet)
Definition: ocrfeatures.cpp:62
char * CHAR_FEATURES
Definition: ocrfeatures.h:76
bool AddFeature(FEATURE_SET FeatureSet, FEATURE Feature)
Definition: ocrfeatures.cpp:40
void FreeFeature(FEATURE Feature)
Definition: ocrfeatures.cpp:54
FEATURE_SET NewFeatureSet(int NumFeatures)
Definition: ocrfeatures.cpp:94
FEATURE_SET ReadFeatureSet(FILE *File, const FEATURE_DESC_STRUCT *FeatureDesc)
Definition: strngs.h:45
float HalfRange
Definition: ocrfeatures.h:48
float Range
Definition: ocrfeatures.h:47
bool Circular
Definition: ocrfeatures.h:43
float Max
Definition: ocrfeatures.h:46
float MidRange
Definition: ocrfeatures.h:49
bool NonEssential
Definition: ocrfeatures.h:44
float Min
Definition: ocrfeatures.h:45
const char * ShortName
Definition: ocrfeatures.h:54
const PARAM_DESC * ParamDesc
Definition: ocrfeatures.h:55
const FEATURE_DESC_STRUCT * Type
Definition: ocrfeatures.h:60
float Params[1]
Definition: ocrfeatures.h:61
FEATURE Features[1]
Definition: ocrfeatures.h:68
uint16_t MaxNumFeatures
Definition: ocrfeatures.h:67
uint16_t NumFeatures
Definition: ocrfeatures.h:66