Add support for handling 2-channel images in Annotator class (#22999)

This commit is contained in:
Yan Tang 2025-12-20 21:36:15 +08:00 committed by GitHub
parent 22d589d2e7
commit 5e7aa316df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -203,6 +203,8 @@ class Annotator:
if not input_is_pil:
if im.shape[2] == 1: # handle grayscale
im = cv2.cvtColor(im, cv2.COLOR_GRAY2BGR)
elif im.shape[2] == 2: # handle 2-channel images
im = np.ascontiguousarray(np.dstack((im, np.zeros_like(im[..., :1]))))
elif im.shape[2] > 3: # multispectral
im = np.ascontiguousarray(im[..., :3])
if self.pil: # use PIL