OCR In Linux using python

2019-09-11 Shashank Dharasurkar Download Code

Hello programmers, today we are going to perform OCR operation on image using python on Linux operating system. Before start coding let’s get to know

What is OCR ?

Optical character recognition or optical character reader (OCR) is the mechanical or electronic conversion of images of typed, handwritten or printed text into machine-encoded text, whether from a scanned document, a photo of a document, a scene-photo (for example the text on signs and billboards in a landscape photo) or from subtitle text superimposed on an image (for example from a television broadcast).

 

So I hope you got basic idea about what is OCR and how it can be applied. So we are ready to perform OCR operation.  To do this we have to complete following conditions.

 

Linux operating system (Latest one)

Python 3.x installed

 

After satisfying above requirements we need few libraries like Pillow, Pytesseract.  To install this libraries just open terminal and enter following commands

pip3 install Pillow

pip3 install pytesseract

 

After installing libraries we have done almost operation. now for coding open terminal and type following code

Code:

 

from PIL import Image 
import pytesseract 
print (pytesseract.image_to_string(Image.open('test.png')))

 

That’s it. here in this line

print (pytesseract.image_to_string(Image.open('test.png')))

 test.png is an sample image we used to do OCR operation. we also used another image as test2.png as sample image and results are

 

test

Test.png

test2

Test2.png

 

And here are OCR results of above images are

ocr_result

Test2.png OCR result:

ocr_test_2_result

 

So here it ends. You have completed performed OCR operation. You can use any other image instead of test image. Sooner we will try to bring this program in windows also. Till then try it with your own and any problem persist feel free to comment below and also help us grow big by sharing this with your programmer friend circle.

Thank you.. Happy Coding..


About author

Card image cap
Shashank Dharasurkar

I’m a full-stack developer, with a fundamental knowledge of programming experience on Computer Vision and Automation like Opencv, python-Gui, python and Interested in computers and machine learning and also likes to write about it!!

-Python Developer

0 Comments