I am currently using tesseract to OCR some jpeg files to txt files (Ubuntu 16.04). Typically this is ~500 files in one directory.

I know I can do this by making a text file with all the file names (savedlist.txt), and then do:

tesseract savedlist.txt output.txt

however output.txt is a single file with all the ocr results.

What I need is to be able to save the ocr results to individual txt files with the same file name as the original image file. For example:

input file: image456.jpeg
output file: image456.txt

I realize that ABBYY FineReader more recent versions can do this, but this is for a gratis project so I am looking for a free or inexpensive (less than $20) solution.

What I am looking for a software front-end or GUI using tesseract that can batch process ocr like this, all in one batch operation.

A command line solution to do this would also be OK. If off-topic here, I can ask this on another site but I didn't want to post on two sites at the same time.

  • @Izzy In case there is a programming solution rather than a software one, would there be any problem to also post this question on another site? Any recommendation (SuperUser or another one)? – user3169 Nov 19 '18 at 19:00
  • If by programming you mean scripting, SU might fit. Programming normaly is located on SO. If you make sure the question is focused differently (so it's indeed a different question – e.g. here asking for existing software, there asking for scripting solutions), there shouldn't be a problem. – Izzy Nov 20 '18 at 0:05

In Bash:

for file in FILES ; do tesseract "$file" "${file%%.*}" ; done

where in place of FILES, you should write a series of file names like image456.jpeg image457.jpeg image458.jpeg, or a glob pattern like *.jpeg, or any such combination.

  • I see, but how to handle the extension change? Output files needs to have the .txt extension. FILES will be a list of file names. – user3169 Nov 23 '18 at 0:31
  • @user3169 Tesseract adds the extension ".txt" automatically, the last time I checked. If you say tesseract img.jpg foo.txt, then you actually get foo.txt.txt. Usually it's annoying, but here it's convenient. – Kodiologist Nov 23 '18 at 3:19
  • I tried this and it did the tesseract processing OK, but the results were still all in one text file (FILES.txt). Your example doesn't seem to change the fact that Tesseract only supports a single file output, unless I'm missing something. – user3169 Nov 23 '18 at 19:17
  • @user3169 I think you may have misunderstood my example. The literal characters FILES shouldn't appear in your command. What command did you use, exactly? – Kodiologist Nov 23 '18 at 20:42
  • No, I just named my list "FILES" to follow you example. My command: for file in FILES ; do tesseract "$file" "$file" ; done. I presume "$file" is the image file name pulled from FILE, since the ocr function was performed. But then where is the individual output text file? All I got was one FILE.txt with all the results. – user3169 Nov 23 '18 at 22:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.