OK its way better now but sitll noticed 2 major problems if not 3. The boxes are in a…
- User
OK its way better now but sitll noticed 2 major problems if not 3. The boxes are in a fixed state and wont disappear even though theres no enemies it still writes enemy detected, and the box is still there when isnt suppost to. also the localplayer box is in a fixed state and not following the player character. Also after sometime when its done observing all the frames the screen goes frozen instead of continuing. And shouldnt it observ all the frames first and only then after doing it so, to try display the boxes / box based on the visualized frames in real time game?
Local player detected! Enemy detected! Local player detected! Enemy detected! Local player detected! Enemy detected! Local player detected! Enemy detected! Local player detected! Enemy detected! Local player detected! Enemy detected! Local player detected! Enemy detected! Local player detected! Enemy detected! Local player detected! Enemy detected! Local player detected! Enemy detected! Local player detected! Enemy detected! Local player detected! Enemy detected! Local player detected! Enemy detected! Done watching all frames. Press Ctrl + C to exit. Script interrupted by user. Exiting...
Heres the code
import os import cv2 import pygetwindow as gw from PIL import ImageGrab import numpy as np
MAX_EPISODE_LENGTH = 1000 # Define MAX_EPISODE_LENGTH here
Function to check if the game is open
def is_game_open(): game_window = gw.getWindowsWithTitle('Superfighters Deluxe') return bool(game_window)
Function to draw dynamic boxes based on local player and enemy coordinates
def draw_boxes(window, local_player_box, enemy_box): # Capture the game window pixels frame = np.array(ImageGrab.grab(bbox=(window.left, window.top, window.right, window.bottom)))
# Draw dynamic boxes based on local player and enemy coordinates color = (0, 255, 0) # Green color for bounding boxes (you can adjust this) if local_player_box is not None: x_lp, y_lp, w_lp, h_lp = local_player_box cv2.rectangle(frame, (x_lp, y_lp), (x_lp + w_lp, y_lp + h_lp), color, 2) cv2.putText(frame, "localPlayer", (x_lp, y_lp - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2) if enemy_box is not None: x_enemy, y_enemy, w_enemy, h_enemy = enemy_box cv2.rectangle(frame, (x_enemy, y_enemy), (x_enemy + w_enemy, y_enemy + h_enemy), color, 2) cv2.putText(frame, "enemy", (x_enemy, y_enemy - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2) cv2.imshow("Annotated Frame", frame) cv2.waitKey(1)Function to process a frame
def process_frame(frame): # Replace this with your actual logic local_player_box = (50, 50, 100, 100) enemy_box = (150, 150, 100, 100) return local_player_box, enemy_box
Function to visualize and process frames
def visualize_and_process_frames(): try: game_window = gw.getWindowsWithTitle('Superfighters Deluxe')[0]
# Initialize variables for dynamic box coordinates local_player_box = None enemy_box = None for t in range(6, MAX_EPISODE_LENGTH, 6): # Process the frame local_player_box, enemy_box = process_frame(None) # Replace None with your actual frame # Visualize the frame with dynamic boxes draw_boxes(game_window, local_player_box, enemy_box) # Print the results (replace with your actual logic) if local_player_box is not None: print("Local player detected!") if enemy_box is not None: print("Enemy detected!") cv2.waitKey(1) print("Done watching all frames. Press Ctrl + C to exit.") while True: cv2.waitKey(1) except KeyboardInterrupt: print("Script interrupted by user. Exiting...") - Assistant