Next, we will write a process image function. This function will reduce or expand the image, depending on its original size.
Here, we want to transform the image as per the input for the YOLO model:
def process_image(img):
"""Resize, reduce and expand image.
# Argument:
img: original image.
# Returns
image_org: ndarray(64, 64, 3), processed image.
"""
image_org = cv2.resize(img, (416, 416),
interpolation=cv2.INTER_CUBIC)
image_org = np.array(image_org, dtype='float32')
image_org /= 255.
image_org = np.expand_dims(image_org, axis=0)
return image_org
In the next section, we will write a class function so that we can access the classes from a text file.