def get_bbox_in_context(bbox_selected, crop_pos, target_size):
    """Computes the relative bounding box location in the image (actual image in the training).

    Args:
        bbox_selected: object bounding box with class label (dict),
          containing {'bbox': (xmin, ymin, xmax, ymax), 'cls': cls}.
        crop_pos: adjusted image position (list of four elements).
        target_size: image size (int).

    Returns:
        bbox_in_context: object bounding box location relative to image
          (list of four elements).
    """
    # rescaling.
    xmin = bbox_selected['bbox'][0]
    ymin = bbox_selected['bbox'][1]
    xmax = bbox_selected['bbox'][2]
    ymax = bbox_selected['bbox'][3]
    # transform the object box coordinate according to the cropped window
    x_scale = 1.0 * target_size / (crop_pos[2] - crop_pos[0])
    y_scale = 1.0 * target_size / (crop_pos[3] - crop_pos[1])
    xmin_ = (xmin - crop_pos[0]) * x_scale
    ymin_ = (ymin - crop_pos[1]) * y_scale
    xmax_ = xmin_ + (xmax - xmin) * x_scale
    ymax_ = ymin_ + (ymax - ymin) * y_scale
    bbox_in_context = [
        max(int(xmin_), 0),
        max(int(ymin_), 0),
        min(int(xmax_), target_size),
        min(int(ymax_), target_size)
    ]
    return bbox_in_context