tesseract 4.1.1
Loading...
Searching...
No Matches
merge_unicharsets.cpp
Go to the documentation of this file.
1
2// File: merge_unicharsets.cpp
3// Description: Simple tool to merge two or more unicharsets.
4// Author: Ray Smith
5// Created: Wed Sep 30 16:09:01 PDT 2015
6//
7// (C) Copyright 2015, Google Inc.
8// Licensed under the Apache License, Version 2.0 (the "License");
9// you may not use this file except in compliance with the License.
10// You may obtain a copy of the License at
11// http://www.apache.org/licenses/LICENSE-2.0
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17//
19
20#include "commontraining.h" // CheckSharedLibraryVersion
21#include "unicharset.h"
22
23int main(int argc, char** argv) {
24 tesseract::CheckSharedLibraryVersion();
25
26 if (argc > 1 && (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version"))) {
27 printf("%s\n", tesseract::TessBaseAPI::Version());
28 return 0;
29 } else if (argc < 4) {
30 // Print usage
31 printf("Usage: %s -v | --version |\n"
32 " %s unicharset-in-1 ... unicharset-in-n unicharset-out\n",
33 argv[0], argv[0]);
34 return 1;
35 }
36
37 UNICHARSET input_unicharset, result_unicharset;
38 for (int arg = 1; arg < argc - 1; ++arg) {
39 // Load the input unicharset
40 if (input_unicharset.load_from_file(argv[arg])) {
41 printf("Loaded unicharset of size %d from file %s\n",
42 input_unicharset.size(), argv[arg]);
43 result_unicharset.AppendOtherUnicharset(input_unicharset);
44 } else {
45 printf("Failed to load unicharset from file %s!!\n", argv[arg]);
46 exit(1);
47 }
48 }
49
50 // Save the combined unicharset.
51 if (result_unicharset.save_to_file(argv[argc - 1])) {
52 printf("Wrote unicharset file %s.\n", argv[argc - 1]);
53 } else {
54 printf("Cannot save unicharset file %s.\n", argv[argc - 1]);
55 exit(1);
56 }
57 return 0;
58}
int main(int argc, char **argv)
bool save_to_file(const char *const filename) const
Definition: unicharset.h:350
void AppendOtherUnicharset(const UNICHARSET &src)
Definition: unicharset.cpp:464
int size() const
Definition: unicharset.h:341
bool load_from_file(const char *const filename, bool skip_fragments)
Definition: unicharset.h:388