neuro-mkr/live.py

25 lines
470 B
Python
Raw Permalink Normal View History

2025-12-04 13:19:41 +02:00
from ultralytics import YOLO
import json
import cv2 as cv
m = YOLO("best.pt")
c = cv.VideoCapture(0)
while True:
_, frame = c.read()
res = m(frame)
for i in json.loads(res[0].to_json()):
i = i['box']
cv.rectangle(frame, (round(i['x1']), round(i['y1'])), (round(i['x2']), round(i['y2'])), (0, 0, 255), 3)
#print(i)
cv.imshow('frame', frame)
if cv.waitKey(1) == ord('q'):
break
c.release()
cv.destroyAllWindows()