tesseract v5.3.3.20231005
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//
6// (C) Copyright 2015, Google Inc.
7// Licensed under the Apache License, Version 2.0 (the "License");
8// you may not use this file except in compliance with the License.
9// You may obtain a copy of the License at
10// http://www.apache.org/licenses/LICENSE-2.0
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
18
19#include "commontraining.h" // CheckSharedLibraryVersion
20#include "unicharset.h"
21
22int main(int argc, char **argv) {
23 tesseract::CheckSharedLibraryVersion();
24
25 if (argc > 1 && (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version"))) {
26 printf("%s\n", tesseract::TessBaseAPI::Version());
27 return EXIT_SUCCESS;
28 } else if (argc < 4) {
29 // Print usage
30 printf(
31 "Usage: %s -v | --version |\n"
32 " %s unicharset-in-1 ... unicharset-in-n unicharset-out\n",
33 argv[0], argv[0]);
34 return EXIT_FAILURE;
35 }
36
37 tesseract::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 %zu from file %s\n", input_unicharset.size(), argv[arg]);
42 result_unicharset.AppendOtherUnicharset(input_unicharset);
43 } else {
44 printf("Failed to load unicharset from file %s!!\n", argv[arg]);
45 return EXIT_FAILURE;
46 }
47 }
48
49 // Save the combined unicharset.
50 if (result_unicharset.save_to_file(argv[argc - 1])) {
51 printf("Wrote unicharset file %s.\n", argv[argc - 1]);
52 } else {
53 printf("Cannot save unicharset file %s.\n", argv[argc - 1]);
54 return EXIT_FAILURE;
55 }
56 return EXIT_SUCCESS;
57}
int main(int argc, char **argv)
static const char * Version()
Definition: baseapi.cpp:241
bool load_from_file(const char *const filename, bool skip_fragments)
Definition: unicharset.h:391
bool save_to_file(const char *const filename) const
Definition: unicharset.h:361
size_t size() const
Definition: unicharset.h:355
void AppendOtherUnicharset(const UNICHARSET &src)
Definition: unicharset.cpp:454