def get_image(file_location, local=False):
# users can either
# [1] upload a picture (local = True)
# or
# [2] provide the image URL (local = False)
if local == True:
fname = file_location
else:
fname = mx.test_utils.download(file_location, dirname="static/img_pool")
img = cv2.cvtColor(cv2.imread(fname), cv2.COLOR_BGR2RGB)
if img is None:
return None
# convert into format (batch, RGB, width, height)
img = cv2.resize(img, (224, 224))
img = np.swapaxes(img, 0, 2)
img = np.swapaxes(img, 1, 2)
img = img[np.newaxis, :]
return img
评论列表
文章目录