18
18
//
19
19
// /////////////////////////////////////////////////////////////////////
20
20
21
+ #include " lstmrecognizer.h"
21
22
#include " tessdatamanager.h"
22
23
23
24
// Main program to combine/extract/overwrite tessdata components
@@ -122,6 +123,31 @@ int main(int argc, char **argv) {
122
123
123
124
// Write the updated traineddata file.
124
125
tm .OverwriteComponents (new_traineddata_filename, argv+3 , argc-3 );
126
+ } else if (argc == 3 && strcmp (argv[1 ], " -c" ) == 0 ) {
127
+ tm .Init (argv[2 ]);
128
+ tesseract::TFile fp;
129
+ if (!tm .GetComponent (tesseract::TESSDATA_LSTM, &fp)) {
130
+ tprintf (" No LSTM Component found in %s!\n " , argv[2 ]);
131
+ exit (1 );
132
+ }
133
+ tesseract::LSTMRecognizer recognizer;
134
+ if (!recognizer.DeSerialize (&tm , &fp)) {
135
+ tprintf (" Failed to deserialize LSTM in %s!\n " , argv[2 ]);
136
+ exit (1 );
137
+ }
138
+ recognizer.ConvertToInt ();
139
+ GenericVector<char > lstm_data;
140
+ fp.OpenWrite (&lstm_data);
141
+ ASSERT_HOST (recognizer.Serialize (&tm , &fp));
142
+ tm .OverwriteEntry (tesseract::TESSDATA_LSTM, &lstm_data[0 ],
143
+ lstm_data.size ());
144
+ if (!tm .SaveFile (argv[2 ], nullptr )) {
145
+ tprintf (" Failed to write modified traineddata:%s!\n " , argv[2 ]);
146
+ exit (1 );
147
+ }
148
+ } else if (argc == 3 && strcmp (argv[1 ], " -d" ) == 0 ) {
149
+ // Initialize TessdataManager with the data in the given traineddata file.
150
+ tm .Init (argv[2 ]);
125
151
} else {
126
152
printf (" Usage for combining tessdata components:\n "
127
153
" %s language_data_path_prefix\n "
@@ -137,6 +163,14 @@ int main(int argc, char **argv) {
137
163
printf (" Usage for unpacking all tessdata components:\n "
138
164
" %s -u traineddata_file output_path_prefix\n "
139
165
" (e.g. %s -u eng.traineddata tmp/eng.)\n " , argv[0 ], argv[0 ]);
166
+ printf (
167
+ " Usage for listing directory of components:\n "
168
+ " %s -d traineddata_file\n " ,
169
+ argv[0 ]);
170
+ printf (
171
+ " Usage for compacting LSTM component to int:\n "
172
+ " %s -c traineddata_file\n " ,
173
+ argv[0 ]);
140
174
return 1 ;
141
175
}
142
176
tm .Directory ();
0 commit comments