50

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.

3

4 Answers 4

48

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

sudo apt install tesseract-ocr

and can be used with

tesseract input.png out.txt
0
24

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
5
  • 4
    fwiw, this uses the below mentioned Tesseract.
    – exic
    Commented Mar 13, 2018 at 7:06
  • 1
    ocrmypdf made my day
    – oh really
    Commented Jan 27, 2019 at 8:22
  • the idea of having to convert to pdf first is just goofy. why can't i just input a jpg file and get some raw text out?
    – Michael
    Commented Mar 24, 2019 at 17:03
  • You can use a bash file to do all the command lines for you.
    – projetmbc
    Commented Jul 13, 2019 at 9:20
  • Convert doesn't work any more. They turned off that option in its policy file and that's buried in a container - at least in Ubuntu. img2pdf will do it now.
    – Joe
    Commented Jan 30, 2022 at 14:01
17

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.

1
  • 1
    This is what worked for me with a very small piece of non-english text with tiny font size. Amazing.
    – Avio
    Commented Dec 13, 2018 at 14:47
-1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .