Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
combine_tessdata.cpp File Reference
#include "tessdatamanager.h"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Public Function Prototypes

Definition at line 66 of file combine_tessdata.cpp.

66  {
67  int i;
68  if (argc == 2) {
69  printf("Combining tessdata files\n");
70  STRING output_file = argv[1];
71  output_file += kTrainedDataSuffix;
73  argv[1], output_file.string())) {
74  char* last = &argv[1][strlen(argv[1])-1];
75  printf("Error combining tessdata files into %s\n",
76  output_file.string());
77  if (*last != '.')
78  printf("Hint: the prefix is missing a period (.)\n");
79  }
80  } else if (argc >= 4 && (strcmp(argv[1], "-e") == 0 ||
81  strcmp(argv[1], "-u") == 0)) {
82  // Initialize TessdataManager with the data in the given traineddata file.
84  tm.Init(argv[2], 0);
85  printf("Extracting tessdata components from %s\n", argv[2]);
86  if (strcmp(argv[1], "-e") == 0) {
87  for (i = 3; i < argc; ++i) {
88  if (tm.ExtractToFile(argv[i])) {
89  printf("Wrote %s\n", argv[i]);
90  } else {
91  printf("Not extracting %s, since this component"
92  " is not present\n", argv[i]);
93  }
94  }
95  } else { // extract all the components
96  for (i = 0; i < tesseract::TESSDATA_NUM_ENTRIES; ++i) {
97  STRING filename = argv[3];
98  filename += tesseract::kTessdataFileSuffixes[i];
99  if (tm.ExtractToFile(filename.string())) {
100  printf("Wrote %s\n", filename.string());
101  }
102  }
103  }
104  tm.End();
105  } else if (argc >= 4 && strcmp(argv[1], "-o") == 0) {
106  // Rename the current traineddata file to a temporary name.
107  const char *new_traineddata_filename = argv[2];
108  STRING traineddata_filename = new_traineddata_filename;
109  traineddata_filename += ".__tmp__";
110  if (rename(new_traineddata_filename, traineddata_filename.string()) != 0) {
111  tprintf("Failed to create a temporary file %s\n",
112  traineddata_filename.string());
113  exit(1);
114  }
115 
116  // Initialize TessdataManager with the data in the given traineddata file.
118  tm.Init(traineddata_filename.string(), 0);
119 
120  // Write the updated traineddata file.
121  tm.OverwriteComponents(new_traineddata_filename, argv+3, argc-3);
122  tm.End();
123  } else {
124  printf("Usage for combining tessdata components:\n"
125  "%s language_data_path_prefix (e.g. tessdata/eng.)\n", argv[0]);
126  printf("Usage for extracting tessdata components:\n"
127  "%s -e traineddata_file [output_component_file...]\n", argv[0]);
128  printf("Usage for overwriting tessdata components:\n"
129  "%s -o traineddata_file [input_component_file...]\n", argv[0]);
130  printf("Usage for unpacking all tessdata components:\n"
131  "%s -u traineddata_file output_path_prefix"
132  " (e.g. /tmp/eng.)\n", argv[0]);
133  return 1;
134  }
135 }
bool ExtractToFile(const char *filename)
bool Init(const char *data_file_name, int debug_level)
LIST last(LIST var_list)
Definition: oldlist.cpp:277
const char * string() const
Definition: strngs.cpp:156
bool OverwriteComponents(const char *new_traineddata_filename, char **component_filenames, int num_new_components)
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
Definition: strngs.h:40
static bool CombineDataFiles(const char *language_data_path_prefix, const char *output_filename)