tesseract  4.00.00dev
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 #ifndef USE_STD_NAMESPACE
24 #include "base/commandlineflags.h"
25 #endif
26 #include "commontraining.h"
27 #include "mastertrainer.h"
28 #include "params.h"
29 #include "strngs.h"
30 
31 INT_PARAM_FLAG(display_cloud_font, -1,
32  "Display cloud of this font, canonical_class1");
33 INT_PARAM_FLAG(display_canonical_font, -1,
34  "Display canonical sample of this font, canonical_class2");
35 STRING_PARAM_FLAG(canonical_class1, "", "Class to show ambigs for");
36 STRING_PARAM_FLAG(canonical_class2, "", "Class to show ambigs for");
37 
38 // Loads training data, if requested displays debug information, otherwise
39 // creates the master shape table by shape clustering and writes it to a file.
40 // If FLAGS_display_cloud_font is set, then the cloud features of
41 // FLAGS_canonical_class1/FLAGS_display_cloud_font are shown in green ON TOP
42 // OF the red canonical features of FLAGS_canonical_class2/
43 // FLAGS_display_canonical_font, so as to show which canonical features are
44 // NOT in the cloud.
45 // Otherwise, if FLAGS_canonical_class1 is set, prints a table of font-wise
46 // cluster distances between FLAGS_canonical_class1 and FLAGS_canonical_class2.
47 int main(int argc, char **argv) {
48  ParseArguments(&argc, &argv);
49 
50  STRING file_prefix;
51  tesseract::MasterTrainer* trainer =
52  tesseract::LoadTrainingData(argc, argv, false, nullptr, &file_prefix);
53 
54  if (!trainer)
55  return 1;
56 
57  if (FLAGS_display_cloud_font >= 0) {
58 #ifndef GRAPHICS_DISABLED
59  trainer->DisplaySamples(FLAGS_canonical_class1.c_str(),
60  FLAGS_display_cloud_font,
61  FLAGS_canonical_class2.c_str(),
62  FLAGS_display_canonical_font);
63 #endif // GRAPHICS_DISABLED
64  return 0;
65  } else if (!FLAGS_canonical_class1.empty()) {
66  trainer->DebugCanonical(FLAGS_canonical_class1.c_str(),
67  FLAGS_canonical_class2.c_str());
68  return 0;
69  }
70  trainer->SetupMasterShapes();
71  WriteShapeTable(file_prefix, trainer->master_shapes());
72  delete trainer;
73 
74  return 0;
75 } /* main */
STRING_PARAM_FLAG(canonical_class1, "", "Class to show ambigs for")
void WriteShapeTable(const STRING &file_prefix, const ShapeTable &shape_table)
void ParseArguments(int *argc, char ***argv)
void DisplaySamples(const char *unichar_str1, int cloud_font, const char *unichar_str2, int canonical_font)
Definition: strngs.h:45
MasterTrainer * LoadTrainingData(int argc, const char *const *argv, bool replication, ShapeTable **shape_table, STRING *file_prefix)
int main(int argc, char **argv)
const ShapeTable & master_shapes() const
void DebugCanonical(const char *unichar_str1, const char *unichar_str2)
INT_PARAM_FLAG(display_cloud_font, -1, "Display cloud of this font, canonical_class1")