Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -184,18 +184,40 @@
|
|
| 184 |
|
| 185 |
###
|
| 186 |
|
| 187 |
-
import gradio as gr
|
| 188 |
-
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
import cv2
|
|
|
|
| 190 |
|
| 191 |
-
|
| 192 |
-
model
|
| 193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
annotated_img = results.render()[0]
|
| 198 |
-
return annotated_img
|
| 199 |
|
| 200 |
-
|
| 201 |
-
|
|
|
|
| 184 |
|
| 185 |
###
|
| 186 |
|
| 187 |
+
# import gradio as gr
|
| 188 |
+
# import torch
|
| 189 |
+
# import cv2
|
| 190 |
+
|
| 191 |
+
# # Load the YOLOv8 model
|
| 192 |
+
# model = torch.hub.load('ultralytics/yolov8', 'yolov8s', trust_repo=True)
|
| 193 |
+
# model.load_state_dict(torch.load('Model_IV'))
|
| 194 |
+
|
| 195 |
+
# def inference(img):
|
| 196 |
+
# results = model(img)
|
| 197 |
+
# annotated_img = results.render()[0]
|
| 198 |
+
# return annotated_img
|
| 199 |
+
|
| 200 |
+
# iface = gr.Interface(fn=inference, inputs="webcam", outputs="image")
|
| 201 |
+
# iface.launch()
|
| 202 |
+
|
| 203 |
import cv2
|
| 204 |
+
from ultralytics import YOLO
|
| 205 |
|
| 206 |
+
model = YOLO('Model_IV.pt')
|
| 207 |
+
print(model.names)
|
| 208 |
+
webcamera = cv2.VideoCapture(0)
|
| 209 |
+
# webcamera.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
|
| 210 |
+
# webcamera.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
|
| 211 |
+
|
| 212 |
+
while True:
|
| 213 |
+
success, frame = webcamera.read()
|
| 214 |
+
|
| 215 |
+
results = model.track(frame, conf=0.2, imgsz=480)
|
| 216 |
+
cv2.putText(frame, f"Total: {len(results[0].boxes)}", (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 217 |
+
cv2.imshow("Live Camera", results[0].plot())
|
| 218 |
|
| 219 |
+
if cv2.waitKey(1) == ord('q'):
|
| 220 |
+
break
|
|
|
|
|
|
|
| 221 |
|
| 222 |
+
webcamera.release()
|
| 223 |
+
cv2.destroyAllWindows()
|