If I have clip and need to process each frame and then show frames (display them). I found many examples on how you can get frames of clip and then save (write) them as new video. However, I tried to iterate on each frame and then show each processed image, but the Matplotlib show only one image after the loop finished.
clip = VideoFileClip(filename)
for frame in clip.iter_frames():
new_frame= Fun(frame)
plt.imshow(new_frame)
update frame in matplotlib with live camera preview
I found this link but it uses frames from the camera, I need to display processes images as they received from the Fun one by one. So I don't want to save it or create a list of processed frames and then show them, I need to do it one by one.
I used the second method from the link, but it prints only 0, 0 and only shows the first frame! It seems it can't change the index to go to the next frame!
import cv2
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
index =0
inF=[]
for frames in clip.iter_frames():
inF.append(frames)
global inF
def grab_frame():
print(index)
frame = inF[index]
return cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
#Initiate the two cameras
cap1 = clip
#create two subplots
ax1 = plt.subplot(1,2,1)
#create two image plots
im1 = ax1.imshow(grab_frame())
def update(i):
global index
im1.set_data(grab_frame())
index+=1
ani = FuncAnimation(plt.gcf(), update, interval=10)
plt.show()
Could you please help me? Any hint?
Thanks