capjamesg commited on
Commit
5d3aab5
1 Parent(s): afa8f00

support multiple lines of bboxes

Browse files
Files changed (1) hide show
  1. app.py +15 -9
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
- x0, y0, x1, y1 = [int(float(i.split(".")[0])) for i in boxes.split(",")]
 
12
 
13
- if box_type == "xywh":
14
- x0 = x0 * image.size[0]
15
- y0 = y0 * image.size[1]
16
- x1 = x0 + (x1 * image.size[0])
17
- y1 = y0 + (y1 * image.size[1])
 
 
 
18
 
19
  detections = sv.Detections(
20
- xyxy=np.array([[x0, y0, x1, y1]]),
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)