How to get co-ordinates in Pixel

#5
by rdhoundiyal - opened

H, How to get co-ordinates in Pixel .

Show Lab org

Hi @rdhoundiyal basically, once you receive the output [x,y] as shown in our quick start, what you need to do just using the width / height to multiple [x,y] so that you can get the absolute coordinate,

as shown in our function

def draw_point(image_input, point=None, radius=5):
    if isinstance(image_input, str):
        image = Image.open(BytesIO(requests.get(image_input).content)) if image_input.startswith('http') else Image.open(image_input)
    else:
        image = image_input

    if point:
        x, y = point[0] * image.width, point[1] * image.height
        ImageDraw.Draw(image).ellipse((x - radius, y - radius, x + radius, y + radius), fill='red')
    display(image)
    return
KevinQHLin changed discussion status to closed

Sign up or log in to comment