-
Notifications
You must be signed in to change notification settings - Fork 2
/
object_detect.py
43 lines (32 loc) · 1.15 KB
/
object_detect.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
34
35
36
37
38
39
40
41
42
43
import sys
import cv2
import numpy as np
from ultralytics import YOLO
import ic_utils as ic
def main():
model = YOLO("yolov8n.pt")
cap = ic.select_capture_source(sys.argv)
while True:
grabbed, frame = cap.read()
if not grabbed:
break
img_disp = frame.copy()
#results = model(source=frame, verbose=True, show=True)
results = model(source=frame, verbose=False, show=False)
#for r in results: # loop through source images (single r in this case)
for box in results[0].boxes.data:
obj_info = box.cpu().numpy()
xmin, ymin, xmax, ymax, confidence, class_id = obj_info
cv2.rectangle(img_disp,
np.int16([xmin, ymin]), np.int16([xmax, ymax]),
(255, 0, 0), 2)
ic.putText(img_disp,
model.names[int(class_id)] + ' ' + str(confidence),
np.int16([xmin, ymin - 5]), (0, 255, 0))
cv2.imshow('yolo', img_disp)
key = cv2.waitKey(30)
if key == ord('q'):
break
cv2.destroyAllWindows()
if __name__ == '__main__':
main()