Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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