Spaces:
Runtime error
Runtime error
Martin Tomov
commited on
experimenting
Browse files
app.py
CHANGED
|
@@ -51,20 +51,12 @@ def annotate(image: Union[Image.Image, np.ndarray], detection_results: List[Dete
|
|
| 51 |
image_cv2 = cv2.cvtColor(image_cv2, cv2.COLOR_RGB2BGR)
|
| 52 |
|
| 53 |
for detection in detection_results:
|
| 54 |
-
label = detection.label
|
| 55 |
-
score = detection.score
|
| 56 |
-
box = detection.box
|
| 57 |
mask = detection.mask
|
| 58 |
-
color = np.random.randint(0, 256, size=3).tolist()
|
| 59 |
-
|
| 60 |
-
cv2.rectangle(image_cv2, (box.xmin, box.ymin), (box.xmax, box.ymax), color, 2)
|
| 61 |
-
cv2.putText(image_cv2, f'{label}: {score:.2f}', (box.xmin, box.ymin - 10),
|
| 62 |
-
cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)
|
| 63 |
-
|
| 64 |
if mask is not None:
|
| 65 |
mask_uint8 = (mask * 255).astype(np.uint8)
|
| 66 |
contours, _ = cv2.findContours(mask_uint8, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
| 67 |
-
|
|
|
|
| 68 |
|
| 69 |
return cv2.cvtColor(image_cv2, cv2.COLOR_BGR2RGB)
|
| 70 |
|
|
@@ -172,8 +164,7 @@ def run_length_encoding(mask):
|
|
| 172 |
rle.append(count)
|
| 173 |
count = 1
|
| 174 |
last_val = pixel
|
| 175 |
-
if count > 0
|
| 176 |
-
rle.append(count)
|
| 177 |
return rle
|
| 178 |
|
| 179 |
def detections_to_json(detections):
|
|
|
|
| 51 |
image_cv2 = cv2.cvtColor(image_cv2, cv2.COLOR_RGB2BGR)
|
| 52 |
|
| 53 |
for detection in detection_results:
|
|
|
|
|
|
|
|
|
|
| 54 |
mask = detection.mask
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
if mask is not None:
|
| 56 |
mask_uint8 = (mask * 255).astype(np.uint8)
|
| 57 |
contours, _ = cv2.findContours(mask_uint8, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
| 58 |
+
# Drawing only the mask contours without any bounding box or label
|
| 59 |
+
cv2.drawContours(image_cv2, contours, -1, (0, 0, 0), 2) # Black color for contours
|
| 60 |
|
| 61 |
return cv2.cvtColor(image_cv2, cv2.COLOR_BGR2RGB)
|
| 62 |
|
|
|
|
| 164 |
rle.append(count)
|
| 165 |
count = 1
|
| 166 |
last_val = pixel
|
| 167 |
+
if count > 0, rle.append(count)
|
|
|
|
| 168 |
return rle
|
| 169 |
|
| 170 |
def detections_to_json(detections):
|