Coders Packet

OCR on images to recognize text using Python

By Adarsh Hiremath

Using Python and its libraries for Optical Character Recognition on images to recognize text using Pytesseract and identifying faces associated with the recognized text using OpenCV.

The project is being coded in Python3. In this project, we will manipulate images using pillow a Python imaging library and then apply optical character recognition to the images we have, to recognize text which will be done using Pytesseract, and we will be using the OpenCV library to identify faces in images. 

Installing Dependencies

pip install Pillow
pip install opencv-python pip install pytesseract pip install numpy

 

  • The Python imaging library Pillow will be used to open, view, and manipulate images, including cropping, resizing, recoloring, and overlaying text
  • The python Pytesseract library will be used with Python in order to detect text in images through optical character recognition (OCR).
  • The open-source computer vision library OpenCV will be used to detect faces in images, and how to crop and manipulate these faces into contact sheets.

 

These will be the basic application of these dependencies that will be used in this project.

 

Datasets

There are two datasets that will be used.

  • small_size_images
  • Large_size_images

The dataset is provided within the zip file. As mentioned we will be using two different datasets. One which is of small size for the reason for faster computation and another which is much larger which will take a longer time.

 

If you want to use your own dataset all you need to do is:

if you have your dataset already within a directory then,

pages_list=os.listdir('small_size_iamges')#within the quotes type your directory name

or,

if your dataset is within a zip file then follow the below technique.

for this, we will be importing zipfile library.

os.mkdir('large_size_images')
local_zip = 'datasets/large_size_images.zip' #change this line to  the location of your dataset
zip_ref = zipfile.ZipFile(local_zip, 'r')
zip_ref.extractall('small_img')
zip_ref.close()

 

Both methods have been used in the notebook for better understanding.

 

 

Download Complete Code

Comments

No comments yet

Download Packet

Reviews Report

Submitted by Adarsh Hiremath (adarshhiremath)

Download packets of source code on Coders Packet