Real time RGB graph from video

0 votes

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 =

fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)

while True:
    ret, frame =
    cv2.imshow('Frame', frame)

    if not ret:

    def animate(i):

        b, g, r = cv2.split(frame)
        xs = []
        ys = []
        for line in b:
            if len(line) > 1:
                x, y =
        ax1.plot(xs, ys)

    ani = FuncAnimation(fig, animate, interval=1000)

    keyval = cv2.waitKey(1) & 0xFF

    if keyval == ord('q'):


Sep 15 in Python by Leonardo
• 120 points
Hey, @Leonardo,

Kindly post your error logs here. You have just given the code, kindly paste the error so that we can resolve your isue ASAP.

Thank you for your answer! Let me explain better what I need. While the webcam is opened, I want to show a graph that has at the axis 'x' time in seconds and at the axis 'y' pixel value. Three channels, three lines showing the variation of the channel beyond the time. The code that I wrote above I am trying to do that. Passing an empty list while the loop while is running. But I don't know whether my logic is right or not

The error that I am getting is: 

'numpy.ndarray has no attribute split'.


Check your function animate(). You have used cv2.split() inside your function. But inside the function how you passed the value of the frame?

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

0 votes
1 answer

Problem in real time matplotlib plotting

Hi Sucheta, The error I can see in ...READ MORE

answered May 24, 2019 in Python by sampriti
• 1,100 points
0 votes
1 answer

How to write a python script for downloading a video from YouTube and saving it to a directory?

First download pytube using the following code  pip ...READ MORE

answered Sep 4, 2019 in Python by Neel
• 3,010 points
+2 votes
2 answers

How can I plot a k-dsitance graph using python?

Hi there, instead of sklearn you could ...READ MORE

answered Apr 10, 2018 in Python by charlie_brown
• 7,780 points
0 votes
1 answer

How can I find out the index of an element from row and column in Python?

You probably want to use np.ravel_multi_index: [code] import numpy ...READ MORE

answered Apr 16, 2018 in Python by charlie_brown
• 7,780 points
0 votes
1 answer

How can I convert a list of dictionaries from a CSV into a JSON object in Python?

You could try using the AST module. ...READ MORE

answered Apr 17, 2018 in Python by anonymous
0 votes
2 answers

how to print the current time using python?

print( READ MORE

answered Feb 14, 2019 in Python by Shashank
• 1,370 points
+1 vote
1 answer

How to create plots using python matplotlib in IPython notebook?

I think you should try: I used %matplotlib inline in ...READ MORE

answered Aug 8, 2018 in Python by Priyaj
• 57,680 points
+1 vote
1 answer

How to handle Real-Time Matplotlib Plotting

To draw a continuous set of random ...READ MORE

answered Sep 26, 2018 in Python by Priyaj
• 57,680 points
0 votes
1 answer

How to increase plt.title font size?

Try the following : import matplotlib.pyplot as plt plt.figtext(.5,.9,'Temperature', ...READ MORE

answered Feb 11, 2019 in Python by SDeb
• 13,250 points