MITB Banner

Beginners Guide To Optical Character Recognition Using Pytesseract

In this article, we will see how to fetch texts from an image using OCR with Pytesseract.
Share
Optical Character Recognition Using Pytesseract

It has happened with all of us, tried copying the text but later realised that it is an image. And you have felt like, only if I could copy it!! Haha, no worries in today’s article I will share a secret with you, which will help you fetch the text from an image????

In today’s article, we will see how to fetch texts from an image using OCR.

Introduction to Optical Character Recognition

OCR stands for Optical Character Recognition also known as Optical Character Reader. These terms are used interchangeably. It is devised to read texts from images. It has many advantages and applications for what it is used for today.

Applications of Optical Character Recognition:

  1. Used for recognizing traffic signals on the road
  2. To extract text from cheque books while entering entries in the bank.
  3. Passport detail verification at Airports

And many more.

Most of the scalable ones with high-end applications have portable OCR scanners which fit the right purpose.

Well in this article I will help you make an OCR of your own with the help of tesseract which is a widely used OCR engine open-sourced by Google.

Dependency:

  1. Pillow: pip install pillow
  2. pytesseract : pip install pytesseract
  3. tesseract-ocr : pip install tesseract-ocr

So for this post, we will be taking this image for demonstration:

Optical Character Recognition Using Pytesseract

But before that, we will be in a need to install tesseract into our system.

You can install tesseract from https://github.com/UB-Mannheim/tesseract/wiki

The Github repo supports windows as of now.

You can install as per your requirement, it has for both 32 bit and 64 bit.

When you will install it generally would be installed in your C drive.

In my system, the path is: C:\Program Files\Tesseract-OCR

All the work of reading texts would be done via the tesseract application in the given folder.

CODE

#dependency
from PIL import Image
import pytesseract
If you want the Tesseract engine to work you need to give it the path it needs.
#set this and tesseract.exe is the application I was talking about earlier.
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
path = 'C:/Users/91884/PycharmProjects/Optical Character Recognition/quote.jpg' #image path
img = Image.open(path) #opening the images
text = pytesseract.image_to_string(img,lang='eng') #It supports many languages but as of now we want in english so, “eng”.
print(text)

SNAP OF CODE

Optical Character Recognition Using Pytesseract

OUTPUT

Conclusion:

This article was penned for the purpose to spread awareness about OCR, its applications and how can one really use it for FREE using python. Thanks to Google and other Open Source Communities for forging a supportive environment for aspirants!

The complete code of the above implementation is available at the AIM’s GitHub repository. Please visit this link to find this code.

PS: The story was written using a keyboard.
Share
Picture of Bhavishya Pandit

Bhavishya Pandit

Understanding and building fathomable approaches to problem statements is what I like the most. I love talking about conversations whose main plot is machine learning, computer vision, deep learning, data analysis and visualization. Apart from them, my interest also lies in listening to business podcasts, use cases and reading self help books.
Related Posts

CORPORATE TRAINING PROGRAMS ON GENERATIVE AI

Generative AI Skilling for Enterprises

Our customized corporate training program on Generative AI provides a unique opportunity to empower, retain, and advance your talent.

Upcoming Large format Conference

May 30 and 31, 2024 | 📍 Bangalore, India

Download the easiest way to
stay informed

Subscribe to The Belamy: Our Weekly Newsletter

Biggest AI stories, delivered to your inbox every week.

AI Courses & Careers

Become a Certified Generative AI Engineer

AI Forum for India

Our Discord Community for AI Ecosystem, In collaboration with NVIDIA. 

Flagship Events

Rising 2024 | DE&I in Tech Summit

April 4 and 5, 2024 | 📍 Hilton Convention Center, Manyata Tech Park, Bangalore

MachineCon GCC Summit 2024

June 28 2024 | 📍Bangalore, India

MachineCon USA 2024

26 July 2024 | 583 Park Avenue, New York

Cypher India 2024

September 25-27, 2024 | 📍Bangalore, India

Cypher USA 2024

Nov 21-22 2024 | 📍Santa Clara Convention Center, California, USA

Data Engineering Summit 2024

May 30 and 31, 2024 | 📍 Bangalore, India