majinyu commited on
Commit
8dce060
·
1 Parent(s): 0d77820

reasonable font size and box line width

Browse files
Files changed (1) hide show
  1. app.py +2 -2
app.py CHANGED
@@ -105,13 +105,13 @@ def draw_mask(mask, draw, random_color=False):
105
  def draw_box(box, draw, label):
106
  # random color
107
  color = tuple(np.random.randint(0, 255, size=3).tolist())
108
- line_width = min(5, max(25, 0.006*max(draw.im.size)))
109
  draw.rectangle(((box[0], box[1]), (box[2], box[3])), outline=color, width=line_width)
110
 
111
  if label:
112
  font_path = os.path.join(
113
  cv2.__path__[0], 'qt', 'fonts', 'DejaVuSans.ttf')
114
- font_size = min(15, max(75, 0.02*max(draw.im.size)))
115
  font = ImageFont.truetype(font_path, size=font_size)
116
  if hasattr(font, "getbbox"):
117
  bbox = draw.textbbox((box[0], box[1]), str(label), font)
 
105
  def draw_box(box, draw, label):
106
  # random color
107
  color = tuple(np.random.randint(0, 255, size=3).tolist())
108
+ line_width = max(4, min(20, 0.006*max(draw.im.size)))
109
  draw.rectangle(((box[0], box[1]), (box[2], box[3])), outline=color, width=line_width)
110
 
111
  if label:
112
  font_path = os.path.join(
113
  cv2.__path__[0], 'qt', 'fonts', 'DejaVuSans.ttf')
114
+ font_size = max(12, min(60, 0.02*max(draw.im.size)))
115
  font = ImageFont.truetype(font_path, size=font_size)
116
  if hasattr(font, "getbbox"):
117
  bbox = draw.textbbox((box[0], box[1]), str(label), font)