1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| import time
import os
import random
from pymemuc import PyMemuc
import pyautogui
import pyperclip
import cv2
def save_screenshot(file_path):
screen_shot = pyautogui.screenshot()
screen_shot.save(file_path)
def find_word_coordinates(image_path, word):
image = cv2.imread(image_path)
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
template = cv2.imread(f'C:\\Users\\Damien\\Pictures\\bouton_{num_bouton}.png', 0)
width, height = template.shape[::-1]
result = cv2.matchTemplate(gray_image, template, cv2.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
if max_val > 0.8:
x, y = max_loc
return x + width / 2, y + height / 2
else:
return None
screenshot_file = 'C:\\Users\\'+ username +'\\Pictures\\screenshot.png'
save_screenshot(screenshot_file)
screenshot_file = 'C:\\Users\\'+ username +'\\Pictures\\screenshot.png'
save_screenshot(screenshot_file)
num_bouton = num_bouton + 1 #1
word = 'bouton_1'
coordinates = find_word_coordinates(screenshot_file, word)
if coordinates is not None:
pyautogui.click(coordinates[0], coordinates[1])
time.sleep(5)
else:
print(f"'{word}' n'a pas été trouvé dans l'image.")
time.sleep(5)
screenshot_file = 'C:\\Users\\'+ username +'\\Pictures\\screenshot.png'
save_screenshot(screenshot_file)
num_bouton = num_bouton + 1 #2
word = 'bouton_2'
coordinates = find_word_coordinates(screenshot_file, word)
if coordinates is not None:
pyautogui.click(coordinates[0], coordinates[1])
time.sleep(5)
else:
print(f"'{word}' n'a pas été trouvé dans l'image.")
time.sleep(5) |
Partager