Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/tesseract/src/training/shapeclustering.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 // Copyright 2011 Google Inc. All Rights Reserved. | |
| 2 // Author: rays@google.com (Ray Smith) | |
| 3 | |
| 4 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 // you may not use this file except in compliance with the License. | |
| 6 // You may obtain a copy of the License at | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // Unless required by applicable law or agreed to in writing, software | |
| 9 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 11 // See the License for the specific language governing permissions and | |
| 12 // limitations under the License. | |
| 13 | |
| 14 // Filename: shapeclustering.cpp | |
| 15 // Purpose: Generates a master shape table to merge similarly-shaped | |
| 16 // training data of whole, partial or multiple characters. | |
| 17 // Author: Ray Smith | |
| 18 | |
| 19 #ifdef HAVE_CONFIG_H | |
| 20 # include "config_auto.h" | |
| 21 #endif | |
| 22 | |
| 23 #include "commontraining.h" | |
| 24 #include "mastertrainer.h" | |
| 25 #include "params.h" | |
| 26 | |
| 27 using namespace tesseract; | |
| 28 | |
| 29 static INT_PARAM_FLAG(display_cloud_font, -1, "Display cloud of this font, canonical_class1"); | |
| 30 static INT_PARAM_FLAG(display_canonical_font, -1, | |
| 31 "Display canonical sample of this font, canonical_class2"); | |
| 32 static STRING_PARAM_FLAG(canonical_class1, "", "Class to show ambigs for"); | |
| 33 static STRING_PARAM_FLAG(canonical_class2, "", "Class to show ambigs for"); | |
| 34 | |
| 35 // Loads training data, if requested displays debug information, otherwise | |
| 36 // creates the master shape table by shape clustering and writes it to a file. | |
| 37 // If FLAGS_display_cloud_font is set, then the cloud features of | |
| 38 // FLAGS_canonical_class1/FLAGS_display_cloud_font are shown in green ON TOP | |
| 39 // OF the red canonical features of FLAGS_canonical_class2/ | |
| 40 // FLAGS_display_canonical_font, so as to show which canonical features are | |
| 41 // NOT in the cloud. | |
| 42 // Otherwise, if FLAGS_canonical_class1 is set, prints a table of font-wise | |
| 43 // cluster distances between FLAGS_canonical_class1 and FLAGS_canonical_class2. | |
| 44 int main(int argc, char **argv) { | |
| 45 tesseract::CheckSharedLibraryVersion(); | |
| 46 | |
| 47 ParseArguments(&argc, &argv); | |
| 48 | |
| 49 std::string file_prefix; | |
| 50 auto trainer = tesseract::LoadTrainingData(argv + 1, false, nullptr, file_prefix); | |
| 51 | |
| 52 if (!trainer) { | |
| 53 return EXIT_FAILURE; | |
| 54 } | |
| 55 | |
| 56 if (FLAGS_display_cloud_font >= 0) { | |
| 57 #ifndef GRAPHICS_DISABLED | |
| 58 trainer->DisplaySamples(FLAGS_canonical_class1.c_str(), FLAGS_display_cloud_font, | |
| 59 FLAGS_canonical_class2.c_str(), FLAGS_display_canonical_font); | |
| 60 #endif // !GRAPHICS_DISABLED | |
| 61 return EXIT_SUCCESS; | |
| 62 } else if (!FLAGS_canonical_class1.empty()) { | |
| 63 trainer->DebugCanonical(FLAGS_canonical_class1.c_str(), FLAGS_canonical_class2.c_str()); | |
| 64 return EXIT_SUCCESS; | |
| 65 } | |
| 66 trainer->SetupMasterShapes(); | |
| 67 WriteShapeTable(file_prefix, trainer->master_shapes()); | |
| 68 | |
| 69 return EXIT_SUCCESS; | |
| 70 } /* main */ |
