izaskunmz commited on
Commit
fe47b1a
1 Parent(s): 5ea5177

adding predict.py

Browse files
Files changed (1) hide show
  1. predict.py +28 -0
predict.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ from ultralytics import YOLO
3
+
4
+ # Cargar modelo YOLOv8 entrenado
5
+ model = YOLO("/home/izaskunmz/yolo/yolov8-object-detection/runs/detect/train_yolov8s_v4/weights/best.pt")
6
+
7
+ # Abrir v铆deo
8
+ video_path = "/ruta/al/video.mp4"
9
+ cap = cv2.VideoCapture(video_path)
10
+
11
+ while cap.isOpened():
12
+ ret, frame = cap.read()
13
+ if not ret:
14
+ break # Si el v铆deo ha terminado, salimos del bucle
15
+
16
+ # Realizar detecci贸n en el frame
17
+ results = model(frame)
18
+
19
+ # Mostrar el frame con detecciones
20
+ annotated_frame = results[0].plot() # Dibuja las detecciones en el frame
21
+ cv2.imshow("YOLOv8 Detecci贸n", annotated_frame)
22
+
23
+ # Salir con la tecla "q"
24
+ if cv2.waitKey(1) & 0xFF == ord('q'):
25
+ break
26
+
27
+ cap.release()
28
+ cv2.destroyAllWindows()