How to Extract Text from an Image using Tesseract OCR in Linux

Optical Character Recognition (OCR) is the process of extracting editable text from images or scanned documents. While there are many paid cloud services that offer this functionality, Linux users can achieve fantastic, offline OCR results directly from the terminal using an open-source engine called Tesseract.

What is Tesseract?

Originally developed by Hewlett-Packard and currently maintained by Google, Tesseract is widely considered one of the most accurate open-source OCR engines available. It works entirely offline and supports over 100 languages.

How to Install Tesseract on Ubuntu

Tesseract is available in the default Ubuntu repositories, making installation incredibly simple.

  1. Open your terminal (Ctrl + Alt + T).
  2. Update your package list: sudo apt update
  3. Install the Tesseract engine: sudo apt install tesseract-ocr

How to Extract Text from an Image

Once installed, using Tesseract is as simple as passing it an image file and telling it where to save the text output.

  1. Navigate to the folder containing your image using the cd command.
  2. Run the following command: tesseract image.png output

In this example, Tesseract will read image.png, extract the text, and automatically create a file named output.txt containing the results. You do not need to add the .txt extension to the command; Tesseract adds it automatically.

If you are scanning a document in a language other than English, you must install the specific language pack (e.g., sudo apt install tesseract-ocr-fra for French) and use the language flag: tesseract image.png output -l fra.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.

Receive our best articles and tips delivered straight to your inbox.