脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - python 含子图的gif生成时内存溢出的方法

python 含子图的gif生成时内存溢出的方法

2021-08-03 00:25睡觉不准打呼噜 Python

今天小编就为大家分享一篇python 含子图的gif生成时内存溢出的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

今天想用python做个demo,含两个子图的动态gif,代码如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import matplotlib.pyplot as plt
import imageio,os
import matplotlib
 
 
# plt.ion()
 
fig=plt.figure(0)
ax1=plt.subplot(121)
ax2=plt.subplot(122)
 
ax1.set_title('input')
ax2.set_title('GT')
 
 
for i in range(1000):
  img1=plt.imread('F:\\pythonprogram\\test_bord/path\\enc_in_img\\{}.png'.format(i))
  img2 = plt.imread('F:\\pythonprogram\\test_bord/path\\dec_out_img\\{}.png'.format(i))
  ax1.imshow(img1)
  ax2.imshow(img2)
  # ax2.axis('off')
  plt.pause(0.00001)
  plt.cla()
 
plt.show()

首先分别将画布分为两块,分别循环读如图片,显示图片后暂停,再清除原图像~

但是由于plt.cla()只能作用于最后一个子图,第一块子图读取过程中占用大量内存导致内存溢出,目前没找到解决办法。

最后在matlab上完成这个工作。

以上这篇python 含子图的gif生成时内存溢出的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/shuijiaobuzhundahulu/article/details/92799495

延伸 · 阅读

精彩推荐