69 int main(
int argc,
char **argv) {
70 tesseract::CheckSharedLibraryVersion();
74 if (argc > 1 && (!strcmp(argv[1],
"-v") || !strcmp(argv[1],
"--version"))) {
77 }
else if (argc == 2) {
78 printf(
"Combining tessdata files\n");
80 char*
last = &argv[1][strlen(argv[1])-1];
84 output_file += kTrainedDataSuffix;
86 printf(
"Error combining tessdata files into %s\n",
89 printf(
"Output %s created successfully.\n", output_file.
string());
91 }
else if (argc >= 4 && (strcmp(argv[1],
"-e") == 0 ||
92 strcmp(argv[1],
"-u") == 0)) {
94 if (!tm.
Init(argv[2])) {
95 tprintf(
"Failed to read %s\n", argv[2]);
98 printf(
"Extracting tessdata components from %s\n", argv[2]);
99 if (strcmp(argv[1],
"-e") == 0) {
100 for (i = 3; i < argc; ++i) {
103 printf(
"Wrote %s\n", argv[i]);
104 }
else if (errno == 0) {
105 printf(
"Not extracting %s, since this component" 106 " is not present\n", argv[i]);
109 printf(
"Error, could not extract %s: %s\n",
110 argv[i], strerror(errno));
116 STRING filename = argv[3];
117 char*
last = &argv[3][strlen(argv[3])-1];
120 filename += tesseract::kTessdataFileSuffixes[i];
123 printf(
"Wrote %s\n", filename.
string());
124 }
else if (errno != 0) {
125 printf(
"Error, could not extract %s: %s\n",
126 filename.
string(), strerror(errno));
131 }
else if (argc >= 4 && strcmp(argv[1],
"-o") == 0) {
133 const char *new_traineddata_filename = argv[2];
134 STRING traineddata_filename = new_traineddata_filename;
135 traineddata_filename +=
".__tmp__";
136 if (rename(new_traineddata_filename, traineddata_filename.
string()) != 0) {
137 tprintf(
"Failed to create a temporary file %s\n",
138 traineddata_filename.
string());
147 }
else if (argc == 3 && strcmp(argv[1],
"-c") == 0) {
148 if (!tm.
Init(argv[2])) {
149 tprintf(
"Failed to read %s\n", argv[2]);
154 tprintf(
"No LSTM Component found in %s!\n", argv[2]);
159 tprintf(
"Failed to deserialize LSTM in %s!\n", argv[2]);
168 if (!tm.
SaveFile(argv[2],
nullptr)) {
169 tprintf(
"Failed to write modified traineddata:%s!\n", argv[2]);
172 }
else if (argc == 3 && strcmp(argv[1],
"-d") == 0) {
176 printf(
"Usage for combining tessdata components:\n" 177 " %s language_data_path_prefix\n" 178 " (e.g. %s tessdata/eng.)\n\n", argv[0], argv[0]);
179 printf(
"Usage for extracting tessdata components:\n" 180 " %s -e traineddata_file [output_component_file...]\n" 181 " (e.g. %s -e eng.traineddata eng.unicharset)\n\n",
183 printf(
"Usage for overwriting tessdata components:\n" 184 " %s -o traineddata_file [input_component_file...]\n" 185 " (e.g. %s -o eng.traineddata eng.unicharset)\n\n",
187 printf(
"Usage for unpacking all tessdata components:\n" 188 " %s -u traineddata_file output_path_prefix\n" 189 " (e.g. %s -u eng.traineddata tmp/eng.)\n", argv[0], argv[0]);
191 "Usage for listing directory of components:\n" 192 " %s -d traineddata_file\n",
195 "Usage for compacting LSTM component to int:\n" 196 " %s -c traineddata_file\n",
bool CombineDataFiles(const char *language_data_path_prefix, const char *output_filename)
bool GetComponent(TessdataType type, TFile *fp)
void OpenWrite(GenericVector< char > *data)
void OverwriteEntry(TessdataType type, const char *data, int size)
const char * string() const
bool OverwriteComponents(const char *new_traineddata_filename, char **component_filenames, int num_new_components)
bool DeSerialize(const TessdataManager *mgr, TFile *fp)
bool Init(const char *data_file_name)
DLLSYM void tprintf(const char *format,...)
int main(int argc, char **argv)
static const char * Version()
bool SaveFile(const STRING &filename, FileWriter writer) const
bool Serialize(const TessdataManager *mgr, TFile *fp) const
bool ExtractToFile(const char *filename)