I have several thousand pages of scanned book pages. Each page is saved individually as a JPG. The writing is clear, but fonts vary, and the pages do include pictures and illustrations.

I need to create a list of all of the words appearing in each JPG file. Is there a command line tool for scanning an image listing the words that appear? It does not need to have perfect scanning, just an estimate.

Install imagemagick, pdftotext (found in a package named poppler-utils within some package managers) and ocrmypdf. The latter is a fast (ocr takes a lot of cpu, and it is configured to use all your cores), open-source and frequently updated piece of OCR software. This approach is possibly overkill as it actually tries to assign a string to each word instead of just labeling a word, but I've had a lot of trouble finding good and easy to use opensource OCR software in general. Then, in the directory where you have saved all your JPGs:

$ convert *.jpg pictures.pdf
$ ocrmypdf pictures.pdf scanned.pdf
$ pdftotext scanned.pdf scanned.txt
$ wc -w scanned.txt
  • 1
    fwiw, this uses the below mentioned Tesseract. – exic Mar 13 at 7:06

tesseract is probably the most-used solution here. It's available in most package repositories, e.g.,

apt install tesseract-ocr

and can be used with

tesseract input.png out.txt

Upscale image file.png by 480%, change to greyscale, backfill with white, sharpen and then extract using tesseract OCR. It works well most of the time for me, except for very large fonts, and white on black. If fonts are very large only upscale 200% or 300%.

 convert -colorspace gray -fill white  -resize 480%  -sharpen 0x1  file.png file.jpg
 tesseract file.jpg file

The result is in file.txt.

For linux users, nothing works as well as using Calibre to convert pdf to docx. https://calibre-ebook.com/download_linux

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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