我试图找到一种方法将matplotlib窗口内容的副本直接复制到内存中 - 我想避免将其保存到中间PNG文件中,只是将其读回内存,如下所示 . 有什么建议?谢谢 .
from matplotlib import pyplot as plt
# draw into window with detected objects bounding boxes
ax = utils.viz.plot_bbox(img, bbox, scores=scores, labels=labels,
thresh=ARGS.thresh, class_names=CLASSNAMES,
absolute_coordinates=False)
plt.show(block=False)
# capture contents of window to disk
plt.savefig ('out.png')
# read from disk for use down stream
img2 = cv2.imread('out.png')
# use img2 down stream
谢谢
1 回答
你可以使用
fig.canvas.tostring_rgb
. 以下是一些示例代码,注释中的详细信息 .第一个情节
导出的缓冲区