`plot_one_box()` default `color=(128, 128, 128)` (#3240)
Browse files* Color can be none by default
* `plot_one_box()` default `color=(128, 128, 128)`
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
- utils/plots.py +5 -7
utils/plots.py
CHANGED
@@ -68,11 +68,10 @@ def butter_lowpass_filtfilt(data, cutoff=1500, fs=50000, order=5):
|
|
68 |
return filtfilt(b, a, data) # forward-backward filter
|
69 |
|
70 |
|
71 |
-
def plot_one_box(x, im, color=
|
72 |
# Plots one bounding box on image 'im' using OpenCV
|
73 |
assert im.data.contiguous, 'Image not contiguous. Apply np.ascontiguousarray(im) to plot_on_box() input image.'
|
74 |
tl = line_thickness or round(0.002 * (im.shape[0] + im.shape[1]) / 2) + 1 # line/font thickness
|
75 |
-
color = color or [random.randint(0, 255) for _ in range(3)]
|
76 |
c1, c2 = (int(x[0]), int(x[1])), (int(x[2]), int(x[3]))
|
77 |
cv2.rectangle(im, c1, c2, color, thickness=tl, lineType=cv2.LINE_AA)
|
78 |
if label:
|
@@ -83,17 +82,16 @@ def plot_one_box(x, im, color=None, label=None, line_thickness=3):
|
|
83 |
cv2.putText(im, label, (c1[0], c1[1] - 2), 0, tl / 3, [225, 255, 255], thickness=tf, lineType=cv2.LINE_AA)
|
84 |
|
85 |
|
86 |
-
def plot_one_box_PIL(box, im, color=
|
87 |
# Plots one bounding box on image 'im' using PIL
|
88 |
im = Image.fromarray(im)
|
89 |
draw = ImageDraw.Draw(im)
|
90 |
line_thickness = line_thickness or max(int(min(im.size) / 200), 2)
|
91 |
-
draw.rectangle(box, width=line_thickness, outline=
|
92 |
if label:
|
93 |
-
|
94 |
-
font = ImageFont.truetype("Arial.ttf", fontsize)
|
95 |
txt_width, txt_height = font.getsize(label)
|
96 |
-
draw.rectangle([box[0], box[1] - txt_height + 4, box[0] + txt_width, box[1]], fill=
|
97 |
draw.text((box[0], box[1] - txt_height + 1), label, fill=(255, 255, 255), font=font)
|
98 |
return np.asarray(im)
|
99 |
|
|
|
68 |
return filtfilt(b, a, data) # forward-backward filter
|
69 |
|
70 |
|
71 |
+
def plot_one_box(x, im, color=(128, 128, 128), label=None, line_thickness=3):
|
72 |
# Plots one bounding box on image 'im' using OpenCV
|
73 |
assert im.data.contiguous, 'Image not contiguous. Apply np.ascontiguousarray(im) to plot_on_box() input image.'
|
74 |
tl = line_thickness or round(0.002 * (im.shape[0] + im.shape[1]) / 2) + 1 # line/font thickness
|
|
|
75 |
c1, c2 = (int(x[0]), int(x[1])), (int(x[2]), int(x[3]))
|
76 |
cv2.rectangle(im, c1, c2, color, thickness=tl, lineType=cv2.LINE_AA)
|
77 |
if label:
|
|
|
82 |
cv2.putText(im, label, (c1[0], c1[1] - 2), 0, tl / 3, [225, 255, 255], thickness=tf, lineType=cv2.LINE_AA)
|
83 |
|
84 |
|
85 |
+
def plot_one_box_PIL(box, im, color=(128, 128, 128), label=None, line_thickness=None):
|
86 |
# Plots one bounding box on image 'im' using PIL
|
87 |
im = Image.fromarray(im)
|
88 |
draw = ImageDraw.Draw(im)
|
89 |
line_thickness = line_thickness or max(int(min(im.size) / 200), 2)
|
90 |
+
draw.rectangle(box, width=line_thickness, outline=color) # plot
|
91 |
if label:
|
92 |
+
font = ImageFont.truetype("Arial.ttf", size=max(round(max(im.size) / 40), 12))
|
|
|
93 |
txt_width, txt_height = font.getsize(label)
|
94 |
+
draw.rectangle([box[0], box[1] - txt_height + 4, box[0] + txt_width, box[1]], fill=color)
|
95 |
draw.text((box[0], box[1] - txt_height + 1), label, fill=(255, 255, 255), font=font)
|
96 |
return np.asarray(im)
|
97 |
|