Home > Enterprise >  How to crop an image given proportional coordinates with Python PIL?
How to crop an image given proportional coordinates with Python PIL?

Time:11-23

I have an image with dimension (1920x1080) with proportional coordinates provided with a description of the detected person region. I want to crop only the detected person from the image using provided proportional coordinates. I looked up enter image description here

def img_crop(url, box):
    box = {
            'x0': 0.974, 
            'x1': 0.922, 
            'y0': 0.502, 
            'y1': 0.315
    }
    img = Image.open(requests.get(url, stream=True).raw)
    h, w = img.size
    print(img.size)
    return img.crop((box['x0']*h, box['y0']*w, box['x1']*h, box['y1']*w))

This results in the following error

ValueError: Coordinate 'right' is less than 'left'

CodePudding user response:

But your drawing contradict your own description of what x0,y0,x1,y1 are. It is said (in a enter image description here

  • Related