import time import numpy as np import pyscreenshot as ImageGrab import cv2 import os import pytesseract import pyautogui import pyperclip from mss import mss from PIL import Image monitor = { "left": 8, "top": 31, "width": 845, "height": 785, } # Поиск цвета на экране def find_color(our_color, monitor={}): # Возмём кусок экрана m = mss() # Получаем пиксель с экрана монитора img = m.grab(monitor) # Преобразуем этот пиксель в матрицу img_arr = np.array(img) # Поиск цвета (b, g, r, alpha) our_map = (our_color[2], our_color[1], our_color[0], 255) indexes = np.where(np.all(img_arr == our_map, axis=-1)) our_crd = np.transpose(indexes) return our_crd # Искомый цвет our_color = [3, 121, 229] while True: time1 = time.time() result = find_color(our_color, monitor) time2 = time.time() if result.__len__(): xin = result[0][1] + monitor.get('left') yin = result[0][0] + monitor.get('top') print(time2 - time1, [xin, yin]) break else: pyautogui.leftClick(717, 314) xina = int(xin) + 275 yina = int(yin) + 58 print(xina, yina) print(xin, yin) filename = 'Image.png' x = 1 last_time = time.time() m = ImageGrab.grab(bbox=(xin, yin, xina, yina)) m.save('Image.png') cv2.cvtColor(np.array(m), cv2.COLOR_BGR2GRAY) m = cv2.imread('Image.png') text = pytesseract.image_to_string(m) print(text) pyperclip.copy(text) pyautogui.PAUSE = 0.1 pyperclip.paste() pyautogui.moveTo(1141,497) pyautogui.tripleClick() pyautogui.hotkey('ctrl','v') pyautogui.hotkey('backspace') pyautogui.moveTo(1143,596) pyautogui.leftClick() pyautogui.moveTo(1682,975) pyautogui.leftClick() pyautogui.PAUSE = 0.4 pyautogui.moveTo(1414,706) pyautogui.leftClick()