Python Forum

Full Version: how to take a screnshot by Pyautogui automatically and randomly
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
objective i want to extract text from image. i play a game which an icon appears randomly ,and there is a text(text as image) near to the icon from the right. i want the script take screenshot of the region of the text only. so, i want the script every time he locatonscreen the i con, i want him take screen shot of the text. here is an image to understand the idea :
[Image: 751Vm.png]

this is my code:

import pyautogui as py
import time
from PIL import Image
from pytesseract import *

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

while 1:
        indice1 = py.locateOnScreen("icon.png")
    
    if indice1:
        
        print("indice see it ")

        myScreenshot = py.screenshot()
        myScreenshot.save(r'C:\Users\rachidel07\Desktop\ok\venv\image.png')

        img=Image.open("image.png")
        output = pytesseract.image_to_string(img)
        print(output)

    else:
            print ("non")