[Python] YOLOv8, display bounding boxes on the screen

Discussão em 'Python' iniciado por Stack, Março 7, 2025.

  1. Stack

    Stack Membro Participativo

    How to display bounding boxes directly on the screen? Its not a video, so I can't use tracking. My program captures the whole screen and checks for Objects. I researched that CV can help me with that but I can't get it to work

    from ultralytics import YOLO
    import pyautogui
    import cv2
    import numpy as np

    # Load the model
    model_path = 'C:/Users/toto/Desktop/DETECT/best.pt'
    model = YOLO(model_path)

    # Set the confidence threshold
    conf_threshold = 0.4

    # Capture the entire screen
    screen_image = pyautogui.screenshot()
    screen_image = cv2.cvtColor(np.array(screen_image), cv2.COLOR_RGB2BGR)

    # Perform object detection on the captured screen image
    results = model(screen_image)


    my code output

    0: 384x640 3 Objects, 70.1ms
    Speed: 4.5ms preprocess, 70.1ms inference, 1.0ms postprocess per image at shape (1, 3, 384, 640)

    Continue reading...

Compartilhe esta Página