shape-recognition / preprocess_cnn.py
Laufey's picture
Rename preprocess.py to preprocess_cnn.py
6724345 verified
Raw
History Blame Contribute Delete
306 Bytes
import numpy as np
import cv2
from PIL import Image
IMAGE_SIZE = 128
def preprocess_for_cnn(image: Image.Image):
img = np.array(image.convert("L"))
img = cv2.resize(img, (IMAGE_SIZE, IMAGE_SIZE))
img = img.astype(np.float32) / 255.0
img = np.expand_dims(img, axis=(0, -1))
return img