def crop_img(img, leaf):
    """
    For a given image and leaf position, returns the img, cropped to the leaf
    :param img: image that needs to be cropped
    :param leaf: {'x': int, 'y': int, 'width': int, 'height': int}
    :return: cropped image
    """
    height = leaf['height']
    width = leaf['width']
    x = leaf['x']
    y = leaf['y']
    if x < 0:
        x = 0
    if y < 0:
        y = 0

    cropped = img[y:y + height, x:x + width]
    # cv2.imshow("cropped", cropped)
    # cv2.waitKey(0)
    return cropped