All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 
)

This program reads in a text file consisting of feature samples from a training page in the following format:

   FontName UTF8-char-str xmin ymin xmax ymax page-number
    NumberOfFeatureTypes(N)
      FeatureTypeName1 NumberOfFeatures(M)
         Feature1
         ...
         FeatureM
      FeatureTypeName2 NumberOfFeatures(M)
         Feature1
         ...
         FeatureM
      ...
      FeatureTypeNameN NumberOfFeatures(M)
         Feature1
         ...
         FeatureM
   FontName CharName ...

The result of this program is a binary inttemp file used by the OCR engine.

Parameters
argcnumber of command line arguments
argvarray of command line arguments
Returns
none
Note
Exceptions: none
History: Fri Aug 18 08:56:17 1989, DSJ, Created.
History: Mon May 18 1998, Christy Russson, Revistion started.

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