Spaces:
Runtime error
Runtime error
support multiple lines of bboxes
Browse files
app.py
CHANGED
@@ -7,19 +7,25 @@ from gradio.components import Image, Radio, Textbox
|
|
7 |
def plot_bounding_boxes(image, boxes, box_type):
|
8 |
if not boxes:
|
9 |
return image
|
|
|
|
|
10 |
|
11 |
-
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
18 |
|
19 |
detections = sv.Detections(
|
20 |
-
xyxy=np.array(
|
21 |
-
class_id=np.array([0]),
|
22 |
-
confidence=np.array([1.0]),
|
23 |
)
|
24 |
|
25 |
image = np.array(image)
|
|
|
7 |
def plot_bounding_boxes(image, boxes, box_type):
|
8 |
if not boxes:
|
9 |
return image
|
10 |
+
|
11 |
+
bboxes = []
|
12 |
|
13 |
+
for row in boxes.split("\n"):
|
14 |
+
x0, y0, x1, y1 = [int(float(i.split(".")[0])) for i in boxes.split(",")]
|
15 |
|
16 |
+
if box_type == "xywh":
|
17 |
+
x0 = x0 * image.size[0]
|
18 |
+
y0 = y0 * image.size[1]
|
19 |
+
x1 = x0 + (x1 * image.size[0])
|
20 |
+
y1 = y0 + (y1 * image.size[1])
|
21 |
+
|
22 |
+
bbox = [x0, y0, x1, y1]
|
23 |
+
bboxes.append(bbox)
|
24 |
|
25 |
detections = sv.Detections(
|
26 |
+
xyxy=np.array(bboxes),
|
27 |
+
class_id=np.array([0] * len(bboxes)),
|
28 |
+
confidence=np.array([1.0] * len(bboxes)),
|
29 |
)
|
30 |
|
31 |
image = np.array(image)
|