矩形图
程序员文章站
2022-04-03 16:53:29
...
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
#rectange3个参数,起点坐标,矩形宽度,矩形高度
rect = plt.Rectangle((0.1,0.1),0.5,0.3)
ax.add_patch(rect)
plt.show()
import matplotlib.pyplot as plt
fig = plt.figure() #创建图
ax = fig.add_subplot(111) #创建子图
plt.gca().add_patch(plt.Rectangle((0.1,0.1),0.5,0.3))
plt.show()
#roi框是在图像中画出来的,而图像的原点在左上角,但坐标轴的原点在左下角,所以即使Rectangle中参数一模一样,但在图像和坐标轴中画出来的不一样
def _vis_minibatch(im_blob, rois_blob, labels_blob, overlaps):
"""Visualize a mini-batch for debugging."""
import matplotlib.pyplot as plt
#print im_blob
count = 0
for i in xrange(rois_blob.shape[0]):
count += 1
rois = rois_blob[i, :]
print(rois)
im_ind = rois[0]
roi = rois[1:]
im = im_blob[im_ind, :, :, :].transpose((1, 2, 0)).copy()
im += cfg.PIXEL_MEANS
im = im[:, :, (2, 1, 0)]
im = im.astype(np.uint8)
cls = labels_blob[i]
plt.imshow(im)
#print 'class: ', cls, ' overlap: ', overlaps[i]
#print count
plt.gca().add_patch(
plt.Rectangle((roi[0], roi[1]), roi[2] - roi[0],
roi[3] - roi[1], fill=False,
edgecolor='r', linewidth=3)
)
plt.show()
上一篇: 燕昭王如果能多活20年,会不会改变历史?
下一篇: JavaScript日期格式化