Spaces:
Runtime error
Runtime error
File size: 523 Bytes
8478e62 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import cv2, math
DESIRED_HEIGHT = 480
DESIRED_WIDTH = 480
def read_n_resize(image_file, read=True):
image = cv2.imread(image_file) if read else image_file
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) if read else image
h, w = image.shape[:2]
if h < w:
img = cv2.resize(
image, (DESIRED_WIDTH, math.floor(h/(w/DESIRED_WIDTH)))
)
else:
img = cv2.resize(
image, (math.floor(w/(h/DESIRED_HEIGHT)), DESIRED_HEIGHT)
)
return img |