-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
31 lines (24 loc) · 957 Bytes
/
app.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
import cv2
import supervision as sv
from ultralytics import YOLO
from supervision import BoxAnnotator
model = YOLO("best.pt")
box_annotator = BoxAnnotator(text_thickness=1)
def main():
cam = cv2.VideoCapture(0)
while cam.isOpened():
success, frame = cam.read()
if success:
predictions = model(frame)[0]
detections = sv.Detections.from_ultralytics(predictions)
labels = [f"{model.model.names[class_id]}--{confidence:.2f}" for class_id, confidence in zip(detections.class_id, detections.confidence)]
annotated_frame = box_annotator.annotate(scene=frame, detections=detections, labels=labels)
cv2.imshow("Detection", annotated_frame)
if cv2.waitKey(1) == ord("q"):
break
else:
raise("Can't Open Camera")
cam.release()
cv2.destroyAllWindows()
if __name__ == "__main__":
main()