Python | Using PIL ImageGrab and PyTesseract Last Updated : 13 Oct, 2019 Comments Improve Suggest changes Like Article 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 More infoAdvertise with us Next Article Python | Using PIL ImageGrab and PyTesseract R RuturajM Follow Improve Article Tags : Project Python Programming Language Python Programs Image-Processing Python-pil +2 More Practice Tags : python Similar Reads How to compress images using Python and PIL? There are organizations who receive data form lakhs or more persons, which is mostly in form of text, with a few images. Most of you know that the text part is stored in databases in the form of tables, but what about the images? The images are small compared to the textual data but constitute a muc 3 min read Python | Copy and Paste Images onto other Image using Pillow In this article, we will learn how to copy an image over another image using pillow library. We will use image module from pillow and copy() and paste() methods to achieve this task. We will need to create copies of both images so that it does not affect the original image with the help of copy() me 2 min read Python Nameerror: Name 'Imagedraw' is Not Defined Python, being a versatile and dynamic programming language, is widely used for various applications, including image processing. However, as with any programming language, errors can occur. One common issue that developers encounter is the "NameError: name 'ImageDraw' is not defined." This error can 3 min read How to Convert PIL Image into pygame surface image? In this article, we will know How to Convert PIL Image into pygame surface image. Pygame Surface Image: A surface that not only has fixed resolution and pixel format but also represents the image in Pygame is known as Pygame Surface Image. Are you constructing any game in Pygame in which you want t 4 min read Image Enhancement in PIL The Python Imaging Library(PIL) adds powerful image processing capabilities. It provides immense file format support, an efficient representation, and fairly powerful image processing capabilities. The core image library is intended for fast access to data stored in very few basic pixel formats. It 4 min read Like