Python | Using PIL ImageGrab and PyTesseract Last Updated : 12 Jul, 2025 Comments Improve Suggest changes 4 Likes Like Report 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. Installation - Pillow (a newer version of PIL) pip install Pillow PyTesseract pip 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 Python3 # cv2.cvtColor takes a numpy ndarray as an argument import numpy as nm import pytesseract # importing OpenCV import cv2 from PIL import ImageGrab def imToString(): # Path of tesseract executable pytesseract.pytesseract.tesseract_cmd ='**Path to tesseract executable**' while(True): # ImageGrab-To capture the screen image in a loop. # Bbox used to capture a specific area. cap = ImageGrab.grab(bbox =(700, 300, 1400, 900)) # Converted the image to monochrome for it to be easily # read by the OCR and obtained the output String. tesstr = pytesseract.image_to_string( cv2.cvtColor(nm.array(cap), cv2.COLOR_BGR2GRAY), lang ='eng') print(tesstr) # Calling the function imToString() Output 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 Numpy OpenCV(cv2) Comment R RuturajM Follow 4 Improve R RuturajM Follow 4 Improve Article Tags : Project Python Programming Language Python Programs Image-Processing Python-pil +2 More Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 5 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 2 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 7 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 15+ min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 8 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Python | Build a REST API using Flask 3 min read How to Create a basic API using Django Rest Framework ? 4 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like