21 #if (defined _MSC_VER && defined USE_VLD)
28 #include "config_auto.h"
33 #define _(x) gettext(x)
38 #include "allheaders.h"
50 int main(
int argc,
char **argv) {
52 setlocale (LC_ALL,
"");
53 bindtextdomain (PACKAGE, LOCALEDIR);
56 if ((argc == 2 && strcmp(argv[1],
"-v") == 0) ||
57 (argc == 2 && strcmp(argv[1],
"--version") == 0)) {
62 versionStrP = getLeptonicaVersion();
63 fprintf(stderr,
" %s\n", versionStrP);
64 lept_free(versionStrP);
66 versionStrP = getImagelibVersions();
67 fprintf(stderr,
" %s\n", versionStrP);
68 lept_free(versionStrP);
78 fprintf(stderr,
_(
"Could not initialize tesseract.\n"));
82 if (argc == 2 && strcmp(argv[1],
"--list-langs") == 0) {
85 fprintf(stderr,
_(
"List of available languages (%d):\n"), languages.
size());
86 for (
int index = 0; index < languages.
size(); ++index) {
87 STRING&
string = languages[index];
88 fprintf(stderr,
"%s\n",
string.
string());
96 const char*
lang =
"eng";
97 const char* image =
NULL;
98 const char* output =
NULL;
101 while (arg < argc && (output ==
NULL || argv[arg][0] ==
'-')) {
102 if (strcmp(argv[arg],
"-l") == 0 && arg + 1 < argc) {
103 lang = argv[arg + 1];
105 }
else if (strcmp(argv[arg],
"-psm") == 0 && arg + 1 < argc) {
108 }
else if (image ==
NULL) {
110 }
else if (output ==
NULL) {
115 if (output ==
NULL) {
116 fprintf(stderr,
_(
"Usage:%s imagename outputbase [-l lang] "
117 "[-psm pagesegmode] [configfile...]\n\n"), argv[0]);
119 _(
"pagesegmode values are:\n"
120 "0 = Orientation and script detection (OSD) only.\n"
121 "1 = Automatic page segmentation with OSD.\n"
122 "2 = Automatic page segmentation, but no OSD, or OCR\n"
123 "3 = Fully automatic page segmentation, but no OSD. (Default)\n"
124 "4 = Assume a single column of text of variable sizes.\n"
125 "5 = Assume a single uniform block of vertically aligned text.\n"
126 "6 = Assume a single uniform block of text.\n"
127 "7 = Treat the image as a single text line.\n"
128 "8 = Treat the image as a single word.\n"
129 "9 = Treat the image as a single word in a circle.\n"
130 "10 = Treat the image as a single character.\n"));
131 fprintf(stderr,
_(
"-l lang and/or -psm pagesegmode must occur before any"
133 fprintf(stderr,
_(
"Single options:\n"));
134 fprintf(stderr,
_(
" -v --version: version info\n"));
135 fprintf(stderr,
_(
" --list-langs: list available languages for tesseract "
144 &(argv[arg]), argc - arg,
NULL,
NULL,
false);
146 fprintf(stderr,
_(
"Could not initialize tesseract.\n"));
164 tprintf(
"Tesseract Open Source OCR Engine v%s with Leptonica\n",
168 FILE* fin = fopen(image,
"rb");
170 fprintf(stderr,
_(
"Cannot open input file: %s\n"), image);
176 if ((pixs = pixRead(image)) ==
NULL) {
177 fprintf(stderr,
_(
"Unsupported image type.\n"));
184 fprintf(stderr,
_(
"Error during processing.\n"));
186 bool output_hocr =
false;
188 bool output_box =
false;
191 outfile += output_hocr ?
".html" : output_box ?
".box" :
".txt";
192 FILE* fout = fopen(outfile.
string(),
"wb");
194 fprintf(stderr,
_(
"Cannot create output file %s\n"), outfile.
string());
205 char szAppName[] =
"Tesseract";
216 HINSTANCE hPrevInstance,
228 wc.style = CS_NOCLOSE | CS_OWNDC;
229 wc.lpfnWndProc = (WNDPROC) WndProc;
232 wc.hInstance = hInstance;
235 wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
236 wc.lpszMenuName =
NULL;
237 wc.lpszClassName = szAppName;
241 hwnd = CreateWindow (szAppName, szAppName,
242 WS_OVERLAPPEDWINDOW | WS_DISABLED,
243 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
244 CW_USEDEFAULT, HWND_DESKTOP,
NULL, hInstance,
NULL);
246 argsin[0] = strdup (szAppName);
247 argsin[1] = strdup (lpszCmdLine);
250 argv = (
char **)malloc(((strlen(argsin[0]) + strlen(argsin[1])) / 2 + 1) *
254 argc = parse_args (2, argsin, argv);
260 exit_code =
main (argc, argv);
266 while (GetMessage (&msg,
NULL, 0, 0)) {
267 TranslateMessage(&msg);
268 DispatchMessage(&msg);
270 exit_code =
main (argc, argv);
274 exit_code = msg.wParam;
296 if (msg == WM_CREATE) {
301 ReleaseDC(hwnd, hdc);
305 return DefWindowProc (hwnd, msg, wParam, lParam);
327 for (arg = 0; arg < argc; arg++) {
328 testchar = argv[arg];
331 && (*testchar ==
' ' || *testchar ==
'\n'
332 || *testchar ==
'\t'))
336 arglist[argcount++] = testchar;
338 for (testchar++; *testchar && *testchar !=
' ' && *testchar !=
'\n' && *testchar !=
'\t'; testchar++) ;