Skip to content

Instantly share code, notes, and snippets.

@ibeex
Forked from jtbonhomme/ocr.markdown
Created October 14, 2013 20:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ibeex/6981800 to your computer and use it in GitHub Desktop.
Save ibeex/6981800 to your computer and use it in GitHub Desktop.

Install ImageMagick (>= 6.8.0-10) for image conversion:

brew install imagemagick

Install leptonica (>= 1.69) and tesseract (>= 3.02.02) for OCR:

brew install leptonica
brew install tesseract --all-languages

Or install without --all-languages and install them manually as needed.

Make sure the input image is a grayscale .tif and fairly large. ~500x150 was too small, while ~2000*500 worked very well.

convert input.png -resize 400% -type Grayscale input.tif

OCR it. The default language is English. Language codes are 3 chars per man tesseract. French language is coded 'fra'.

tesseract -l eng input.tif output

This creates output.txt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment