mike-silva-fairportrobotics
commited on
Commit
•
bc5b711
1
Parent(s):
5421aab
Update README.md
Browse files
README.md
CHANGED
@@ -73,4 +73,69 @@ plt.imshow(plt.imread('detected/sample.jpg'))
|
|
73 |
plt.show()
|
74 |
```
|
75 |
|
76 |
-
As you can see the model isn't perfect ;)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
plt.show()
|
74 |
```
|
75 |
|
76 |
+
As you can see the model isn't perfect ;)
|
77 |
+
|
78 |
+
|
79 |
+
### Use the model with your webcam
|
80 |
+
|
81 |
+
```
|
82 |
+
from ultralytics import YOLO
|
83 |
+
import cv2
|
84 |
+
import math
|
85 |
+
from huggingface_hub import hf_hub_download
|
86 |
+
|
87 |
+
# start the webcam
|
88 |
+
cap = cv2.VideoCapture(0)
|
89 |
+
cap.set(3, 640)
|
90 |
+
cap.set(4, 480)
|
91 |
+
|
92 |
+
# Load the weights from our repository
|
93 |
+
model_path = hf_hub_download(
|
94 |
+
local_dir=".",
|
95 |
+
repo_id="fairportrobotics/rock-paper-scissors",
|
96 |
+
filename="model.pt"
|
97 |
+
)
|
98 |
+
model = YOLO(model_path)
|
99 |
+
|
100 |
+
# object classes
|
101 |
+
classNames = ["rock", "paper", "scissors"]
|
102 |
+
|
103 |
+
|
104 |
+
while True:
|
105 |
+
success, img = cap.read()
|
106 |
+
results = model(img, stream=True)
|
107 |
+
|
108 |
+
# coordinates
|
109 |
+
for r in results:
|
110 |
+
boxes = r.boxes
|
111 |
+
|
112 |
+
for box in boxes:
|
113 |
+
# bounding box
|
114 |
+
x1, y1, x2, y2 = box.xyxy[0]
|
115 |
+
x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2) # convert to int values
|
116 |
+
|
117 |
+
# put box in cam
|
118 |
+
cv2.rectangle(img, (x1, y1), (x2, y2), (255, 0, 255), 3)
|
119 |
+
|
120 |
+
# confidence
|
121 |
+
confidence = math.ceil((box.conf[0]*100))/100
|
122 |
+
|
123 |
+
# class name
|
124 |
+
cls = int(box.cls[0])
|
125 |
+
|
126 |
+
# object details
|
127 |
+
org = [x1, y1]
|
128 |
+
font = cv2.FONT_HERSHEY_SIMPLEX
|
129 |
+
fontScale = 1
|
130 |
+
color = (255, 0, 0)
|
131 |
+
thickness = 2
|
132 |
+
|
133 |
+
cv2.putText(img, classNames[cls] + " " + str(round(confidence,2)), org, font, fontScale, color, thickness)
|
134 |
+
|
135 |
+
cv2.imshow('Webcam', img)
|
136 |
+
if cv2.waitKey(1) == ord('q'):
|
137 |
+
break
|
138 |
+
|
139 |
+
cap.release()
|
140 |
+
cv2.destroyAllWindows()
|
141 |
+
```
|