amir221-003 commited on
Commit
c357333
·
verified ·
1 Parent(s): a6f99fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -5
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
- x1,y1,x2,y2 = map(int, box)
 
91
  color = (0,255,0) if label=="RBC" else (255,0,0) if label=="WBC" else (0,0,255)
92
- cv2.rectangle(img,(x1,y1),(x2,y2),color,2)
93
- cv2.putText(img,label,(x1,y1-5),cv2.FONT_HERSHEY_SIMPLEX,0.5,color,2)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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")