68 int main(
int argc,
char **argv) {
69 tesseract::CheckSharedLibraryVersion();
73 if (argc > 1 && (!strcmp(argv[1],
"-v") || !strcmp(argv[1],
"--version"))) {
76 }
else if (argc == 2) {
77 printf(
"Combining tessdata files\n");
79 char*
last = &argv[1][strlen(argv[1])-1];
83 output_file += kTrainedDataSuffix;
85 printf(
"Error combining tessdata files into %s\n",
88 printf(
"Output %s created successfully.\n", output_file.
c_str());
90 }
else if (argc >= 4 && (strcmp(argv[1],
"-e") == 0 ||
91 strcmp(argv[1],
"-u") == 0)) {
93 if (!tm.
Init(argv[2])) {
94 tprintf(
"Failed to read %s\n", argv[2]);
97 printf(
"Extracting tessdata components from %s\n", argv[2]);
98 if (strcmp(argv[1],
"-e") == 0) {
99 for (i = 3; i < argc; ++i) {
102 printf(
"Wrote %s\n", argv[i]);
103 }
else if (errno == 0) {
104 printf(
"Not extracting %s, since this component"
105 " is not present\n", argv[i]);
108 printf(
"Error, could not extract %s: %s\n",
109 argv[i], strerror(errno));
115 STRING filename = argv[3];
116 char*
last = &argv[3][strlen(argv[3])-1];
119 filename += tesseract::kTessdataFileSuffixes[i];
122 printf(
"Wrote %s\n", filename.
c_str());
123 }
else if (errno != 0) {
124 printf(
"Error, could not extract %s: %s\n",
125 filename.
c_str(), strerror(errno));
130 }
else if (argc >= 4 && strcmp(argv[1],
"-o") == 0) {
132 const char *new_traineddata_filename = argv[2];
133 STRING traineddata_filename = new_traineddata_filename;
134 traineddata_filename +=
".__tmp__";
135 if (rename(new_traineddata_filename, traineddata_filename.
c_str()) != 0) {
136 tprintf(
"Failed to create a temporary file %s\n",
137 traineddata_filename.
c_str());
146 }
else if (argc == 3 && strcmp(argv[1],
"-c") == 0) {
147 if (!tm.
Init(argv[2])) {
148 tprintf(
"Failed to read %s\n", argv[2]);
153 tprintf(
"No LSTM Component found in %s!\n", argv[2]);
158 tprintf(
"Failed to deserialize LSTM in %s!\n", argv[2]);
167 if (!tm.
SaveFile(argv[2],
nullptr)) {
168 tprintf(
"Failed to write modified traineddata:%s!\n", argv[2]);
171 }
else if (argc == 3 && strcmp(argv[1],
"-d") == 0) {
175 printf(
"Usage for combining tessdata components:\n"
176 " %s language_data_path_prefix\n"
177 " (e.g. %s tessdata/eng.)\n\n", argv[0], argv[0]);
178 printf(
"Usage for extracting tessdata components:\n"
179 " %s -e traineddata_file [output_component_file...]\n"
180 " (e.g. %s -e eng.traineddata eng.unicharset)\n\n",
182 printf(
"Usage for overwriting tessdata components:\n"
183 " %s -o traineddata_file [input_component_file...]\n"
184 " (e.g. %s -o eng.traineddata eng.unicharset)\n\n",
186 printf(
"Usage for unpacking all tessdata components:\n"
187 " %s -u traineddata_file output_path_prefix\n"
188 " (e.g. %s -u eng.traineddata tmp/eng.)\n", argv[0], argv[0]);
190 "Usage for listing directory of components:\n"
191 " %s -d traineddata_file\n",
194 "Usage for compacting LSTM component to int:\n"
195 " %s -c traineddata_file\n",