Spaces:
Runtime error
Runtime error
beverage model
Browse files
app.py
CHANGED
|
@@ -26,7 +26,7 @@ for i, url in enumerate(file_urls):
|
|
| 26 |
f"image_{i}.jpg"
|
| 27 |
)
|
| 28 |
|
| 29 |
-
model = YOLO('
|
| 30 |
path = [['image_0.jpg'], ['image_1.jpg']]
|
| 31 |
video_path = [['video.mp4']]
|
| 32 |
|
|
@@ -35,7 +35,9 @@ def show_preds_image(image_path):
|
|
| 35 |
image = cv2.imread(image_path)
|
| 36 |
outputs = model.predict(source=image_path)
|
| 37 |
results = outputs[0].cpu().numpy()
|
|
|
|
| 38 |
for i, det in enumerate(results.boxes.xyxy):
|
|
|
|
| 39 |
cv2.rectangle(
|
| 40 |
image,
|
| 41 |
(int(det[0]), int(det[1])),
|
|
@@ -44,6 +46,26 @@ def show_preds_image(image_path):
|
|
| 44 |
thickness=2,
|
| 45 |
lineType=cv2.LINE_AA
|
| 46 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
| 48 |
|
| 49 |
inputs_image = [
|
|
|
|
| 26 |
f"image_{i}.jpg"
|
| 27 |
)
|
| 28 |
|
| 29 |
+
model = YOLO('yolov8n.pt')
|
| 30 |
path = [['image_0.jpg'], ['image_1.jpg']]
|
| 31 |
video_path = [['video.mp4']]
|
| 32 |
|
|
|
|
| 35 |
image = cv2.imread(image_path)
|
| 36 |
outputs = model.predict(source=image_path)
|
| 37 |
results = outputs[0].cpu().numpy()
|
| 38 |
+
|
| 39 |
for i, det in enumerate(results.boxes.xyxy):
|
| 40 |
+
# Draw bounding boxes
|
| 41 |
cv2.rectangle(
|
| 42 |
image,
|
| 43 |
(int(det[0]), int(det[1])),
|
|
|
|
| 46 |
thickness=2,
|
| 47 |
lineType=cv2.LINE_AA
|
| 48 |
)
|
| 49 |
+
|
| 50 |
+
# Get the class of the object
|
| 51 |
+
class_id = int(results.boxes.cls[i])
|
| 52 |
+
class_name = model.names[class_id] # Assuming model.names has class names
|
| 53 |
+
label = f"{class_name}"
|
| 54 |
+
|
| 55 |
+
# Display the class label above the bounding box
|
| 56 |
+
label_size, _ = cv2.getTextSize(label, cv2.FONT_HERSHEY_SIMPLEX, 0.5, 2)
|
| 57 |
+
label_y = max(int(det[1]), label_size[1] + 10)
|
| 58 |
+
cv2.putText(
|
| 59 |
+
image,
|
| 60 |
+
label,
|
| 61 |
+
(int(det[0]), label_y - 5),
|
| 62 |
+
cv2.FONT_HERSHEY_SIMPLEX,
|
| 63 |
+
0.5,
|
| 64 |
+
(0, 255, 0),
|
| 65 |
+
2,
|
| 66 |
+
lineType=cv2.LINE_AA
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
| 70 |
|
| 71 |
inputs_image = [
|