easyOCR: A walkthrough with examples

By hientd, at: July 28, 2024, 11:04 a.m.

Estimated Reading Time: 5 min read

easyOCR: A walkthrough with examples
easyOCR: A walkthrough with examples

easyOCR: A walkthrough with examples

 

Introduction

Optical Character Recognition (OCR) is a crucial technology in today's digital world, enabling the conversion of different types of documents, such as scanned paper documents, PDF files, or images captured by a digital camera, into editable and searchable data. One of the leading libraries in Python for OCR is easyOCR. Developed by Jaided AI, easyOCR offers a simple interface, making it accessible for both beginners and experienced developers.

 

Pros and Cons


Pros

  1. Easy to Use: As the name suggests, easyOCR is user-friendly and straightforward to integrate into your projects.
     
  2. Multi-Language Support: easyOCR supports over 80 languages, making it versatile for global applications.
     
  3. Pretrained Models: The library comes with pretrained models, eliminating the need for extensive training.
     
  4. Active Community: It has a growing community and active development, ensuring regular updates and improvements.
     

Cons

  1. Resource Intensive: OCR processes can be demanding on system resources, particularly for large batches of images.
     
  2. Accuracy Variance: The accuracy can vary depending on the quality of the image and the language of the text.
     
  3. Limited Customization: While it is easy to use, it might lack some customization options available in more advanced OCR tools.

 

Samples: Code Snippets and Output

Here's a quick example to get you started with easyOCR:


Example

import easyocr

# Initialize reader with the desired language(s)
reader = easyocr.Reader(['en'])

# Perform OCR on an image
image_path = '/Users/joe/Downloads/Jim-Carrey.png'
result = reader.readtext(image_path)

# Print the results
for (bbox, text, prob) in result:
    print(f'Text: {text}, Probability: {prob:.4f}')

 

Output

Text: Ithink everybody should get, Probability: 0.9500
Text: rich and famous and do, Probability: 0.8559
Text: everything they ever dreamed, Probability: 0.8573
Text: of so, Probability: 0.9516
Text: they can see that it's not, Probability: 0.9783
Text: the answer., Probability: 0.6836
Text: Jim Carrey, Probability: 0.8824


In this example, the image file is processed by easyOCR, and it prints the detected text along with the probability of correctness for each piece of text.

 

Performance Insight


Time

The time taken for OCR processing largely depends on the size and number of images, as well as the system's hardware capabilities. On a standard modern laptop, processing a single image typically takes a few seconds. Here’s a quick benchmark for processing a single image:

import time

start_time = time.time()
result = reader.readtext(image_path)
end_time = time.time()

print(f"Time taken: {end_time - start_time} seconds")
# Time taken: 0.394942045211792 seconds

 

Accuracy

The accuracy of easyOCR can be impressive for clean and well-defined text. However, it may struggle with:

  • Blurred or low-resolution images: I have tested around 10 images with different blurry levels. The more blurry images take more time.
     
  • Handwritten text
     
  • Complex fonts or stylized text
     

For clean, printed text, the accuracy can often reach above 95%. For more challenging scenarios, the accuracy may drop, necessitating some post-processing or manual correction.

 

Conclusion

easyOCR is a powerful tool for anyone looking to implement OCR capabilities quickly and efficiently. Its ease of use and support for multiple languages make it a GREAT choice for a wide range of applications. However, be mindful of its resource demands and potential accuracy limitations with poor-quality images.

By integrating easyOCR into your projects, you can streamline the process of extracting text from images, making your applications more versatile and user-friendly.


Subscribe

Subscribe to our newsletter and never miss out lastest news.