-
Notifications
You must be signed in to change notification settings - Fork 0
/
only-yolo.py
33 lines (24 loc) · 885 Bytes
/
only-yolo.py
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
30
31
32
33
import cv2
from ultralytics import YOLO
model = YOLO("runs/detect/train2/weights/best.pt")
cap = cv2.VideoCapture("data/p3.mp4")
assert cap.isOpened(), "Error leyendo el archivo de video"
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
results = model(frame)
for result in results:
for box in result.boxes:
x1, y1, x2, y2 = map(int, box.xyxy[0].tolist())
label = int(box.cls)
confidence = box.conf.item()
if label == 3:
label = "Auto"
cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
cv2.putText(frame, f"{label} {confidence:.2f}", (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
cv2.imshow("Vehicle Detection", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()