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
from PIL import Image import pytesseract print (pytesseract.image_to_string(Image.open('test.png')))
That’s it. here in this line
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
And here are OCR results of above images are
Test2.png OCR 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..