python matplotlib在圖像上畫方框

今天用matplotlib畫方框,發現死活畫不上去,opencv一下子就畫上去了,但是jupyter用matplotlib居多,我這裏分享一下我顯示方框的代碼:

import numpy as np
import matplotlib.pyplot as plt # 導入繪圖包
from PIL import Image
import matplotlib.patches as patches

img_path='/media/data/projects/EyesDetection/eyes/眼部打碼/45度側面像/A005969.JPG'
img = Image.open(img_path)
# print(img.size)
fig,ax = plt.subplots(1)
ax.imshow(img)
plt.figure("Image")
for point1 in points:
    print(point1)
    rect=patches.Rectangle(xy=(point1[0][0],point1[0][1]),width=point1[1][0]-point1[0][0],height=point1[1][1]-point1[0][1],linewidth=2,fill=False,edgecolor='r')
    ax.add_patch(rect)

我的目的是把voc 2007格式的數據顯示出來

 

參考文獻

[1].matplotlib:如何在圖像上繪製一個矩形(matplotlib: how to draw a rectangle on image). https://www.it1352.com/896494.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章