Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/tesseract/src/training/common/intfeaturedist.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 // Copyright 2011 Google Inc. All Rights Reserved. | |
| 2 // Author: rays@google.com (Ray Smith) | |
| 3 /////////////////////////////////////////////////////////////////////// | |
| 4 // File: intfeaturedist.h | |
| 5 // Description: Fast set-difference-based feature distance calculator. | |
| 6 // | |
| 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 | |
| 19 #ifndef TESSERACT_CLASSIFY_INTFEATUREDIST_H_ | |
| 20 #define TESSERACT_CLASSIFY_INTFEATUREDIST_H_ | |
| 21 | |
| 22 #include <vector> | |
| 23 | |
| 24 namespace tesseract { | |
| 25 | |
| 26 class IntFeatureMap; | |
| 27 | |
| 28 // Feature distance calculator designed to provide a fast distance calculation | |
| 29 // based on set difference between a given feature set and many other feature | |
| 30 // sets in turn. | |
| 31 // Representation of a feature set as an array of bools that are sparsely | |
| 32 // true, and companion arrays that allow fast feature set distance | |
| 33 // calculations with allowance of offsets in position. | |
| 34 // Init is expensive, so for greatest efficiency, to re-initialize for a new | |
| 35 // feature set, use Set(..., false) on the SAME feature set as was used to | |
| 36 // setup with Set(..., true), to return to its initialized state before | |
| 37 // reuse with Set(..., true) on a new feature set. | |
| 38 class IntFeatureDist { | |
| 39 public: | |
| 40 IntFeatureDist(); | |
| 41 ~IntFeatureDist(); | |
| 42 | |
| 43 // Initialize the bool array to the given size of feature space. | |
| 44 // The feature_map is just borrowed, and must exist for the entire | |
| 45 // lifetime of the IntFeatureDist. | |
| 46 void Init(const IntFeatureMap *feature_map); | |
| 47 | |
| 48 // Setup the map for the given indexed_features that have been indexed by | |
| 49 // feature_map. After use, use Set(..., false) to reset to the initial state | |
| 50 // as this is faster than calling Init for sparse spaces. | |
| 51 void Set(const std::vector<int> &indexed_features, int canonical_count, bool value); | |
| 52 | |
| 53 // Compute the distance between the given feature vector and the last | |
| 54 // Set feature vector. | |
| 55 double FeatureDistance(const std::vector<int> &features) const; | |
| 56 double DebugFeatureDistance(const std::vector<int> &features) const; | |
| 57 | |
| 58 private: | |
| 59 // Clear all data. | |
| 60 void Clear(); | |
| 61 | |
| 62 // Size of the indexed feature space. | |
| 63 int size_; | |
| 64 // Total weight of features currently stored in the maps. | |
| 65 double total_feature_weight_; | |
| 66 // Pointer to IntFeatureMap given at Init to find offset features. | |
| 67 const IntFeatureMap *feature_map_; | |
| 68 // Array of bools indicating presence of a feature. | |
| 69 bool *features_; | |
| 70 // Array indicating the presence of a feature offset by one unit. | |
| 71 bool *features_delta_one_; | |
| 72 // Array indicating the presence of a feature offset by two units. | |
| 73 bool *features_delta_two_; | |
| 74 }; | |
| 75 | |
| 76 } // namespace tesseract | |
| 77 | |
| 78 #endif // TESSERACT_CLASSIFY_INTFEATUREDIST_H_ |
