glenn-jocher commited on
Commit
47faf95
1 Parent(s): db28ce6

reset head

Browse files
Files changed (1) hide show
  1. utils/plots.py +15 -1
utils/plots.py CHANGED
@@ -15,7 +15,7 @@ import pandas as pd
15
  import seaborn as sns
16
  import torch
17
  import yaml
18
- from PIL import Image, ImageDraw
19
  from scipy.signal import butter, filtfilt
20
 
21
  from utils.general import xywh2xyxy, xyxy2xywh
@@ -68,6 +68,20 @@ def plot_one_box(x, img, color=None, label=None, line_thickness=None):
68
  cv2.putText(img, label, (c1[0], c1[1] - 2), 0, tl / 3, [225, 255, 255], thickness=tf, lineType=cv2.LINE_AA)
69
 
70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  def plot_wh_methods(): # from utils.plots import *; plot_wh_methods()
72
  # Compares the two methods for width-height anchor multiplication
73
  # https://github.com/ultralytics/yolov3/issues/168
 
15
  import seaborn as sns
16
  import torch
17
  import yaml
18
+ from PIL import Image, ImageDraw, ImageFont
19
  from scipy.signal import butter, filtfilt
20
 
21
  from utils.general import xywh2xyxy, xyxy2xywh
 
68
  cv2.putText(img, label, (c1[0], c1[1] - 2), 0, tl / 3, [225, 255, 255], thickness=tf, lineType=cv2.LINE_AA)
69
 
70
 
71
+ def plot_one_box_PIL(box, img, color=None, label=None, line_thickness=None):
72
+ img = Image.fromarray(img)
73
+ draw = ImageDraw.Draw(img)
74
+ line_thickness = line_thickness or max(int(min(img.size) / 200), 2)
75
+ draw.rectangle(box, width=line_thickness, outline=tuple(color)) # plot
76
+ if label:
77
+ fontsize = max(round(max(img.size) / 40), 12)
78
+ font = ImageFont.truetype("Arial.ttf", fontsize)
79
+ txt_width, txt_height = font.getsize(label)
80
+ draw.rectangle([box[0], box[1] - txt_height + 4, box[0] + txt_width, box[1]], fill=tuple(color))
81
+ draw.text((box[0], box[1] - txt_height + 1), label, fill=(255, 255, 255), font=font)
82
+ return np.asarray(img)
83
+
84
+
85
  def plot_wh_methods(): # from utils.plots import *; plot_wh_methods()
86
  # Compares the two methods for width-height anchor multiplication
87
  # https://github.com/ultralytics/yolov3/issues/168