From 5e81651b4f85fb3d404148eedc6b0513628514f2 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 14 Feb 2024 14:34:44 +0100 Subject: [PATCH] Fix PIL `show()` and `save()` (#8202) Signed-off-by: Glenn Jocher --- ultralytics/utils/plotting.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ultralytics/utils/plotting.py b/ultralytics/utils/plotting.py index c206f8a5..da7e5851 100644 --- a/ultralytics/utils/plotting.py +++ b/ultralytics/utils/plotting.py @@ -332,11 +332,11 @@ class Annotator: def show(self, title=None): """Show the annotated image.""" - (self.im if isinstance(self.im, Image.Image) else Image.fromarray(self.im[..., ::-1])).show(title) + Image.fromarray(np.asarray(self.im)[..., ::-1]).show(title) def save(self, filename="image.jpg"): """Save the annotated image to 'filename'.""" - (self.im if isinstance(self.im, Image.Image) else Image.fromarray(self.im[..., ::-1])).save(filename) + cv2.imwrite(filename, np.asarray(self.im)) def draw_region(self, reg_pts=None, color=(0, 255, 0), thickness=5): """ @@ -422,8 +422,6 @@ class Annotator: shape (tuple): imgsz for model inference radius (int): Keypoint radius value """ - nkpts, ndim = keypoints.shape - nkpts == 17 and ndim == 3 for i, k in enumerate(keypoints): if i in indices: x_coord, y_coord = k[0], k[1]