January 6, 2025
Beginner’s Guide to Extract Text from Images Using Python
A real-life example with code using EasyOCR package

By Rishabh Sharma
3 min read
Optical Character Recognition (OCR) has numerous real-world applications, including:
Document Processing: Extracting text from invoices, receipts, forms, and other documents for data entry and analysis. Image Recognition: Recognizing text in images for image search, content categorization, and image captioning. Autonomous Vehicles: Reading street signs, traffic signals, and license plates for navigation and safety. Retail: Analyzing product labels, shelf tags, and customer feedback forms for inventory management, market research, and customer service. Historical Archives: Digitizing and transcribing historical documents, books, and manuscripts.
For my mini-project, I explored the capabilities of EasyOCR, a user-friendly open-source library in Python that simplifies Optical Character Recognition (OCR).
Key Features of EasyOCR
- Multilingual Support: EasyOCR supports a vast array of languages, including English, Chinese, Japanese, Korean, and many more. This versatility makes it adaptable to diverse use cases.
- High Accuracy: The library leverages advanced deep learning models, resulting in high accuracy in text recognition even in challenging scenarios like low-resolution images, handwritten text, and complex layouts.
- Flexibility: EasyOCR offers flexible output formats. It can return the recognized text, bounding boxes around the detected text, and even confidence scores for each recognized character. This flexibility allows developers to tailor the output to their specific needs.
- Ease of Use: The library boasts a simple and intuitive API, making it easy to integrate into various projects with minimal effort.
Hidden Nuggets of EasyOCR
- GPU Acceleration: EasyOCR can leverage the power of GPUs (Graphics Processing Unit) to significantly accelerate the OCR process, making it suitable for real-time applications and large-scale image processing tasks.
- Customizable Models: While pre-trained models are readily available, EasyOCR also provides the option to train custom models on specific datasets for improved accuracy on domain-specific text.
Extracting Text from an Image
Finally, this is how I used EasyOCR to extract text from a Costco invoice. Here's the code and I'll explain each and every step.
import easyocr
reader = easyocr.Reader(['en'])
result = reader.readtext('C:\\Users\\rs\\Downloads\\Costco_invoice.jpg')
for (bbox, text, prob) in result:
print (text)import easyocr
reader = easyocr.Reader(['en'])
result = reader.readtext('C:\\Users\\rs\\Downloads\\Costco_invoice.jpg')
for (bbox, text, prob) in result:
print (text)This code performs the following steps:
- Imports the
easyocrlibrary. - Creates an OCR Reader object:
reader = easyocr.Reader(['en'])creates an instance of theReaderclass, specifying English as the language for text recognition.result = reader.readtext('C:\\Users\\Downloads\\Costco_invoice.jpg')reads the text from the specified image file. You can change this address based on wherever you have stored the image on your machine.resultis a list of tuples, where each tuple contains:bbox: The bounding box coordinates of the recognized text.text: The recognized text string.prob: The confidence score of the recognized text.- The code iterates through the
resultlist and extracts thetextfrom each tuple. - Finally, it prints each extracted text string.
Building Upon This Project
This was a basic implementation. To further enhance this project, I could:
- Extract Specific Information:
Develop logic to extract specific information from the extracted text, such as item names, prices, and totals. This could involve using regular expressions or natural language processing techniques.
- Integrate with Other Tools:
Integrate EasyOCR with other tools, such as spreadsheets or databases, to store and analyze the extracted data.
- Create a User Interface:
Develop a user interface (e.g., a simple GUI) to allow users to easily upload images, select language options, and view the extracted text.
Conclusion
This project was a really interesting dive into the world of OCR. I was excited to see how well EasyOCR could extract text from a real-world example like a Costco receipt. While I successfully extracted the text, I realized there's still a lot I can learn and improve. I'm eager to explore ways to make the price extraction more accurate, figure out how to better identify individual items, and maybe even try some image pre-processing techniques to make the results even cleaner.
This project was a great starting point, and I'm already brainstorming ideas for how to build upon it and explore other exciting OCR applications! Please share any ideas in the comments where you could think of implementing OCR data extraction in the real world.
Thank you for being a part of the community
Before you go:
- Be sure to clap and follow the writer ️👏️️
- Follow us: X | LinkedIn | YouTube | Newsletter | Podcast
- Check out CoFeed, the smart way to stay up-to-date with the latest in tech 🧪
- Start your own free AI-powered blog on Differ 🚀
- Join our content creators community on Discord 🧑🏻💻
- For more content, visit plainenglish.io + stackademic.com