Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -138,19 +138,18 @@ def inference(image_url, image, min_score):
|
|
| 138 |
measurements = {}
|
| 139 |
|
| 140 |
for ind,item_mask in enumerate(masks):
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
# Loop over the masks
|
| 155 |
# return outputs
|
| 156 |
for ind, item_mask in enumerate(masks):
|
|
|
|
| 138 |
measurements = {}
|
| 139 |
|
| 140 |
for ind,item_mask in enumerate(masks):
|
| 141 |
+
if segmentation[1].any() segmentation[0].any()
|
| 142 |
+
# box=bbox[ind]
|
| 143 |
+
# Get the true bounding box of the mask (not the same as the bbox prediction)
|
| 144 |
+
segmentation = np.where(item_mask == True)
|
| 145 |
+
x_min = int(np.min(segmentation[1]))
|
| 146 |
+
x_max = int(np.max(segmentation[1]))
|
| 147 |
+
y_min = int(np.min(segmentation[0]))
|
| 148 |
+
y_max = int(np.max(segmentation[0]))
|
| 149 |
+
measurement = int(0.5+len(segmentation[0])/600)
|
| 150 |
+
measurements[ind] = {'measurement': measurement, 'x_min': x_min, 'x_max': x_max, 'y_min': y_min, 'y_max': y_max}
|
| 151 |
+
# cv2.putText(img=img, text=str(int(0.5+len( segmentation[0])/600)), org=(x_min+20,y_min-10), fontFace=cv2.FONT_HERSHEY_TRIPLEX, fontScale=0.8, color=(0, 255, 0),thickness=2)
|
| 152 |
+
|
|
|
|
| 153 |
# Loop over the masks
|
| 154 |
# return outputs
|
| 155 |
for ind, item_mask in enumerate(masks):
|