DEV Community

Cover image for 3-lines code to detect text from an image in python
M.V.S.Sai hiranmayee
M.V.S.Sai hiranmayee

Posted on

3-lines code to detect text from an image in python

Using Tesseract library, we can detect the text from an image in 3 lines of code.

Step-1:
Install teserract library
In command prompt: pip install pytesseract
In Anaconda prompt: conda install -c conda-forge pytesseract

Step-2:
Download and install the Tesseract OCR executable from the following links
https://digi.bib.uni-mannheim.de/tesseract/tesseract-ocr-w32-setup-v5.0.0-alpha.20210506.exe (32-bit)
https://digi.bib.uni-mannheim.de/tesseract/tesseract-ocr-w64-setup-v5.0.0-alpha.20210506.exe (64-bit)

Step-3:
And run the below given code to extract text from an image

import pytesseract

pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract'

print(pytesseract.image_to_string(r'link to the image from which the text to be detected'))

Image description

Top comments (0)