[Python] How to draw a rectangle on image

Discussão em 'Python' iniciado por Stack, Abril 20, 2025.

  1. Stack

    Stack Membro Participativo

    How to draw a rectangle on an image, like this: [​IMG]

    import matplotlib.pyplot as plt
    from PIL import Image
    import numpy as np
    im = np.array(Image.open('dog.png'), dtype=np.uint8)
    plt.imshow(im)


    To make it clear, I meant to draw a rectangle on top of the image for visualization, not to change the image data.

    So using matplotlib.patches.Patch would be the best option.

    Continue reading...

Compartilhe esta Página