Spaces:
No application file
No application file
| import numpy as np | |
| import cv2 | |
| from PIL import Image | |
| def preprocess_image(image: Image.Image): | |
| # Convert PIL to OpenCV | |
| img = np.array(image) | |
| if img.shape[-1] == 4: | |
| img = img[..., :3] | |
| return cv2.cvtColor(img, cv2.COLOR_RGB2BGR) | |