Validate and format an image to numpy array.
(im)
| 389 | |
| 390 | @staticmethod |
| 391 | def _single_check(im): |
| 392 | """Validate and format an image to numpy array.""" |
| 393 | assert isinstance(im, (Image.Image, np.ndarray)), f'Expected PIL/np.ndarray image type, but got {type(im)}' |
| 394 | if isinstance(im, Image.Image): |
| 395 | if im.mode != 'RGB': |
| 396 | im = im.convert('RGB') |
| 397 | im = np.asarray(im)[:, :, ::-1] |
| 398 | im = np.ascontiguousarray(im) # contiguous |
| 399 | return im |
| 400 | |
| 401 | def __len__(self): |
| 402 | """Returns the length of the 'im0' attribute.""" |