IMAGE_SIZE = (224, 224) # ①
CELL_SIZE = 32 # ②
def convert_to_corner_coordinates(x, y, bbox, image_size):# ③
bbox_x = (CELL_SIZE * x + bbox[0] * CELL_SIZE) * image_size[0] / IMAGE_SIZE[0]
bbox_y = (CELL_SIZE * y + bbox[1] * CELL_SIZE) * image_size[1] / IMAGE_SIZE[1]
bbox_w = bbox[2] * image_size[0]
bbox_h = bbox[3] * image_size[1]
min_x = int(bbox_x - bbox_w/2)
min_y = int(bbox_y - bbox_h/2)
max_x = int(bbox_x + bbox_w/2)
max_y = int(bbox_y + bbox_h/2)
return [min_x, min_y, max_x, max_y]
def process_single_bbox(x, y, bbox, image_size, classes_score, class_names): # ④
idx_highest_score = np.argmax(classes_score)
highest_score = classes_score[idx_highest_score]
highest_score_name = class_names[idx_highest_score]
corner_coords = convert_to_corner_coordinates(x, y, bbox, image_size)
return corner_coords + [highest_score, highest_score_name]