Привязка скрипта python к определенному окну виндовс ( игре wow)

Есть скрипт Python , который следит за экраном игры wow, если появляется каптча, скрипт делая скриншоты экрана , видит что появилась каптча и делает действия по её решению.

Как сделать так, чтобы скрипт или скриншоты делались именно в определенном окне. Как привязать к приложению скрипт или именно функцию скриншотов.

Сейчас мне нужно чтобы у меня на экране была игра, чтоб он работал. А я хочу, чтобы я мог делать свои дела и скриншоты делались именно игры, а не рабочего стола, это возможно?

import time
import pytesseract
import cv2
import numpy as np
import pyautogui
from PIL import ImageGrab
import math
from PIL import Image
from PIL import ImageChops
import imagehash


pytesseract.pytesseract.tesseract_cmd = r'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
average = [0, ]



def reshenie():
    pyautogui.moveTo(140, 270, 0.3)
    pyautogui.click()

    base_screen = ImageGrab.grab(bbox=(814, 145, 1108, 170))
    base_screen.save('/Users/9/Documents/bot/base_screen.png')


    template = cv2.imread('base_screen.png', 0)
    w, h = template.shape[::-1]

     
    img_rgb = cv2.imread('base_screen.png')
    img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
    scale_percent = 400
    width = int(img_gray.shape[1] * scale_percent / 100)
    height = int(img_gray.shape[0] * scale_percent / 100)
    dim = (width, height)
    resized_img = cv2.resize(img_gray, dim, interpolation=cv2.INTER_AREA)

    blur_img = cv2.GaussianBlur(resized_img, (3, 3), 0)
    blur_img = cv2.medianBlur(blur_img, 3)

    thresh, new_img = cv2.threshold(blur_img, 0, 255, cv2.THRESH_OTSU |cv2.THRESH_BINARY)

    config = r'--oem 3 --psm 6 -c tessedit_char_whitelist=0123456789-+?='
    print(pytesseract.image_to_string(new_img, config=config))
    l = pytesseract.image_to_string(new_img, config=config)
    l = l.replace('?', '')
    l = l.replace('=', '')
    l = l.strip()


    a = ''
    b = ''

    for i in range(3):
        a = l[:l.index('+'):1]
        i += 1

    for i in range(3):
        b = l[l.index('+')+1::1]
        i += 1


     

    pyautogui.moveTo(874, 176, 0.3)
    pyautogui.click()

    print(int(a)+int(b))
    b = int(a)+int(b)
    b = str(b)
    pyautogui.write(b)

    pyautogui.moveTo(874, 222, 0.3)
    pyautogui.click()
    time.sleep(2)

while True:
    try:
        base_screen1 = ImageGrab.grab(bbox=(21, 135, 317, 319))
        base_screen1.save('/Users/9/Documents/bot/base_screen1.png')

        img_1 = Image.open(r'base_screen1.png')
        img_2 = Image.open(r'captcha.png')
        hash = imagehash.average_hash(Image.open('captcha.png'))
        hash2 = imagehash.average_hash(Image.open('base_screen1.png'))
        if hash == hash2:
            reshenie()
        else:
            continue
    except KeyboardInterrupt:
        time.sleep(5)
        continue
    except PermissionError:
        time.sleep(5)
        continue
    except ValueError:
        time.sleep(5)
        continue
    except OSError:
        time.sleep(5)
        continue

Ответы (0 шт):