tesseract 4.1.1
Loading...
Searching...
No Matches
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#ifdef GOOGLE_TESSERACT
24#include "base/commandlineflags.h"
25#endif
26#include "commontraining.h"
27#include "mastertrainer.h"
28#include "params.h"
29#include "strngs.h"
30
31static INT_PARAM_FLAG(display_cloud_font, -1,
32 "Display cloud of this font, canonical_class1");
33static INT_PARAM_FLAG(display_canonical_font, -1,
34 "Display canonical sample of this font, canonical_class2");
35static STRING_PARAM_FLAG(canonical_class1, "", "Class to show ambigs for");
36static 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.
47int main(int argc, char **argv) {
48 tesseract::CheckSharedLibraryVersion();
49
50 ParseArguments(&argc, &argv);
51
52 STRING file_prefix;
54 tesseract::LoadTrainingData(argc, argv, false, nullptr, &file_prefix);
55
56 if (!trainer)
57 return 1;
58
59 if (FLAGS_display_cloud_font >= 0) {
60#ifndef GRAPHICS_DISABLED
61 trainer->DisplaySamples(FLAGS_canonical_class1.c_str(),
62 FLAGS_display_cloud_font,
63 FLAGS_canonical_class2.c_str(),
64 FLAGS_display_canonical_font);
65#endif // GRAPHICS_DISABLED
66 return 0;
67 } else if (!FLAGS_canonical_class1.empty()) {
68 trainer->DebugCanonical(FLAGS_canonical_class1.c_str(),
69 FLAGS_canonical_class2.c_str());
70 return 0;
71 }
72 trainer->SetupMasterShapes();
73 WriteShapeTable(file_prefix, trainer->master_shapes());
74 delete trainer;
75
76 return 0;
77} /* main */
#define INT_PARAM_FLAG(name, val, comment)
#define STRING_PARAM_FLAG(name, val, comment)
void ParseArguments(int *argc, char ***argv)
int main(int argc, char **argv)
MasterTrainer * LoadTrainingData(int argc, const char *const *argv, bool replication, ShapeTable **shape_table, STRING *file_prefix)
Definition: strngs.h:45
void DisplaySamples(const char *unichar_str1, int cloud_font, const char *unichar_str2, int canonical_font)
void DebugCanonical(const char *unichar_str1, const char *unichar_str2)
const ShapeTable & master_shapes() const