Skip to content

Commit

Permalink
tesseract app: check if input file exists; fixes #1023
Browse files Browse the repository at this point in the history
  • Loading branch information
zdenop committed Sep 29, 2018
1 parent abe40f1 commit 1a09644
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/api/tesseractmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,19 +530,27 @@ int main(int argc, char** argv) {
return EXIT_SUCCESS;
}

if (FILE* file = fopen(image, "r")) {
fclose(file);
} else {
fprintf(stderr, "Cannot open input file: %s\n", image);
return EXIT_FAILURE;
}

FixPageSegMode(&api, pagesegmode);

if (dpi) {
char dpi_string[255];
snprintf(dpi_string, 254, "%d", dpi);
api.SetVariable("user_defined_dpi", dpi_string);
}

if (pagesegmode == tesseract::PSM_AUTO_ONLY) {
int ret_val = EXIT_SUCCESS;

Pix* pixs = pixRead(image);
if (!pixs) {
fprintf(stderr, "Cannot open input file: %s\n", image);
fprintf(stderr, "Leptonica can process input file: %s\n", image);
return 2;
}

Expand Down

0 comments on commit 1a09644

Please sign in to comment.