File size: 756 Bytes
fe47b1a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import cv2
from ultralytics import YOLO

# Cargar modelo YOLOv8 entrenado
model = YOLO("/home/izaskunmz/yolo/yolov8-object-detection/runs/detect/train_yolov8s_v4/weights/best.pt")

# Abrir vídeo
video_path = "/ruta/al/video.mp4"
cap = cv2.VideoCapture(video_path)

while cap.isOpened():
    ret, frame = cap.read()
    if not ret:
        break  # Si el vídeo ha terminado, salimos del bucle

    # Realizar detección en el frame
    results = model(frame)

    # Mostrar el frame con detecciones
    annotated_frame = results[0].plot()  # Dibuja las detecciones en el frame
    cv2.imshow("YOLOv8 Detección", annotated_frame)

    # Salir con la tecla "q"
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()