时间:2020-07-16 python教程 查看: 1206
当要处理批量图片,且每张图片都要进行显示时,用plt.imshow() plt.show()会出现内存泄漏, 管理器中看到其中一个python进程的内存不断上涨,目前有找到解决方法
from matplotlib import pyplot as plt
...
for...:
...
plt.figure(figsize=IMAGE_SIZE)
plt.imshow(image_np)
plt.show()
补充知识:python在内存中读取base64图片
import base64
import skimage.io
import matplotlib.pyplot as plt
def base64_to_rgb(base64_str):
"""
默认base64中的图像为rgb,直接转换成即可
:param base64:
:return:
"""
if isinstance(base64_str, bytes):
base64_str = base64_str.decode("utf-8")
imgdata = base64.b64decode(base64_str)
img = skimage.io.imread(imgdata, plugin='imageio')
return img
base = 'R0lGODlhdQAmAKIAAOYyL+rU4llg6Jmd8e92dCky4eEGAv///yH5BAAAAAAALAAAAAB1ACYAAAP/eLrc/jC2IEoZMATJu/9gyFVWIUyksIls677LUJbrEcxWDe98f+CWk4I0w/iOSNANKJQBC8mo9LEEDp8F3XR7rOIU2Cx3jHwKsUKyWqRhEEvGN3xN91BoCq8l9tTW/244Rk4mOkBGgIl8VjF+d4V5A5KKf3IWiCCEOZRraGxPnGqeIZpzoVyjDBptDpYmp1yumI9BWq5QUQS6fn+lm3lYmLdSBsW8xcjJBgAABLwfAMhXRQt6ODWuJ8rb3AYK0d3h4OHIBC7jC0TCYb/ZB+Th3/Dc4/PmLOgSvkwK+xjMAAEmCwhQnrc8rFSxGkiwnoFnEnTp0mdqlJw0DgIggwgu/08xABM+KkhGJdm9JJqMhGkyQIAATA3HxVwATuO8jyQfECiXJyYzZwzyOSilcqWEmzkP1ES6LGmDcStshjspNJAgMOwwNmBajGZXGyJVhU22quxOaR7hrahqQ52DC1jh/nj1AG0Eux3BLgu59x3SkxHO9mVLhJfcirUc2IWA96vUbvf+QkNbldCgIGCKHi6h1e/Bu1+VOiYHYAVTwBHyCfWyocoZzZovbf3ok1njzx/IltUg+GG13twMfta0gdDruLH3MOD6uaPDcI8hCAZp4/k24elmtOacGXlcPAuYe/VmnVt0ncioTyeYU+ibQRWOHyCRXEz40BDyivYWYBzQAIbTbeBUNTIZRF1QlNlVimGdfffLSPg9oJ9+vVV4H23smWSgFqrZZc0AWiTWACMXcjAhfgAqgxpXKwDXDXbZsSPjVcth6NNtZj3nzCpM1dDfPDACM+OQ9l2I1HiPlfNceentMoGLygQp5Eq3aKfYaUgOdBIB9RyYSEsmvASiFgG0RMRLEK2RAAA7'
img = base64_to_rgb(base)
plt.imshow(img)
plt.show()
以上这篇解决python中显示图片的plt.imshow plt.show()内存泄漏问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持python博客。