22 #include "config_auto.h"
27 #include "allheaders.h"
41 int main(
int argc,
char **argv) {
42 if ((argc == 2 && strcmp(argv[1],
"-v") == 0) ||
43 (argc == 2 && strcmp(argv[1],
"--version") == 0)) {
48 versionStrP = getLeptonicaVersion();
49 fprintf(stderr,
" %s\n", versionStrP);
50 lept_free(versionStrP);
52 versionStrP = getImagelibVersions();
53 fprintf(stderr,
" %s\n", versionStrP);
54 lept_free(versionStrP);
57 cl_platform_id platform;
58 cl_uint num_platforms;
59 cl_device_id devices[2];
64 fprintf(stderr,
" OpenCL info:\n");
65 clGetPlatformIDs(1, &platform, &num_platforms);
66 fprintf(stderr,
" Found %d platforms.\n", num_platforms);
67 clGetPlatformInfo(platform, CL_PLATFORM_NAME, 256, info, 0);
68 fprintf(stderr,
" Platform name: %s.\n", info);
69 clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 256, info, 0);
70 fprintf(stderr,
" Version: %s.\n", info);
71 clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 2, devices, &num_devices);
72 fprintf(stderr,
" Found %d devices.\n", num_devices);
73 for (i = 0; i < num_devices; ++i) {
74 clGetDeviceInfo(devices[i], CL_DEVICE_NAME, 256, info, 0);
75 fprintf(stderr,
" Device %d name: %s.\n", i+1, info);
82 const char*
lang =
"eng";
83 const char* image =
NULL;
84 const char* outputbase =
NULL;
85 const char* datapath =
NULL;
87 bool list_langs =
false;
88 bool print_parameters =
false;
93 while (arg < argc && (outputbase ==
NULL || argv[arg][0] ==
'-')) {
94 if (strcmp(argv[arg],
"-l") == 0 && arg + 1 < argc) {
97 }
else if (strcmp(argv[arg],
"--tessdata-dir") == 0 && arg + 1 < argc) {
98 datapath = argv[arg + 1];
100 }
else if (strcmp(argv[arg],
"--user-words") == 0 && arg + 1 < argc) {
104 }
else if (strcmp(argv[arg],
"--user-patterns") == 0 && arg + 1 < argc) {
105 vars_vec.
push_back(
"user_patterns_file");
108 }
else if (strcmp(argv[arg],
"--list-langs") == 0) {
111 }
else if (strcmp(argv[arg],
"-psm") == 0 && arg + 1 < argc) {
114 }
else if (strcmp(argv[arg],
"--print-parameters") == 0) {
116 print_parameters =
true;
117 }
else if (strcmp(argv[arg],
"-c") == 0 && arg + 1 < argc) {
120 }
else if (image ==
NULL) {
122 }
else if (outputbase ==
NULL) {
123 outputbase = argv[arg];
128 if (argc == 2 && strcmp(argv[1],
"--list-langs") == 0) {
133 if (outputbase ==
NULL && noocr ==
false) {
134 fprintf(stderr,
"Usage:\n %s imagename|stdin outputbase|stdout "
135 "[options...] [configfile...]\n\n", argv[0]);
137 fprintf(stderr,
"OCR options:\n");
138 fprintf(stderr,
" --tessdata-dir /path\tspecify the location of tessdata"
140 fprintf(stderr,
" --user-words /path/to/file\tspecify the location of user"
142 fprintf(stderr,
" --user-patterns /path/to/file\tspecify the location of"
143 " user patterns file\n");
144 fprintf(stderr,
" -l lang[+lang]\tspecify language(s) used for OCR\n");
145 fprintf(stderr,
" -c configvar=value\tset value for control parameter.\n"
146 "\t\t\tMultiple -c arguments are allowed.\n");
147 fprintf(stderr,
" -psm pagesegmode\tspecify page segmentation mode.\n");
148 fprintf(stderr,
"These options must occur before any configfile.\n\n");
150 "pagesegmode values are:\n"
151 " 0 = Orientation and script detection (OSD) only.\n"
152 " 1 = Automatic page segmentation with OSD.\n"
153 " 2 = Automatic page segmentation, but no OSD, or OCR\n"
154 " 3 = Fully automatic page segmentation, but no OSD. (Default)\n"
155 " 4 = Assume a single column of text of variable sizes.\n"
156 " 5 = Assume a single uniform block of vertically aligned text.\n"
157 " 6 = Assume a single uniform block of text.\n"
158 " 7 = Treat the image as a single text line.\n"
159 " 8 = Treat the image as a single word.\n"
160 " 9 = Treat the image as a single word in a circle.\n"
161 " 10 = Treat the image as a single character.\n\n");
162 fprintf(stderr,
"Single options:\n");
163 fprintf(stderr,
" -v --version: version info\n");
164 fprintf(stderr,
" --list-langs: list available languages for tesseract "
165 "engine. Can be used with --tessdata-dir.\n");
166 fprintf(stderr,
" --print-parameters: print tesseract parameters to the "
171 if (outputbase !=
NULL && strcmp(outputbase,
"-") &&
172 strcmp(outputbase,
"stdout")) {
173 tprintf(
"Tesseract Open Source OCR Engine v%s with Leptonica\n",
181 &(argv[arg]), argc - arg, &vars_vec, &vars_values,
false);
184 fprintf(stderr,
"Could not initialize tesseract.\n");
188 char opt1[255], opt2[255];
189 for (arg = 0; arg < argc; arg++) {
190 if (strcmp(argv[arg],
"-c") == 0 && arg + 1 < argc) {
191 strncpy(opt1, argv[arg + 1], 255);
192 char *p = strchr(opt1,
'=');
194 fprintf(stderr,
"Missing = in configvar assignment\n");
198 strncpy(opt2, strchr(argv[arg + 1],
'=') + 1, 255);
203 fprintf(stderr,
"Could not set option: %s=%s\n", opt1, opt2);
211 fprintf(stderr,
"List of available languages (%d):\n",
213 for (
int index = 0; index < languages.
size(); ++index) {
214 STRING&
string = languages[index];
215 fprintf(stderr,
"%s\n",
string.
string());
221 if (print_parameters) {
223 fprintf(stdout,
"Tesseract parameters:\n");
248 Pix* pixs = pixRead(image);
250 fprintf(stderr,
"Cannot open input file: %s\n", image);
262 tprintf(
"Orientation: %d\nOrientation in degrees: %d\n" \
263 "Orientation confidence: %.2f\n" \
264 "Script: %d\nScript confidence: %.2f\n",
266 script_id, orient_sco);
277 it->
Orientation(&orientation, &direction, &order, &deskew_angle);
278 tprintf(
"Orientation: %d\nWritingDirection: %d\nTextlineOrder: %d\n" \
279 "Deskew angle: %.4f\n",
280 orientation, direction, order, deskew_angle);
309 if (!renderers.
empty()) {
312 for (
int r = 1; r < renderers.
size(); ++r) {
313 renderers[0]->
insert(renderers[r]);
317 fprintf(stderr,
"Error during processing.\n");
static const char * Version()
bool DetectOS(OSResults *)
void GetAvailableLanguagesAsVector(GenericVector< STRING > *langs) const
PageIterator * AnalyseLayout()
int direction(EDGEPT *point)
bool SetVariable(const char *name, const char *value)
const char * GetDatapath()
PageSegMode GetPageSegMode() const
bool GetBoolVariable(const char *name, bool *value) const
void insert(T *t, int index)
Orientation and script detection only.
const int OrientationIdToValue(const int &id)
Automatic page segmentation, but no OSD, or OCR.
bool ProcessPages(const char *filename, const char *retry_config, int timeout_millisec, TessResultRenderer *renderer)
#define PERF_COUNT_START(FUNCT_NAME)
int Init(const char *datapath, const char *language, OcrEngineMode mode, char **configs, int configs_size, const GenericVector< STRING > *vars_vec, const GenericVector< STRING > *vars_values, bool set_only_non_debug_params)
Assume a single uniform block of text. (Default.)
void SetOutputName(const char *name)
TESS_API int get_best_script(int orientation_id) const
Fully automatic page segmentation, but no OSD.
void Orientation(tesseract::Orientation *orientation, tesseract::WritingDirection *writing_direction, tesseract::TextlineOrder *textline_order, float *deskew_angle) const
void PrintVariables(FILE *fp) const
void SetPageSegMode(PageSegMode mode)
void SetImage(const unsigned char *imagedata, int width, int height, int bytes_per_pixel, int bytes_per_line)
int main(int argc, char **argv)