{
#ifdef USING_GETTEXT
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
#endif
if ((argc == 2 && strcmp(argv[1], "-v") == 0) ||
(argc == 2 && strcmp(argv[1], "--version") == 0)) {
char *versionStrP;
versionStrP = getLeptonicaVersion();
fprintf(stderr, " %s\n", versionStrP);
lept_free(versionStrP);
versionStrP = getImagelibVersions();
fprintf(stderr, " %s\n", versionStrP);
lept_free(versionStrP);
exit(0);
}
if (rc) {
fprintf(stderr,
_(
"Could not initialize tesseract.\n"));
exit(1);
}
if (argc == 2 && strcmp(argv[1], "--list-langs") == 0) {
fprintf(stderr,
_(
"List of available languages (%d):\n"), languages.
size());
for (
int index = 0; index < languages.
size(); ++index) {
STRING&
string = languages[index];
fprintf(stderr, "%s\n", string.string());
}
exit(0);
}
const char*
lang =
"eng";
const char* image =
NULL;
const char* output =
NULL;
int arg = 1;
while (arg < argc && (output ==
NULL || argv[arg][0] ==
'-')) {
if (strcmp(argv[arg], "-l") == 0 && arg + 1 < argc) {
lang = argv[arg + 1];
++arg;
} else if (strcmp(argv[arg], "-psm") == 0 && arg + 1 < argc) {
++arg;
}
else if (image ==
NULL) {
image = argv[arg];
}
else if (output ==
NULL) {
output = argv[arg];
}
++arg;
}
fprintf(stderr,
_(
"Usage:%s imagename outputbase [-l lang] "
"[-psm pagesegmode] [configfile...]\n\n"), argv[0]);
fprintf(stderr,
_(
"pagesegmode values are:\n"
"0 = Orientation and script detection (OSD) only.\n"
"1 = Automatic page segmentation with OSD.\n"
"2 = Automatic page segmentation, but no OSD, or OCR\n"
"3 = Fully automatic page segmentation, but no OSD. (Default)\n"
"4 = Assume a single column of text of variable sizes.\n"
"5 = Assume a single uniform block of vertically aligned text.\n"
"6 = Assume a single uniform block of text.\n"
"7 = Treat the image as a single text line.\n"
"8 = Treat the image as a single word.\n"
"9 = Treat the image as a single word in a circle.\n"
"10 = Treat the image as a single character.\n"));
fprintf(stderr,
_(
"-l lang and/or -psm pagesegmode must occur before any"
"configfile.\n\n"));
fprintf(stderr,
_(
"Single options:\n"));
fprintf(stderr,
_(
" -v --version: version info\n"));
fprintf(stderr,
_(
" --list-langs: list available languages for tesseract "
"engine\n"));
exit(1);
}
&(argv[arg]), argc - arg,
NULL,
NULL,
false);
if (rc) {
fprintf(stderr,
_(
"Could not initialize tesseract.\n"));
exit(1);
}
tprintf(
"Tesseract Open Source OCR Engine v%s with Leptonica\n",
FILE* fin = fopen(image, "rb");
fprintf(stderr,
_(
"Cannot open input file: %s\n"), image);
exit(2);
}
fclose(fin);
if ((pixs = pixRead(image)) ==
NULL) {
fprintf(stderr,
_(
"Unsupported image type.\n"));
exit(3);
}
pixDestroy(&pixs);
fprintf(stderr,
_(
"Error during processing.\n"));
}
bool output_hocr = false;
bool output_box = false;
outfile += output_hocr ? ".html" : output_box ? ".box" : ".txt";
FILE* fout = fopen(outfile.
string(),
"wb");
fprintf(stderr,
_(
"Cannot create output file %s\n"), outfile.
string());
exit(1);
}
fclose(fout);
return 0;
}