Spaces:
Runtime error
Runtime error
Martin Tomov
commited on
experimenting with extraction of bbx
Browse files
app.py
CHANGED
|
@@ -59,13 +59,14 @@ def annotate(image: Union[Image.Image, np.ndarray], detection_results: List[Dete
|
|
| 59 |
|
| 60 |
if mask is not None:
|
| 61 |
mask_uint8 = (mask * 255).astype(np.uint8)
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
|
|
|
| 69 |
|
| 70 |
return cv2.cvtColor(yellow_background, cv2.COLOR_BGR2RGB)
|
| 71 |
|
|
@@ -217,4 +218,4 @@ gr.Interface(
|
|
| 217 |
outputs=[gr.Image(type="numpy"), gr.Textbox()],
|
| 218 |
title="InsectSAM π",
|
| 219 |
examples=examples
|
| 220 |
-
).launch()
|
|
|
|
| 59 |
|
| 60 |
if mask is not None:
|
| 61 |
mask_uint8 = (mask * 255).astype(np.uint8)
|
| 62 |
+
mask_inv = cv2.bitwise_not(mask_uint8)
|
| 63 |
+
|
| 64 |
+
# Extract insect using mask
|
| 65 |
+
insect_region = cv2.bitwise_and(image_cv2, image_cv2, mask=mask_uint8)
|
| 66 |
+
yellow_background_masked = cv2.bitwise_and(yellow_background, yellow_background, mask=mask_inv)
|
| 67 |
+
insect_combined = cv2.add(insect_region, yellow_background_masked)
|
| 68 |
+
|
| 69 |
+
yellow_background = cv2.add(yellow_background, insect_combined)
|
| 70 |
|
| 71 |
return cv2.cvtColor(yellow_background, cv2.COLOR_BGR2RGB)
|
| 72 |
|
|
|
|
| 218 |
outputs=[gr.Image(type="numpy"), gr.Textbox()],
|
| 219 |
title="InsectSAM π",
|
| 220 |
examples=examples
|
| 221 |
+
).launch()
|