Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/tesseract/src/classify/ocrfeatures.h @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 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 | |
| 26 namespace tesseract { | |
| 27 | |
| 28 class 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 | |
| 41 struct 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 | |
| 51 struct FEATURE_DESC_STRUCT { | |
| 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 }; | |
| 56 using FEATURE_DESC = FEATURE_DESC_STRUCT *; | |
| 57 | |
| 58 struct FEATURE_STRUCT { | |
| 59 /// Constructor for a new feature of the specified type. | |
| 60 /// @param FeatureDesc description of feature to be created. | |
| 61 FEATURE_STRUCT(const FEATURE_DESC_STRUCT *FeatureDesc) : Type(FeatureDesc), Params(FeatureDesc->NumParams) { | |
| 62 } | |
| 63 ~FEATURE_STRUCT() { | |
| 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 }; | |
| 68 using FEATURE = FEATURE_STRUCT *; | |
| 69 | |
| 70 struct FEATURE_SET_STRUCT { | |
| 71 /// Creator for a new feature set large enough to | |
| 72 /// hold the specified number of features. | |
| 73 /// @param NumFeatures maximum # of features to be put in feature set | |
| 74 FEATURE_SET_STRUCT(int numFeatures) : NumFeatures(0), MaxNumFeatures(numFeatures), Features(numFeatures) { | |
| 75 } | |
| 76 | |
| 77 ~FEATURE_SET_STRUCT() { | |
| 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 }; | |
| 87 using FEATURE_SET = FEATURE_SET_STRUCT *; | |
| 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. | |
| 93 using 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 /*---------------------------------------------------------------------- | |
| 113 Macro for describing a new feature. The parameters of the macro | |
| 114 are as follows: | |
| 115 | |
| 116 DefineFeature (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 ----------------------------------------------------------------------*/ | |
| 124 bool AddFeature(FEATURE_SET FeatureSet, FEATURE Feature); | |
| 125 | |
| 126 FEATURE_SET ReadFeatureSet(FILE *File, const FEATURE_DESC_STRUCT *FeatureDesc); | |
| 127 | |
| 128 void WriteFeatureSet(FEATURE_SET FeatureSet, std::string &str); | |
| 129 | |
| 130 } // namespace tesseract | |
| 131 | |
| 132 #endif |
