innat/Google-MediaPipe
8
1 2import cv2, math 3 4DESIRED_HEIGHT = 4805DESIRED_WIDTH = 4806 7def read_n_resize(image_file, read=True):8 image = cv2.imread(image_file) if read else image_file9 image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) if read else image10 11 h, w = image.shape[:2]12 13 if h < w:14 img = cv2.resize(15 image, (DESIRED_WIDTH, math.floor(h/(w/DESIRED_WIDTH)))16 )17 else:18 img = cv2.resize(19 image, (math.floor(w/(h/DESIRED_HEIGHT)), DESIRED_HEIGHT)20 )21 22 return img