izaskunmz
adding predict.py
fe47b1a
raw
history blame
756 Bytes
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()