Hi! I need to create a graphic that shows in real time RGB from a video. I know that I have to capture a frame and plot 3 channels in a graphic and in the axis x plot time. But I am having a error. Could help me? Or do you have any ideas that how can I write this code?
I am trying to develop the code below but I am having a error:
import cv2
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.animation import FuncAnimation
capture = cv2.VideoCapture(0)
ret, frame = capture.read()
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
while True:
ret, frame = capture.read()
cv2.imshow('Frame', frame)
if not ret:
break
def animate(i):
b, g, r = cv2.split(frame)
xs = []
ys = []
for line in b:
if len(line) > 1:
x, y = np.prod(frame.shape)
xs.append(x)
ys.append(y)
ax1.clear()
ax1.plot(xs, ys)
ani = FuncAnimation(fig, animate, interval=1000)
plt.show()
keyval = cv2.waitKey(1) & 0xFF
if keyval == ord('q'):
break
capture.release()
cv2.destroyAllWindows()