python avec ia pr suivie avec un calque
python avec ia pr suivie avec un calque
import cv2
import pyautogui
import tkinter as tk
import win32gui
import win32con
import win32api
import time
import tensorflow as tf
class OverlayWindow:
def __init__(self):
self.root = tk.Tk()
self.root.attributes('-alpha', 0.6)
self.root.attributes('-topmost', True)
self.root.overrideredirect(True)
self.root.configure(bg='#FF0000')
self.hwnd = win32gui.GetParent(self.root.winfo_id())
extended_style = win32gui.GetWindowLong(self.hwnd, win32con.GWL_EXSTYLE)
win32gui.SetWindowLong(self.hwnd, win32con.GWL_EXSTYLE,
extended_style | win32con.WS_EX_TRANSPARENT |
win32con.WS_EX_LAYERED)
self.size = 35
self.root.withdraw()
class CupTracker:
def __init__(self):
self.overlay = OverlayWindow()
self.tracking_active = False
self.cup_position = None
self.initial_position = None
self.initial_template = None
pyautogui.PAUSE = 0
screenshot = np.array(pyautogui.screenshot())
frame = cv2.cvtColor(screenshot, cv2.COLOR_RGB2BGR)
y1, y2 = max(0, y-20), min(frame.shape[0], y+20)
x1, x2 = max(0, x-20), min(frame.shape[1], x+20)
self.initial_template = frame[y1:y2, x1:x2]
self.overlay.show(x, y)
self.tracking_active = True
try:
x, y = target_pos
search_width = 400
x1 = max(0, x - search_width//2)
y1 = max(0, y - search_width//2)
x2 = min(frame.shape[1], x + search_width//2)
y2 = min(frame.shape[0], y + search_width//2)
return target_pos
except Exception as e:
print(f"Error: {e}")
return target_pos
def track_game(self):
print("Clic droit sur le gobelet à suivre")
print("Q pour quitter")
last_right_click = False
try:
while True:
current_right_click = win32api.GetKeyState(win32con.VK_RBUTTON) < 0
if self.tracking_active:
screenshot = np.array(pyautogui.screenshot())
frame = cv2.cvtColor(screenshot, cv2.COLOR_RGB2BGR)
finally:
self.overlay.root.destroy()
if __name__ == "__main__":
tracker = CupTracker()
tracker.track_game()