tesseract  5.0.0
shapeclustering.cpp
Go to the documentation of this file.
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 1;
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 0;
62  } else if (!FLAGS_canonical_class1.empty()) {
63  trainer->DebugCanonical(FLAGS_canonical_class1.c_str(), FLAGS_canonical_class2.c_str());
64  return 0;
65  }
66  trainer->SetupMasterShapes();
67  WriteShapeTable(file_prefix, trainer->master_shapes());
68 
69  return 0;
70 } /* main */
#define STRING_PARAM_FLAG(name, val, comment)
int main(int argc, char **argv)
void WriteShapeTable(const std::string &file_prefix, const ShapeTable &shape_table)
void ParseArguments(int *argc, char ***argv)
INT_PARAM_FLAG(debug_level, 0, "Level of Trainer debugging")
std::unique_ptr< MasterTrainer > LoadTrainingData(const char *const *filelist, bool replication, ShapeTable **shape_table, std::string &file_prefix)