Created
May 4, 2025 12:35
-
-
Save C-ffeeStain/171577465cdcca29f966e67b521187b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
import pyautogui | |
import time | |
def find_image_on_screen(template_path): | |
# Load the template image | |
template = cv2.imread(template_path, cv2.IMREAD_GRAYSCALE) | |
template_height, template_width = template.shape | |
# Capture the screen | |
screen = pyautogui.screenshot() | |
screen = cv2.cvtColor(np.array(screen), cv2.COLOR_RGB2GRAY) | |
# Perform template matching | |
result = cv2.matchTemplate(screen, template, cv2.TM_CCOEFF_NORMED) | |
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) | |
# Define a threshold for a good match | |
threshold = 0.8 | |
if max_val >= threshold: | |
# Get the top-left corner of the match | |
top_left = max_loc | |
bottom_right = (top_left[0] + template_width, top_left[1] + template_height) | |
# Return the center of the match | |
center_x = top_left[0] + template_width // 2 | |
center_y = top_left[1] + template_height // 2 | |
return center_x, center_y | |
return None | |
def main(): | |
template_path = 'join.png' | |
template_path2 = 'live.png' | |
template_path3 = 'speakers.png' | |
template_path4 = 'close_chat.png' | |
while True: | |
position = find_image_on_screen(template_path) | |
# 'Join Stage' button | |
if position: | |
x, y = position | |
pyautogui.moveTo(x, y) | |
pyautogui.click() | |
print("Got kicked off stage, joined again!") | |
position = find_image_on_screen(template_path2) | |
speakers = find_image_on_screen(template_path3) | |
# If someone is streaming in the stage, full screen it | |
if position and speakers and speakers[1] < 750 and position[1] < 360: | |
x, y = position | |
pyautogui.moveTo(x, y) | |
pyautogui.click() | |
pyautogui.click() | |
pyautogui.moveTo(10, 10) | |
print(f"Found a live stage!") | |
position = find_image_on_screen(template_path4) | |
# X button to close chat | |
if position: | |
x, y = position | |
if x > 1800 and y > 30: | |
pyautogui.moveTo(x, y) | |
pyautogui.click() | |
print("Chat was opened, closing.") | |
# Wait for 5 seconds before the next check | |
time.sleep(5) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment