Skip to content

Instantly share code, notes, and snippets.

Created March 3, 2012 17:07
What would you like to do?
OCR on OS X with tesseract

Install ImageMagick for image conversion:

brew install imagemagick

Install tesseract for OCR:

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.

tesseract -l eng input.tif output

This creates output.txt.

Copy link

Thanks for posting this, saved me lots of time :)

Copy link

Also thank you. This was great.

Copy link

coolya commented Oct 8, 2015


Copy link


Copy link

If you landed here looking to convert a scanned PDF to an OCRable format:

I found that imagemagick's PDF-to-TIFF output was all garbled / distorted. Couldn't find the right flag to increase the resolution, so I tried Ghostscript instead (which imagemagick might use under the hood):

gs -q -r300x300 -dNOPAUSE -sDEVICE=tiffg4 -dBATCH -sOutputFile=output.tif myscan.pdf -c quit

buyer beware, do: man gs first

Copy link

FYI, the --all-languages flag has been depreciated in favor of --with-all-languages. Thanks for the guide!

Copy link

stoivo commented Apr 26, 2016

Is there a way I can install only norwegian language?

Copy link

I have tried as your tutorial. But it shows:
"dyld: Library not loaded: /usr/local/opt/leptonica/lib/liblept.4.dylib
Referenced from: /usr/local/bin/tesseract
Reason: image not found
Trace/BPT trap: 5"
Can anyone tell me how to solve it?

Copy link

thanks a lot

Copy link

tesseract: --all-languages was deprecated; using --with-all-languages instead!

Copy link

yangboz commented Nov 22, 2016

Warning: tesseract: --all-languages was deprecated; using --with-all-languages instead!

Copy link

ekovacs commented Jan 30, 2017

👍 🥇
thank you! you saved me much frustration and time!!!

Copy link

👍 😄

Copy link

Thanks A lot , you saved my life.

Copy link

what if I want to convert images to text files in bulk ?

Copy link

Does converting a png to tiff increase the odds of accurate OCR?

Copy link

It's working thanks for the help

Copy link

HjoshM commented Feb 16, 2018

A long time ago, I installed tesseract 3.05.01 for OCR using HomeBrew:

brew install --with-training-tools tesseract

How do I update it to the latest? I thought by regularly running the following, this would be done:

brew update
brew upgrade
brew outdated

However, my tesseract has not been updated at all...

Copy link

@flyingmrwang did you figure it out? I encountered same issue.

Copy link

Love this tip. I created a bash function to make it even easier to run on english text:

function extract-text {
    convert $1 -resize 400% -type Grayscale $1.tif
    tesseract -l eng $1.tif output

Copy link

sshaw commented Nov 24, 2018

For imagemagick: stable 7.0.8-14 on OS X 10.9.5 I had to install with --with-fontconfig:

brew install imagemagick --with-fontconfig

Compare your results with/without resize as resize can take more resources for no OCR improvement.

For OCR improvements see Improving Quality or try training.

Copy link

Is there a brew route for getting & running the latest version of tesseract (LSTM-based, 4.0.0)?

I'm currently using:

$ tesseract --version                                                                                                   
tesseract 3.05.01
  libjpeg 9c : libpng 1.6.34 : libtiff 4.0.9 : zlib 1.2.11

..on macOS, High Sierra 10.13.4 17E202 x86_64. Thanks!

Copy link

euakll commented Feb 5, 2019

All languages option is not working

brew install tesseract --all-languages
Error: invalid option: --all-languages

brew --version
Homebrew 2.0.0
Homebrew/homebrew-core (git revision a761; last commit 2019-02-05)
Homebrew/homebrew-cask (git revision 1e6e6; last commit 2019-02-05)

Copy link

varenc commented Feb 6, 2019


Homebrew recently decided to remove all options from the homebrew-core Formula's. Though as of right now tesseract now includes all languages by default so just remove the option and you should get all languages. This makes tesseract 680MB by default though so think this should change in the future.

In the medium to short term, you can install tesseract with all language support with this
brew install though that's just a reference to a particular version of the Formula so won't receive future updates.

Copy link

why my execute brew install tesseract --all-languages is Error: invalid option: --all-languages ?

Copy link

why my execute brew install tesseract --all-languages is Error: invalid option: --all-languages ?

Homebrew recently decided to remove all options from the homebrew-core Formula's as explained by @varenc

Copy link

bejvisek commented May 22, 2019

Hi, I have installed tessaract 4.0.0 smoothly by
brew install tesseract
but have only these languages available:
$ tesseract --list-langs List of available languages (3): eng osd snum
No above mention option like --with-all-languates does not work anymore :-/

Is there a way to install selected language(s)? Thanks!

Copy link

Answering my own question:
brew install tesseract-lang
It installs most of the languages, but not all listed here: link
I need to install language "equ", still don't know how

Copy link

thanks @bejvisek

Copy link

MacOS user must use "brew install tesseract-lang" instant "brew install tesseract --all-languages"

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