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.


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

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
  • 2
    fwiw, this uses the below mentioned Tesseract. – exic Mar 13 '18 at 7:06
  • ocrmypdf made my day – Everyday Astronaut Jan 27 '19 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 Mar 24 '19 at 17:03
  • You can use a bash file to do all the command lines for you. – projetmbc Jul 13 '19 at 9:20

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.

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

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



for i in /path_to/*.jpg;do ./myocr.sh $i $(basename $i .jpg);done

# PROGRAM=myocr.sh
if [ "$1" ] && [ -e "$1" ]; then
  TMPF=$(mktemp myocr.sh.XXXXXXXX.tif)
  if [ ! "$DEST" ]; then
    if [ -e "$DEST" ]; then
      echo "$DEST already exists; please provide a new textfile name" >&2
      exit 1
  /usr/bin/convert "$1" -colorspace Gray -depth 8 -resample 200x200 -flatten -alpha Off $TMPF \
  && /usr/bin/tesseract $TMPF "$DEST"
  /bin/rm -f $TMPF
  [ $EX -eq 0 ] && [ "$TERM" ] && echo "created $DEST"
  exit $EX
  echo "Usage: $0 imagefile [textfile]" >&2
  echo " creates a plain text file with the text found in imagefile" >&2
  exit 1

Source: https://help.ubuntu.com/community/OCR

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.