import numpy as np
import os
from PIL import Image
input_path = "./aaa.jpg"
im = Image.open(input_path)
im = im.resize((256,256))
# hwc
img = np.array(im)
height = img.shape[0]
width = img.shape[1]
h_off = int((height-224)/2)
w_off = int((width-224)/2)
#crop_img = img[h_off:height-h_off, w_off:width-w_off, :]
# rgb to bgr
img = img[:,:,::-1]
shape = img.shape
img = img/255
img = img.astype("float16")
#img[:,:,0] -= 104
#img[:,:,1] -= 117
#img[:,:,2] -= 123
#img = img.reshape([1] + list(shape))
print(img.shape)
img = np.expand_dims(img,0)
result = img.transpose([0, 3, 1, 2])
outputName = "./jpg_256.bin"
result.tofile(outputName)
jpg2bin
最新推荐文章于 2024-09-25 09:46:06 发布