From 64046a24b68207b89413d865002dd962d84f7fef Mon Sep 17 00:00:00 2001 From: yeric1789 <76454253+yeric1789@users.noreply.github.com> Date: Wed, 19 May 2021 11:26:42 -0400 Subject: [PATCH 1/2] Color can be none by default --- utils/plots.py | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/plots.py b/utils/plots.py index ade9322ce4ec..af20dc59ba3b 100644 --- a/utils/plots.py +++ b/utils/plots.py @@ -88,6 +88,7 @@ def plot_one_box_PIL(box, im, color=None, label=None, line_thickness=None): im = Image.fromarray(im) draw = ImageDraw.Draw(im) line_thickness = line_thickness or max(int(min(im.size) / 200), 2) + color = color or [random.randint(0, 255) for _ in range(3)] draw.rectangle(box, width=line_thickness, outline=tuple(color)) # plot if label: fontsize = max(round(max(im.size) / 40), 12) From afe8b7316356dab783c4ac9e04cd44af2e369890 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 19 May 2021 19:43:38 +0200 Subject: [PATCH 2/2] `plot_one_box()` default `color=(128, 128, 128)` --- utils/plots.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/utils/plots.py b/utils/plots.py index af20dc59ba3b..8313ef210f90 100644 --- a/utils/plots.py +++ b/utils/plots.py @@ -68,11 +68,10 @@ def butter_lowpass(cutoff, fs, order): return filtfilt(b, a, data) # forward-backward filter -def plot_one_box(x, im, color=None, label=None, line_thickness=3): +def plot_one_box(x, im, color=(128, 128, 128), label=None, line_thickness=3): # Plots one bounding box on image 'im' using OpenCV assert im.data.contiguous, 'Image not contiguous. Apply np.ascontiguousarray(im) to plot_on_box() input image.' tl = line_thickness or round(0.002 * (im.shape[0] + im.shape[1]) / 2) + 1 # line/font thickness - color = color or [random.randint(0, 255) for _ in range(3)] c1, c2 = (int(x[0]), int(x[1])), (int(x[2]), int(x[3])) cv2.rectangle(im, c1, c2, color, thickness=tl, lineType=cv2.LINE_AA) if label: @@ -83,18 +82,16 @@ def plot_one_box(x, im, color=None, label=None, line_thickness=3): cv2.putText(im, label, (c1[0], c1[1] - 2), 0, tl / 3, [225, 255, 255], thickness=tf, lineType=cv2.LINE_AA) -def plot_one_box_PIL(box, im, color=None, label=None, line_thickness=None): +def plot_one_box_PIL(box, im, color=(128, 128, 128), label=None, line_thickness=None): # Plots one bounding box on image 'im' using PIL im = Image.fromarray(im) draw = ImageDraw.Draw(im) line_thickness = line_thickness or max(int(min(im.size) / 200), 2) - color = color or [random.randint(0, 255) for _ in range(3)] - draw.rectangle(box, width=line_thickness, outline=tuple(color)) # plot + draw.rectangle(box, width=line_thickness, outline=color) # plot if label: - fontsize = max(round(max(im.size) / 40), 12) - font = ImageFont.truetype("Arial.ttf", fontsize) + font = ImageFont.truetype("Arial.ttf", size=max(round(max(im.size) / 40), 12)) txt_width, txt_height = font.getsize(label) - draw.rectangle([box[0], box[1] - txt_height + 4, box[0] + txt_width, box[1]], fill=tuple(color)) + draw.rectangle([box[0], box[1] - txt_height + 4, box[0] + txt_width, box[1]], fill=color) draw.text((box[0], box[1] - txt_height + 1), label, fill=(255, 255, 255), font=font) return np.asarray(im)