Easily Recognize Text With This Python OCR Library Supporting Over 80 Languages

Click the aboveBeginner’s Guide to Vision” and choose to add a Star or “Pin

Important content delivered first

This article is adapted from | Python Big Data Analysis

What is OCR?

There is a software called “ScanMaster”, which some of you may have heard of. This is an integrated OCR software that can scan image content into text.

So, the role of OCR is to analyze and recognize text materials from image files to extract text and layout information.

OCR stands for “Optical Character Recognition”.

This is one of the most common and useful AI application technologies in everyday life.

Easily Recognize Text With This Python OCR Library Supporting Over 80 Languages

With careful observation, you can find that OCR is everywhere around us: document scanning, license plate recognition, ID recognition, bank card recognition, receipt recognition, and so on.

The essence of OCR is image recognition, which includes two key technologies: text detection and character recognition.

First, extract features from the image and detect the target area, then segment and classify the characters in the target area.

Easily Recognize Text With This Python OCR Library Supporting Over 80 Languages
About EasyOCR

There is a good OCR library in Python called EasyOCR, which has 9700 stars on GitHub. It can be called in Python to recognize text in images and output it as text.

https://github.com/JaidedAI/EasyOCR

Easily Recognize Text With This Python OCR Library Supporting Over 80 Languages

EasyOCR supports recognition in over 80 languages, including English, Chinese (simplified and traditional), Arabic, Japanese, etc., and this library is continuously updated to support more languages in the future.Easily Recognize Text With This Python OCR Library Supporting Over 80 Languages

Installing EasyOCR

The installation process is quite simple, using pip or conda to install.

pip install easyocr

If using the PyPI source, it may take some time to install, so it is recommended to use Tsinghua source, which can be installed in just a few seconds.

Usage Method

The usage of EasyOCR is very simple and consists of three steps:

  • 1. Create a recognition object;
  • 2. Read and recognize the image;
  • 3. Export the text.

Let’s start with a simple example.

Find a picture of a road sign and save it to your computer:Easily Recognize Text With This Python OCR Library Supporting Over 80 Languages

Then write the code:

# Import easyocr
import easyocr
# Create reader object
reader = easyocr.Reader(['ch_sim','en']) 
# Read image
result = reader.readtext('test.jpg')
# Result
result

Output result:Easily Recognize Text With This Python OCR Library Supporting Over 80 Languages

You can see that the three road names and their pinyin have been recognized!

The recognition result is contained in a tuple, which consists of three parts: bounding box coordinates, text, and recognition probability.

About Languages:

This piece of code has a parameter [‘ch_sim’,’en’], which is the list of languages to be recognized. Since the road sign contains both Chinese and English, ‘ch_sim’ (Simplified Chinese) and ‘en’ (English) were added to the list.

You can pass multiple languages at once, but not all languages can be used together. English is compatible with every language, and languages that share common characters are usually compatible with each other.

Earlier, we provided the list of languages supported by EasyOCR, along with their parameter codes.

About Image Files:

The above passed the relative path ‘test.jpg’, but you can also pass OpenCV image objects (numpy arrays), image byte files, image URLs.

Next, let’s read an image of a news article with more text:Easily Recognize Text With This Python OCR Library Supporting Over 80 Languages

# Import easyocr
import easyocr
# Create reader object
reader = easyocr.Reader(['ch_sim','en']) 
# Read image
result = reader.readtext('test1.jpg')
# Result
result
Easily Recognize Text With This Python OCR Library Supporting Over 80 Languages

The accuracy of the recognized text is still quite high. Next, we will extract the text part.

for i in result:
    word = i[1]
    print(word)

Output:Easily Recognize Text With This Python OCR Library Supporting Over 80 Languages

Conclusion

This open-source library is the result of the author’s research on several papers, truly a practical person.

The detection part uses the CRAFT algorithm, and the recognition model is CRNN, which consists of three main components: feature extraction, sequence labeling (LSTM), and decoding (CTC). The entire deep learning process is implemented based on Pytorch.

The author has been improving EasyOCR, with plans to expand support for more languages to cover 80% to 90% of the global population, and also to support handwritten recognition while improving processing speed.

Good news, the Beginner’s Guide to Vision team has opened a knowledge platform. To thank everyone for their support and love, the team has decided to allow free access to the knowledge platform worth 149 yuan. Everyone should seize the opportunity!

Easily Recognize Text With This Python OCR Library Supporting Over 80 Languages

Download 1: OpenCV-Contrib Extension Module Chinese Tutorial
Reply in the “Beginner’s Guide to Vision” WeChat public account:Chinese Tutorial for Extension Modules, and you can download the first Chinese version of the OpenCV extension module tutorial online, covering installation of extension modules, SFM algorithm, stereo vision, object tracking, biological vision, super-resolution processing, and more than twenty chapters.
Download 2: 52 Lectures on Python Vision Practical Projects
Reply in the “Beginner’s Guide to Vision” WeChat public account:Python Vision Practical Projects, and you can download 31 visual practical projects including image segmentation, mask detection, lane detection, vehicle counting, eyeliner addition, license plate recognition, character recognition, emotion detection, text content extraction, facial recognition, etc., to help quickly learn computer vision.
Download 3: 20 Lectures on OpenCV Practical Projects
Reply in the “Beginner’s Guide to Vision” WeChat public account:20 Lectures on OpenCV Practical Projects, and you can download 20 practical projects based on OpenCV to advance your learning of OpenCV.

Discussion Group

Welcome to join the reader group of the public account to communicate with peers. Currently, there are WeChat groups for SLAM, three-dimensional vision, sensors, autonomous driving, computational photography, detection, segmentation, recognition, medical imaging, GAN, algorithm competitions (which will gradually be subdivided later), please scan the WeChat number below to join the group, and note: “Nickname + School/Company + Research Direction”, for example: “Zhang San + Shanghai Jiao Tong University + Vision SLAM”. Please note according to the format, otherwise it will not be approved. After successful addition, you will be invited to the relevant WeChat group based on your research direction. Please do not send advertisements in the group, otherwise you will be asked to leave the group. Thank you for your understanding~

Easily Recognize Text With This Python OCR Library Supporting Over 80 Languages

Easily Recognize Text With This Python OCR Library Supporting Over 80 Languages

Leave a Comment