所以我的问题是从列表img_array生成动画。上面的代码主要用于从文件夹中获取图像,对其进行注释,然后将其保存到数组中。我想知道是否有人有任何关于如何将图像数组中的图像转换为动画的建议。如有任何帮助,我们不胜感激!蒂娅。
我试过FFmepg之类的,但它们似乎都不起作用。我也尝试过在OpenCV中使用videowriter,但当我试图打开该文件时,我发现该文件类型不受支持或损坏。
import cv2
import numpy as np
import glob
import matplotlib.pyplot as plt
from skimage import io
import trackpy as tp
import pims
import pylab as pl
##########
pixel_min=23
min_mass=5000
Selector1=[1,2,3,4,5,6,7,11]
##########
frames = pims.ImageSequence('/Users/User/Desktop/eleventh_trial_2/*.tif', as_grey=True)
f1 = tp.locate(frames[0], pixel_min,minmass=min_mass)
plt.figure(1)
ax3=tp.annotate(f1,frames[0])
ax = plt.subplot()
ax.hist(f1['mass'], bins=20)
ax.set(xlabel='mass', ylabel='count');
f = tp.batch(frames[:], pixel_min, minmass=min_mass);
#f = tp.batch(frames[lower_frame:upper_frame], pixel, minmass=min_mass);
t=tp.link_df(f,10,memory=3)
##############
min_mass=8000#12000 #3000#2000 #6000#3000
pixel_min=23;
count=0
img_array = []
for filename in glob.glob('/Users/User/Desktop/eleventh_trial_2/*.tif'):
img = cv2.imread(filename)
height, width, layers = img.shape
size = (width,height)
img2 = io.imread(filename, as_gray=True)
fig, ax = plt.subplots()
ax.imshow(img)
#ax=pl.text(T1[i,1]+13,T1[i,0],str(int(T1[i,9])),color="red",fontsize=18)
T1=t.loc[t['frame']==count]
T1=np.array(T1.sort_values(by='particle'))
for i in Selector1:
pl.text(T1[i,1]+13,T1[i,0],str(int(T1[i,9])),color="red",fontsize=18)
circle2 = plt.Circle((T1[i,1], T1[i,0]), 5, color='r', fill=False)
ax.add_artist(circle2)
count=count+1
img_array.append(fig)
ani = animation.ArtistAnimation(fig, img_array, interval=50, blit=True,repeat_delay=1000)当我运行这个,我没有得到一个错误,但我不能保存的ani,因为在过去的尝试,也使用OpenCV videoWriter。
发布于 2019-07-18 22:52:48
我找到了一个工作,虽然不是最有效的。我使用os和plt.savefig()将图形保存在一个单独的目录中,然后使用ImageJ自动将按顺序编号并保存的图形转换为动画。它效率不高,但可以完成工作。我仍然对更有效的答案持开放态度。谢谢
https://stackoverflow.com/questions/57080908
复制相似问题