def get_object_positions(image_resolution, bounding_boxes_with_captions):
    object_positions = []
    for box_with_caption in bounding_boxes_with_captions:
        caption, box_str = box_with_caption.split(":")
        caption = caption.strip()
        box = [int(coord) for coord in box_str.strip()[1:-1].split(",")]
        x1, y1, x2, y2 = box
        object_x = (x1 + x2) / 2 / image_resolution[0]
        object_y = (y1 + y2) / 2 / image_resolution[1]
        if object_x < 0.2:
            x_pos = "on the left"
        elif object_x < 0.4:
            x_pos = "in the middle left"
        elif object_x < 0.6:
            x_pos = "in the center"
        elif object_x < 0.8:
            x_pos = "in the middle right"
        else:
            x_pos = "on the right"
        if object_y < 0.2:
            y_pos = "at the top"
        elif object_y < 0.4:
            y_pos = "near the top"
        elif object_y < 0.6:
            y_pos = "in the middle"
        elif object_y < 0.8:
            y_pos = "near the bottom"
        else:
            y_pos = "at the bottom"
        object_positions.append(caption + " " + x_pos + " " + y_pos)
    return object_positions


image_resolution = (640, 397)
bounding_boxes_with_captions = "a white car: [0, 122, 202, 245]; man sitting on motorcycle: [288, 42, 496, 396]; a motorcycle with a side car: [120, 82, 548, 393]; a car driving down the road: [540, 220, 639, 331]; a large backpack: [218, 115, 296, 225]; a traffic light: [512, 37, 522, 63]; a car is parked: [589, 247, 640, 351]; a traffic light: [409, 33, 427, 60]; a traffic light: [200, 48, 212, 91]; man in uniform and hat: [249, 72, 300, 131]; a traffic light: [430, 63, 437, 90]; a man driving a car: [586, 232, 624, 263]; a traffic light: [586, 88, 594, 112]; a traffic light: [200, 70, 213, 91]; a traffic light: [431, 26, 437, 44];"
 
object_positions = get_object_positions(image_resolution, bounding_boxes_with_captions.split(";")[:-1])
print(object_positions)
