def preprocessing(input_img_path,input_height,input_width):
input_image = cv2.imread(input_img_path)
# Resize the image and convert to array of float32
resized_image = cv2.resize(input_image,(input_height, input_width), interpolation = cv2.INTER_CUBIC)
image_data = np.array(resized_image, dtype='f')
# Normalization [0,255] -> [0,1]
image_data /= 255.
# BGR -> RGB? The results do not change much
# copied_image = image_data
#image_data[:,:,2] = copied_image[:,:,0]
#image_data[:,:,0] = copied_image[:,:,2]
# Add the dimension relative to the batch size needed for the input placeholder "x"
image_array = np.expand_dims(image_data, 0) # Add batch dimension
return image_array
评论列表
文章目录