OCR Extraction | Easy Conversion of Image 2 Text



Images are everywhere, every one loves to takes a snap to different views like scenery, selfie, panorama or even if you don’t feel like writing then you prefer taking a snap of the documents that you have with you. And it really helps us a lot and saves lot of our time. But do you know if you want to edit or copy the text that you have with you in the form of an image then we have to do the typing type the complete text from an image into the text format which will consume lot of our time which we saved before. Now, you will really feel like boring if you don’t like typing.

So, What’s the solution for it, because I will not prefer wasting lot of my time typing the text from an image.

So, once again I’m back with an advanced technique to convert the image to the text which you can also call as the OCR Extraction. So, what is OCR extraction and how does it work. Let’s understand it.

What is OCR Extraction?

OCR or Optical Character Recognition is an electronics or mechanical conversion of the image (with typed, printed, or handwritten text) into the machine-encoded text, whether from the scanned documents, snap of a document, scene photo or from subtitle text superimposed on an image.

How does it work?

In the initial stage, the document that you have is in the form of an image consisting of dots and lines – or unstructured data that cannot be read with the OCR extraction.

1. With OCR Extraction the unstructured data is converted to the structured data.

2. The data that you have now is the in the form of the n-dimensional array which can be used further for character detection as well as the character recognition.

3. Then the recognised text converted to the text format and stored in different text format for reuse.


Now, let’s understand the practical implementation of the conversion that we discussed above. So, to implement this we have to follow the given steps,

– Read the image document on which we want to apply OCR extraction. For reading the image we are going to use OpenCV.
– Image to text conversion using tesseract

Before starting, let’s install OpenCV and tesseract. Use the below command to install OpenCV and pytesseract,

pip install opencv-python pytesseract


sudo apt update && sudo apt install tesseract-ocr

You can also refer to this session for proper understanding,

Here is the image that I’ll use in this blog for image to text conversation,

text for OCR extraction
Fig: Image document to read

After the successful installation, write the below code to read the text from the above image document,

Full code:

import cv2
import pytesseract

## Read the image using cv2.imread

## convert the read image document to text with the given configuration
text=pytesseract.image_to_string(img,config=r"--oem 3 --psm 6")

## store the read text to file named image2text.txt
with open(“image2text.txt”,”w”) as file:

In this way, you will be able to extract the text from the image document and this process will really help you a lot if you have image documents in bulk because it will save a lot of your efforts and time.

Time to wrap up now. Hope you liked our content on How does OCR extraction works. See you in our next blog, thanks for reading our blog and do leave a comment below to help us improve the content to serve you all of our experience with you. Stay tuned with us for more contents.

Also check out our other playlist Rasa Chatbot, Internet of things, Docker, Python Programming, etc.
Become a member of our social family on youtube here.

Stay tuned and Happy Learning. 🙂

Ashish Saini
Ashish Saini

I am a software developer for Python/Machine Learning. Also, I’m Rasa Hero at Rasa. Also, I’m a youtuber where I regulary uploads the videos to help this generation learn about the technology just like they are playing games.

Leave a Reply