Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -85,12 +85,27 @@ def detect_image(image, model_choice, conf_threshold):
|
|
| 85 |
classes = r.boxes.cls.cpu().numpy()
|
| 86 |
for i, (box, cls) in enumerate(zip(boxes, classes)):
|
| 87 |
label = CLASS_NAMES[int(cls)]
|
| 88 |
-
counts[label] +=1
|
| 89 |
-
rows.append([i+1,label])
|
| 90 |
-
|
|
|
|
| 91 |
color = (0,255,0) if label=="RBC" else (255,0,0) if label=="WBC" else (0,0,255)
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
df = pd.DataFrame(rows, columns=["Object_No","Class"])
|
| 96 |
csv_file = tempfile.NamedTemporaryFile(delete=False, suffix=".csv")
|
|
|
|
| 85 |
classes = r.boxes.cls.cpu().numpy()
|
| 86 |
for i, (box, cls) in enumerate(zip(boxes, classes)):
|
| 87 |
label = CLASS_NAMES[int(cls)]
|
| 88 |
+
counts[label] += 1
|
| 89 |
+
rows.append([i+1, label])
|
| 90 |
+
|
| 91 |
+
x1, y1, x2, y2 = map(int, box)
|
| 92 |
color = (0,255,0) if label=="RBC" else (255,0,0) if label=="WBC" else (0,0,255)
|
| 93 |
+
|
| 94 |
+
# Draw box
|
| 95 |
+
cv2.rectangle(img, (x1,y1), (x2,y2), color, 2)
|
| 96 |
+
|
| 97 |
+
# Draw numbered label
|
| 98 |
+
text = f"{i+1}: {label}"
|
| 99 |
+
cv2.putText(
|
| 100 |
+
img,
|
| 101 |
+
text,
|
| 102 |
+
(x1, y1 - 8),
|
| 103 |
+
cv2.FONT_HERSHEY_SIMPLEX,
|
| 104 |
+
0.6,
|
| 105 |
+
color,
|
| 106 |
+
2,
|
| 107 |
+
cv2.LINE_AA
|
| 108 |
+
)
|
| 109 |
|
| 110 |
df = pd.DataFrame(rows, columns=["Object_No","Class"])
|
| 111 |
csv_file = tempfile.NamedTemporaryFile(delete=False, suffix=".csv")
|