Seçkin Üye
Hangi mause
path = "BURAYA FOTOĞRAF YOLU BELİRT !!!!!!!!!!!!!!"
template_img = cv2.imread(path)
screen_width, screen_height = pyautogui.size()
window_size = 400
window_half = window_size // 2
window_top_left = (screen_width // 2 - window_half, screen_height // 2 - window_half)
window_bottom_right = (screen_width // 2 + window_half, screen_height // 2 + window_half)
screen_img = ImageGrab.grab(bbox=(window_top_left[0], window_top_left[1],
window_bottom_right[0], window_bottom_right[1]))
screen_np = np.array(screen_img)
res = cv2.matchTemplate(screen_np, template_img, cv2.TM_CCOEFF_NORMED)
threshold = 0.8
loc = np.where(res >= threshold)
for pt in zip(*loc[::-1]):
x = pt[0] + window_top_left[0] + template_img.shape[1] // 2
y = pt[1] + window_top_left[1] + template_img.shape[0] // 2
if is_point_inside_image(x, y, window_top_left, window_bottom_right):
move_cursor(x, y)
def move_cursor(x, y):
pyautogui.moveTo(x, y)
cv2.imshow("Oyun Ekrani", cv2.cvtColor(np.array(screen_img), cv2.COLOR_RGB2BGR))
if cv2.waitKey(1) & 0xFF == ord('q'):
break