Fix Annotator PIL Image size (width, height) order (#14227)

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
pull/14307/head
Sheffey 8 months ago committed by GitHub
parent 7a6bb2b1c9
commit 755dcd6ca0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      ultralytics/utils/plotting.py

@ -298,8 +298,8 @@ class Annotator:
if label:
w, h = self.font.getsize(label) # text width, height
outside = p1[1] >= h # label fits outside box
if p1[0] > self.im.size[1] - w: # check if label extend beyond right side of image
p1 = self.im.size[1] - w, p1[1]
if p1[0] > self.im.size[0] - w: # size is (w, h), check if label extend beyond right side of image
p1 = self.im.size[0] - w, p1[1]
self.draw.rectangle(
(p1[0], p1[1] - h if outside else p1[1], p1[0] + w + 1, p1[1] + 1 if outside else p1[1] + h + 1),
fill=color,
@ -317,7 +317,7 @@ class Annotator:
w, h = cv2.getTextSize(label, 0, fontScale=self.sf, thickness=self.tf)[0] # text width, height
h += 3 # add pixels to pad text
outside = p1[1] >= h # label fits outside box
if p1[0] > self.im.shape[1] - w: # check if label extend beyond right side of image
if p1[0] > self.im.shape[1] - w: # shape is (h, w), check if label extend beyond right side of image
p1 = self.im.shape[1] - w, p1[1]
p2 = p1[0] + w, p1[1] - h if outside else p1[1] + h
cv2.rectangle(self.im, p1, p2, color, -1, cv2.LINE_AA) # filled

Loading…
Cancel
Save