Installing Tesseract for OCR

Today’s blog post is part one in a two part series on installing and using the Tesseract library for Optical Character Recognition (OCR).

OCR is the automatic process of converting typed, handwritten, or printed text to machine-encoded text that we can access and manipulate via a string variable.

Part one of this series will focus on installing and configuring Tesseract on your machine, followed by utilizing the tesseract  command to apply OCR to input images.

In next week’s blog post we’ll discover how to use the Python “bindings” to the Tesseract library to call Tesseract directly from your Python script.

To learn more about Tesseract and how it can be used for OCR, just keep reading.

Looking for the source code to this post?
Jump right to the downloads section.

Installing Tesseract for OCR

Tesseract, originally developed by Hewlett Packard in the 1980s, was open-sourced in 2005. Later, in 2006, Google adopted the project and has been a sponsor ever since.

The Tesseract software works with many natural languages from English (initially) to Punjabi to Yiddish. Since the updates in 2015, it now supports over 100 written languages and has code in place so that it can easily be trained on other languages as well.

Originally a C program, it was ported to C++ in 1998. The software is headless and can be executed via the command line. It does not come with a GUI but there are several other software packages that wrap around Tesseract to provide a GUI interface.

To read more about Tesseract visit the project page and read the Wikipedia article.

In this blog post we will:

  • Install Tesseract on our systems.
  • Validate that the Tesseract install is working correctly.
  • Try Tesseract OCR on some sample input images.

After going through this tutorial you will have the knowledge to run Tesseract on your own images.

Step #1: Install Tesseract

In order to use the Tesseract library, we first need to install it on our system.

For macOS users, we’ll be using Homebrew to install Tesseract:

Figure 1: Installing Tesseract OCR on macOS.

If you’re using the Ubuntu operating system, simply use apt-get  to install Tesseract OCR:

Figure 2: Installing Tesseract OCR on Ubuntu.

For Windows, please consult Tesseract documentation as PyImageSearch does not support or recommend Windows for computer vision development.

Step #2: Validate that Tesseract has been installed

To validate that Tesseract has been successfully installed on your machine, execute the following command:

Figure 3: Validating that Tesseract has been successfully installed on my machine.

You should see the Tesseract version printed to your screen, along with a list of image file format libraries Tesseract is compatible with.

If you instead get the error:

Then Tesseract was not properly installed on your system. Go back to Step #1 and check for errors. Additionally, you may need to update your PATH  variable (for advanced users only).

Step #3: Test out Tesseract OCR

For Tesseract OCR to obtain reasonable results, you’ll want to supply images that are cleanly pre-processed.

When utilizing Tesseract, I recommend:

  • Using as an input image with as high resolution and DPI as possible.
  • Applying thresholding to segment the text from the background.
  • Ensuring the foreground is as clearly segmented from the background as possible (i.e., no pixelations or character deformations).
  • Applying text skew correction to the input image to ensure the text is properly aligned.

Deviations from these recommendations can lead to incorrect OCR results as we’ll find out later in this tutorial.

Now, let’s apply OCR to the following image:

Figure 4: An example image we are going to apply OCR to using Tesseract.

Simply enter the following command in your terminal:

Correct! Tesseract correctly identified, “Testing Tesseract OCR”, and printed it in the terminal.

Next, let’s try this image:

Figure 5: A second example image to apply Optical Character Recognition to using Tesseract.

Enter the following in your terminal, noting the changed input filename:

Figure 6: Tesseract is able to correctly OCR our image.

Success! Tesseract correctly identified the text, “PyImageSearch”, in the image.

Now, let’s try OCR’ing digits as opposed to alphabetic characters:

Figure 7: Using Tesseract to OCR digits in images.

This example uses the command line  digits  switch to only report digits:

Once again, Tesseract correctly identified our string of characters (in this case digits only).

In each of these three situations Tesseract was able to correctly OCR all of our images — and you may even be thinking that Tesseract is the right tool for all OCR uses cases.

However, as we’ll find out in the next section, Tesseract has a number of limitations.

Limitations of Tesseract for OCR

A few weeks ago I was working on a project to recognize the 16-digit numbers on credit cards.

I was easily able to write Python code to localize each of the four groups of 4-digits.

Here is an example 4-digit region of interest:

Figure 8: Localizing a 4-digit grouping of characters on a credit card.

However, when I tried to apply Tesseract to the following image, the results were dissatisfying:

Figure 9: Trying to apply Tesseract to “noisy” images.

Notice how Tesseract reported 5513 , but the image clearly shows 5678 .

Unfortunately, this is a great example of a limitation of Tesseract. While we have segmented the foreground text from background, the pixelated nature of the text “confuses” Tesseract. It’s also likely that Tesseract was not trained on a credit card-like font.

Tesseract is best suited when building document processing pipelines where images are scanned in, pre-processed, and then Optical Character Recognition needs to be applied.

We should note that Tesseract is not an off-the-shelf solution to OCR that will work in all (or even most) image processing and computer vision applications.

In order to accomplish that, you’ll need to apply feature extraction techniques, machine learning, and deep learning.

A great example of applying feature extraction and machine learning to build a handwriting recognition system can be found inside my book, Practical Python and OpenCV.


Today we learned how to install and configure Tesseract on our machines, the first part in a two part series on using Tesseract for OCR. We then used the  tesseract  binary to apply OCR to input images.

However, we found out that unless our images are cleanly segmented Tesseract will give poor results. In the case of “noisy” input images, we’ll likely obtain better accuracy by training a custom machine learning model to recognize characters in our specific use case.

Tesseract is best suited for situations with high resolution inputs where the foreground text is cleanly segmented from the background.

Next week we’ll learn how to access Tesseract via Python code, so stay tuned.

To be notified when the next blog post on Tesseract goes live, be sure to enter your email address in the form below!


If you would like to download the code and images used in this post, please enter your email address in the form below. Not only will you get a .zip of the code, I’ll also send you a FREE 17-page Resource Guide on Computer Vision, OpenCV, and Deep Learning. Inside you'll find my hand-picked tutorials, books, courses, and libraries to help you master CV and DL! Sound good? If so, enter your email address and I’ll send you the code immediately!

, ,

46 Responses to Installing Tesseract for OCR

  1. Mans July 3, 2017 at 11:29 am #

    Thank you for your professionalism and always interesting newsletter.

    • Adrian Rosebrock July 5, 2017 at 6:09 am #

      Thank you Mans, I’m happy to hear you are enjoying the PyImageSearch blog 🙂

      • Raghunandan Palakodety July 18, 2017 at 12:45 am #

        Thank you Dr. Rosebrock, I always follow your articles. I will try to understand how tesseract works now.

      • Jibin John July 12, 2018 at 1:55 am #

        How to install version 4.xx on raspberry-pi

        executing the same command showing my tesseract is latest version but i want to use 4.xx .

        can you help me

        sorry about my English and Thanks in Advance

        • Jibin John July 12, 2018 at 3:00 am #

          I found that my raspberry pi is based on ARM64 architecture which doestn’t support version 4.xx

          • Adrian Rosebrock July 13, 2018 at 5:10 am #

            I will be creating a dedicated tutorial for Tesseract 4. Stay tuned! 🙂

        • David Hoffman October 1, 2018 at 2:39 pm #

          Hi Jibin, be sure to refer to Adrian’s new post on Tesseract 4 — Raspberry Pi instructions are included.

  2. Rahul July 3, 2017 at 11:36 am #

    Hello sir, how can we add custom database fonts in tesseract, i followed some on-line sites but no results. Can you please help out on this for my academic project.

    • Adrian Rosebrock July 5, 2017 at 6:08 am #

      Take a look at “Daniel Paull”‘s comment.

  3. Jeff Bass July 3, 2017 at 5:41 pm #

    Thanks for this. While there are free online services for OCR, they are web / gui based and not helpful. The Google Drive OCR option for uploaded documents is also web /gui based. The Google cloud platform OCR does a good job, but it still requires uploading the image to the cloud, subsequently using an API to do the OCR. But Google OCR API is not free and a bit of a pain to use. Tesseract can run locally without uploading anything to the internet. This command line approach worked well for me and I look forward to Part 2 so I can use it from Python.

  4. Anthony The Koala July 3, 2017 at 7:17 pm #

    I am yet to study denoising of images. Nevertheless my question is about denoising a noisy image in order to apply the tesseract package to a denoised image.

    Do you have tutorials in your blog about denoising. So that one can apply denoising techniques on a noisy image then perform OCR using the tesseract?

    Anthony from Sydney NSW

    • Adrian Rosebrock July 5, 2017 at 6:03 am #

      Hi Anthony — next week’s blog post will be an example of how to cleanup images before passing them through Tesseract to increase OCR accuracy.

  5. Greg Pierce July 3, 2017 at 10:01 pm #

    Does this mean that a machine neural network would actually be better than using Tesseract in the average case? I’ve tossed credit cards at these at this point and they seem to perform pretty good.

    • Adrian Rosebrock July 5, 2017 at 6:02 am #

      It really depends on your application and how cleanly segmented your images are. If your images are nice and segmented, Tesseract can do very, very well. If you have a lot of noise and variation in your characters, it might be worth considering training your own neural network.

  6. Mahdi July 4, 2017 at 5:22 am #

    Is it possible use for another language?,how?
    Thank you .

    • Adrian Rosebrock July 5, 2017 at 6:00 am #

      Take a look at the “Other Languages” section of the official Tesseract documentation.

  7. Daniel Paull July 4, 2017 at 7:46 am #

    G’day Adrian,

    I’ve recently spent a lot of time getting Tesseract to work nicely for OCR of some documents. I found that disabling the use of dictionaries (since I’m not not parsing prose), using character whitelists and training for specific fonts was needed to get reliable results. As an aside, if you need to train for a specific font, give this website a crack (I have no affiliation with them, but found it useful):

    Noise is a problem for sure. I use morphological operators to fill and smooth, but I still get some problems. Doing your own thresholding is a must as the built in thresholding seems pretty basic and doesn’t do a very good job.

    Once you get it working for a given application, Tesseract can work well. But, it certainly needs a lot of hand holding to get there.

    • Adrian Rosebrock July 5, 2017 at 5:58 am #

      Thank you for sharing, Daniel! I had never used TrainYourTesseract before, I will certainly give it a look.

  8. Thimira Amaratunga July 5, 2017 at 11:08 am #

    Thanks for another great article!
    I haven’t used Tesseract before, but thanks to this article I should be able to 🙂

    Just one thought about the statement “PyImageSearch does not support or recommend Windows for computer vision development”,
    About a year back I would have agreed with you (and I use Linux for most of my development still). But Windows has matured a lot since then, and many computer vision and machine learning tools/libraries does work quite well with Windows now. I think it’s worth a shot giving Windows a chance.
    (Here’s some posts I made on setting up things on Windows:

    Just a thought 🙂

    • Adrian Rosebrock July 7, 2017 at 10:10 am #

      I agree with Windows has matured a lot, especially with the bash inclusion, but I still don’t recommend it for computer vision development. Microsoft is doing some really neat things with their APIs, but Windows itself isn’t conducive to computer vision development. Furthermore, as the writer of PyImageSearch I can only support what I know, which is Unix. The support burden of having to troubleshoot Windows is simply far too high.

  9. Dami July 11, 2017 at 9:52 am #

    Hi Adrian,

    I just recently subscribed to your messages and I have been playing with examples you created. I’m actually pretty new to Python and so far I’m enjoying the ride.

    I have a question i’m hoping you can help me with. I have been testing out the results of running pytesseract with various options. Setting the config to “config=’-psm xx'” works just fine but I can’t get it to read my custom config file which I placed in my tessdata folder (C:\Program Files (x86)\Tesseract-OCR\tessdata\configs). Is there a different folder perhaps which stores the pytesseract config files?

    Please help!

    • Dami July 11, 2017 at 9:54 am #

      Edit : Just wanted to add that using the -c option in the config such as “-c tessedit_char_whitelist=abcdefghijklmnopqrstuvwxyz” also doesn’t seem to work. I still see values returned which are not in that list!

    • Dami July 11, 2017 at 10:32 am #

      Actually…Never mind. Found what I needed. I can’t cancel this comment so…please help me do so.

      Well done with the tutorials though!

      • Adrian Rosebrock July 11, 2017 at 2:08 pm #

        Congrats on resolving the issue Dami!

  10. Petes July 15, 2017 at 1:02 am #


    Loved this introduction to Tesseract. Looking forward to learning about how to use Tesseract with Python next week. Thanks for providing great content!

    • Adrian Rosebrock July 18, 2017 at 10:10 am #

      Thanks Petes! 🙂

  11. Yuan July 18, 2017 at 8:50 am #

    How to recognize Chinese?

    • Adrian Rosebrock July 18, 2017 at 9:41 am #

      I don’t know if Tesseract recognizes Chinese characters out of the box, but you should consult the documentation regarding the provided languages and how to train your own language classifier if need be.

  12. faizal July 19, 2017 at 12:37 am #

    Hi Adrian,

    Thanks for the nice tutorial. Would it possible to read OCR using webcam video streaming?

    • Adrian Rosebrock July 21, 2017 at 9:00 am #

      Absolutely. You would need to localize the text in each frame first, then pass the text through Tesseract.

  13. Justin Alden September 27, 2017 at 9:02 am #

    Thanks Adrian. Your directions are so clean and helpful. One question: before you start writing “$ tesseract tesseract_inputs/example_01.png stdout”
    where does your PWD need to be?

    i’m having issues and i think it’s path related. I have tesseract installed but i can’t manipulate it via python. i’ve gone through stack overflow and there isn’t help when installing tesseract via unix on a mac for python3.

    many thanks,

    • Adrian Rosebrock September 28, 2017 at 9:14 am #

      Your working directory shouldn’t matter here. Provided you have installed tesseract properly you should be able to execute the script from any location on your machine.

      If you want to use Tesseract and Python together, please see this post.

  14. Henny February 16, 2018 at 8:11 am #

    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…

  15. Rodrigo July 2, 2018 at 3:21 pm #


    I’m trying to intall tesseract 3.05, but when I do sudo apt-get install tesseract-ocr
    I get tesseract 3.04.01. I also have noticed that your Figure 2 doesn’t match with your output from tesseract -v command: the first shows tesseract 3.04.01 installed, while the second says 3.05.00.

    How can I install 3.05.00? I’m using linux by the way

    Thanks in advance!

    • Adrian Rosebrock July 3, 2018 at 7:20 am #

      I gathered these results on both macOS and Linux to verify that they worked. If you need a specific version of Tesseract you should compile and install from source.

  16. Hassan September 2, 2018 at 1:04 pm #

    Hi Adrian!

    Nice work and Great blog

    I installed tesseract on Raspbian. However, the version is 3.04.01
    I tried to upgrade it but I could not, what’s the problem?

    From what I read, version 3.05 is provided with many more features and much improved version. Is this right?

    • Adrian Rosebrock September 5, 2018 at 9:03 am #

      I’m not sure what you mean by being unable to upgrade. Did you get an error message of some kind?

      • RAMJAN RAEEN October 18, 2018 at 12:52 pm #

        Hi! Adrian Rosebrock
        Please help me, what is the location to install Pytessract OCR. I installed where all package is installed via pip, But still getting an error that Pytessract is not installed or path is not found?
        Sorry for my English.
        Thank you.

        • RAMJAN RAEEN October 18, 2018 at 12:53 pm #

          I am using Windows 10 OS.

          • Adrian Rosebrock October 20, 2018 at 7:40 am #

            Hey Ramjan, I don’t have a Windows machine and I don’t officially support Windows here on the PyImageSearch blog. Would you be able to try on Unix-based OS like macOS or Linux? Additionally, if you have any questions related to installing pytesseract on Windows I would definitely suggest posting on their official GitHub page. I know that doesn’t solve your exact question but I hope it at least points you in the right direction!

  17. karim October 24, 2018 at 10:22 pm #

    I am using Oracle Linux. I couldn’t find complete steps to install in Linux machine.I installed in Ubuntu, for few for scanned PDFs its extracting unknown characters sometimes not.Can you please let me know the link how to install on Linux machine instead of Ubuntu.
    Thanks & Regards,

    • Adrian Rosebrock October 29, 2018 at 1:54 pm #

      Hey Karim — I use Ubuntu daily which is the Linux OS I have the most experience with. Unfortunately I do not have any tutorials dedicated to Oracle Linux.

  18. Rob November 29, 2018 at 4:51 am #

    How to use and install the Training Tools? In the Documentation it says i have to make the Training Tools from the Source Directory, but i already installed tesseract by “apt-get”.

    Once the above additional libraries have been installed, run the following from the Tesseract source directory:
    make training
    sudo make training-install

    • Adrian Rosebrock November 30, 2018 at 8:58 am #

      Hi Rob — I’ve never personally trained a custom Tesseract model so I’m not sure how to use their training tools.


  1. Using Tesseract OCR with Python - PyImageSearch - July 10, 2017

    […] last week’s blog post we learned how to install the Tesseract binary for Optical Character Recognition […]

  2. Credit card OCR with OpenCV and Python - PyImageSearch - July 17, 2017

    […] a previous blog post, we learned how to install the Tesseract binary and use it for OCR. We then learned how to cleanup images using basic image processing techniques to improve the […]

Before you leave a comment...

Hey, Adrian here, author of the PyImageSearch blog. I'd love to hear from you, but before you submit a comment, please follow these guidelines:

  1. If you have a question, read the comments first. You should also search this page (i.e., ctrl + f) for keywords related to your question. It's likely that I have already addressed your question in the comments.
  2. If you are copying and pasting code/terminal output, please don't. Reviewing another programmers’ code is a very time consuming and tedious task, and due to the volume of emails and contact requests I receive, I simply cannot do it.
  3. Be respectful of the space. I put a lot of my own personal time into creating these free weekly tutorials. On average, each tutorial takes me 15-20 hours to put together. I love offering these guides to you and I take pride in the content I create. Therefore, I will not approve comments that include large code blocks/terminal output as it destroys the formatting of the page. Kindly be respectful of this space.
  4. Be patient. I receive 200+ comments and emails per day. Due to spam, and my desire to personally answer as many questions as I can, I hand moderate all new comments (typically once per week). I try to answer as many questions as I can, but I'm only one person. Please don't be offended if I cannot get to your question
  5. Do you need priority support? Consider purchasing one of my books and courses. I place customer questions and emails in a separate, special priority queue and answer them first. If you are a customer of mine you will receive a guaranteed response from me. If there's any time left over, I focus on the community at large and attempt to answer as many of those questions as I possibly can.

Thank you for keeping these guidelines in mind before submitting your comment.

Leave a Reply