-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject_detection.py
More file actions
36 lines (30 loc) · 844 Bytes
/
Copy pathobject_detection.py
File metadata and controls
36 lines (30 loc) · 844 Bytes
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
34
35
36
import sys
from ultralytics import YOLO
import cv2
import numpy as np
import time
model = YOLO("best.pt", task="detect")
print("model loaded")
CONF_THRESH = 20
def obj_det(im_name, img, show, Ev3):
results = model(img, show=show, imgsz=640)
if show:
cv2.waitKey()
result = results[0]
classes = result.boxes.cls.tolist()
boxes = result.boxes.xyxy.tolist()
"""traffic signs {0:traffic_light, 1:stop, 2:speedlimit, 3:crosswalk, 4:redlight, 5:greenlight}"""
for x in classes:
print(x)
if x == 4:
return True
elif x == 1:
Ev3.write("s\n")
time.sleep(3)
return True
return False
if __name__ == "__main__":
while True:
input()
args = sys.argv[1:]
print(obj_det(args[0], cv2.imread(args[0]), True, None))