matplotlib: how to draw a rectangle on image

前端 未结 4 1734
名媛妹妹
名媛妹妹 2020-11-28 02:01

How to draw a rectangle on an image, like this:

import matplotlib.pyplot as plt
from PIL import Image
import numpy as np
im = np.array(Image.open(\'dog.png\'         


        
4条回答
  •  再見小時候
    2020-11-28 02:23

    From my understanding matplotlib is a plotting library.

    If you want to change the image data (e.g. draw a rectangle on an image), you could use PIL's ImageDraw, OpenCV, or something similar.

    Here is PIL's ImageDraw method to draw a rectangle.

    Here is one of OpenCV's methods for drawing a rectangle.

    Your question asked about Matplotlib, but probably should have just asked about drawing a rectangle on an image.

    Here is another question which addresses what I think you wanted to know: Draw a rectangle and a text in it using PIL

提交回复
热议问题