borakol commited on
Commit
9745baf
·
verified ·
1 Parent(s): 1e0acdb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -17,24 +17,29 @@ def detect_objects(image):
17
  box = r["box"]
18
  label = f"{r['label']} {r['score']:.2f}"
19
 
20
- # stil ayarları
21
- color = "red"
22
  box_width = 4
23
  text_padding = 3
24
 
25
- # Bounding Box
26
  draw.rectangle(
27
  [(box["xmin"], box["ymin"]), (box["xmax"], box["ymax"])],
28
  outline=color, width=box_width
29
  )
30
 
31
- # Label
32
- text_w, text_h = draw.textsize(label, font=font)
 
 
 
33
  text_bg = [
34
  (box["xmin"], box["ymin"] - text_h - text_padding),
35
  (box["xmin"] + text_w + text_padding * 2, box["ymin"])
36
  ]
37
  draw.rectangle(text_bg, fill=color)
 
 
38
  draw.text(
39
  (box["xmin"] + text_padding, box["ymin"] - text_h - text_padding),
40
  label, fill="white", font=font
 
17
  box = r["box"]
18
  label = f"{r['label']} {r['score']:.2f}"
19
 
20
+ # Stil ayarları
21
+ color = "green"
22
  box_width = 4
23
  text_padding = 3
24
 
25
+ # Bounding box
26
  draw.rectangle(
27
  [(box["xmin"], box["ymin"]), (box["xmax"], box["ymax"])],
28
  outline=color, width=box_width
29
  )
30
 
31
+ # Yazı ölçümü
32
+ bbox = draw.textbbox((0, 0), label, font=font)
33
+ text_w, text_h = bbox[2] - bbox[0], bbox[3] - bbox[1]
34
+
35
+ # Yazı arka planı
36
  text_bg = [
37
  (box["xmin"], box["ymin"] - text_h - text_padding),
38
  (box["xmin"] + text_w + text_padding * 2, box["ymin"])
39
  ]
40
  draw.rectangle(text_bg, fill=color)
41
+
42
+ # Yazı
43
  draw.text(
44
  (box["xmin"] + text_padding, box["ymin"] - text_h - text_padding),
45
  label, fill="white", font=font