ImageGrab and PyTesseract
ImageGrab is a Python module that helps to capture the contents of the screen. PyTesseract is an Optical Character Recognition(OCR) tool for Python. Together they can be used to read the contents of a section of the screen.
Pillow (a newer version of PIL)
pip install Pillow
PyTesseractpip install pytesseract
Apart from this, a tesseract executable needs to be installed.
Implementation of code
The following functions were primarily used in the code –
pytesseract.image_to_string(image, lang=**language**) – Takes the image and searches for words of the language in their text.
cv2.cvtColor(image, **colour conversion**) – Used to make the image monochrome(using cv2.COLOR_BGR2GRAY).
ImageGrab.grab(bbox=**Coordinates of the area of the screen to be captured**) – Used to repeatedly(using a loop) capture a specific part of the screen.
The objectives of the code are:
- To use a loop to repeatedly capture a part of the screen.
- To convert the captured image into grayscale.
- Use PyTesseract to read the text in it.
Code : Python code to use ImageGrab and PyTesseract
The above code can be used to capture a certain section of the screen and read the text contents of it.
Read about other libraries used in the code
- Python PIL | ImageGrab.grabclipboard() method
- Python PIL | ImageGrab.grab() method
- Python - Read blob object in python using wand library
- Python | Merge Python key values to list
- Python | Index of Non-Zero elements in Python list
- Important differences between Python 2.x and Python 3.x with examples
- Reading Python File-Like Objects from C | Python
- Python | Convert list to Python array
- MySQL-Connector-Python module in Python
- Python | PRAW - Python Reddit API Wrapper
- Python | Add Logging to Python Libraries
- Python | Add Logging to a Python Script
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Sort Python Dictionaries by Key or Value
- Python | Visualizing O(n) using Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.