In this article, we are going to recognize the character from the images and get text data out of an image. Let’s take a quick introduction to the required module.
- OpenCV: It is a Python module in which we can do image processing, video capture, and some analysis tools like face detection or object detection. It has C++, Python, Java, and MATLAB interfaces and supports Windows, Linux, Android, and Mac OS.
- Pytesseract: Python-tesseract is an optical character recognition (OCR) tool for Python. That is, it will recognize and “read” the text embedded in images. Python-tesseract is a wrapper for Google’s Tesseract-OCR Engine. It is also useful as a stand-alone invocation script to tesseract, as it can read all image types supported by the Pillow and Leptonica imaging libraries, including jpeg, png, gif, BMP, tiff, and others. Additionally, if used as a script, Python-tesseract will print the recognized text instead of writing it to a file.
- Import required module
- Setting the path of pytesseract.
- Read the image with cv2.imread()
- Convert image in RGB format.
- Extract text from image using pytesseract.image_to_string(img).
We are going to use this image for a demonstration:
Below is the full implementation:
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.