Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/tesseract/src/classify/mf.cpp @ 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: mf.c | |
| 3 ** Purpose: Micro-feature interface to flexible feature extractor. | |
| 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 Include Files and Type Defines | |
| 19 ----------------------------------------------------------------------------*/ | |
| 20 #include "mf.h" | |
| 21 | |
| 22 #include "featdefs.h" | |
| 23 #include "mfdefs.h" | |
| 24 #include "mfx.h" | |
| 25 | |
| 26 #include <cmath> | |
| 27 | |
| 28 namespace tesseract { | |
| 29 | |
| 30 /*---------------------------------------------------------------------------- | |
| 31 Private Code | |
| 32 ----------------------------------------------------------------------------*/ | |
| 33 /** | |
| 34 * Call the old micro-feature extractor and then copy | |
| 35 * the features into the new format. Then deallocate the | |
| 36 * old micro-features. | |
| 37 * @param Blob blob to extract micro-features from | |
| 38 * @param cn_denorm control parameter to feature extractor. | |
| 39 * @return Micro-features for Blob. | |
| 40 */ | |
| 41 FEATURE_SET ExtractMicros(TBLOB *Blob, const DENORM &cn_denorm) { | |
| 42 auto features = BlobMicroFeatures(Blob, cn_denorm); | |
| 43 if (features.empty()) { | |
| 44 return nullptr; | |
| 45 } | |
| 46 int n = 0; | |
| 47 for ([[maybe_unused]] auto &f: features) { | |
| 48 ++n; | |
| 49 } | |
| 50 auto FeatureSet = new FEATURE_SET_STRUCT(n); | |
| 51 | |
| 52 for (auto &f : features) { | |
| 53 auto Feature = new FEATURE_STRUCT(&MicroFeatureDesc); | |
| 54 for (int i = 0; i < (int)MicroFeatureParameter::MFCount; ++i) | |
| 55 Feature->Params[i] = f[i]; | |
| 56 // Bulge features are deprecated and should not be used. Set to 0. | |
| 57 Feature->Params[(int)MicroFeatureParameter::MFBulge1] = 0.0f; | |
| 58 Feature->Params[(int)MicroFeatureParameter::MFBulge2] = 0.0f; | |
| 59 | |
| 60 #ifndef _WIN32 | |
| 61 // Assert that feature parameters are well defined. | |
| 62 for (int i = 0; i < Feature->Type->NumParams; i++) { | |
| 63 ASSERT_HOST(!std::isnan(Feature->Params[i])); | |
| 64 } | |
| 65 #endif | |
| 66 | |
| 67 AddFeature(FeatureSet, Feature); | |
| 68 } | |
| 69 return FeatureSet; | |
| 70 } /* ExtractMicros */ | |
| 71 | |
| 72 } // namespace tesseract |
