How to convert image to text using Python in Object oriented programming

Pre-Requisties:

  1. pytesseract package needed to installed

Installing Pytesseract

Installation can be done in two ways in PyCharm IDE,

  1. Run the below command in the terminal window,

                         pip install pytesseract 

ii)Otherwise, Go to File->New Project Settings->Preferences.In the project Interpreter select the Add(+) symbol and choose the pytesseract package from the list and select Install package. 

Once we complete install of pytesseract we are good to start program for image conversion.

LETS GET STARTED

In this example we are going to have four .py files to process the image to text .

  1. InputFile -> to get the image file path
  2. Image Conversion-> to process the image to text
  3. OutputFile -> To display the text
  4. Main Program -> To process the all the files.

The RequestInput file gets the user input image if not process the default image stored. 

The imgtotext file does the image conversion to text using image_to_string method 

The PrintOutputString file prints the output text. 

The MainProgram file defines a user defined class “MainClass” and declares a default file path. If user input file path is not received default file path will be processed.This also imports other three files.

LETS GEAR UP TO RUN THE PROGRAM

The MainProgram is the executable file. Select Run -> Run the MainProgram.py

Give the full file path for the image. 

If the user input is not given default stored image is converted to text.

Thus we have achieved image to text conversion using object oriented way.

POINTS TO BE NOTED:

  1. The image can be stored either in the local path or within the Python Project.   The full file path should be given in both the ways.

2)   The package pytesseract should be properly installed for successful execution of the code.