Spaces:
Running
on
Zero
Running
on
Zero
Martin Tomov
commited on
border colour
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ os.system('pip install gradio==4.29.0')
|
|
3 |
|
4 |
import random
|
5 |
from dataclasses import dataclass
|
6 |
-
from typing
|
7 |
import cv2
|
8 |
import torch
|
9 |
import requests
|
@@ -55,9 +55,9 @@ def annotate(image: Union[Image.Image, np.ndarray], detection_results: List[Dete
|
|
55 |
score = detection.score
|
56 |
box = detection.box
|
57 |
mask = detection.mask
|
58 |
-
color = np.random.randint(0, 256, size=3).tolist()
|
59 |
|
60 |
if include_bboxes:
|
|
|
61 |
cv2.rectangle(image_cv2, (box.xmin, box.ymin), (box.xmax, box.ymax), color, 2)
|
62 |
cv2.putText(image_cv2, f'{label}: {score:.2f}', (box.xmin, box.ymin - 10),
|
63 |
cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)
|
@@ -65,7 +65,7 @@ def annotate(image: Union[Image.Image, np.ndarray], detection_results: List[Dete
|
|
65 |
if mask is not None:
|
66 |
mask_uint8 = (mask * 255).astype(np.uint8)
|
67 |
contours, _ = cv2.findContours(mask_uint8, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
68 |
-
cv2.drawContours(image_cv2, contours, -1,
|
69 |
|
70 |
return cv2.cvtColor(image_cv2, cv2.COLOR_BGR2RGB)
|
71 |
|
|
|
3 |
|
4 |
import random
|
5 |
from dataclasses import dataclass
|
6 |
+
from typing: Any, List, Dict, Optional, Union, Tuple
|
7 |
import cv2
|
8 |
import torch
|
9 |
import requests
|
|
|
55 |
score = detection.score
|
56 |
box = detection.box
|
57 |
mask = detection.mask
|
|
|
58 |
|
59 |
if include_bboxes:
|
60 |
+
color = np.random.randint(0, 256, size=3).tolist()
|
61 |
cv2.rectangle(image_cv2, (box.xmin, box.ymin), (box.xmax, box.ymax), color, 2)
|
62 |
cv2.putText(image_cv2, f'{label}: {score:.2f}', (box.xmin, box.ymin - 10),
|
63 |
cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)
|
|
|
65 |
if mask is not None:
|
66 |
mask_uint8 = (mask * 255).astype(np.uint8)
|
67 |
contours, _ = cv2.findContours(mask_uint8, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
68 |
+
cv2.drawContours(image_cv2, contours, -1, (0, 255, 0), 2)
|
69 |
|
70 |
return cv2.cvtColor(image_cv2, cv2.COLOR_BGR2RGB)
|
71 |
|