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 = 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()
image

Sep 16, 2020 in Python by Leonardo
• 120 points
1,010 views
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'.

Hi,

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,120 points
1,379 views
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,020 points
2,657 views
0 votes
1 answer

How I can remove day and time from TimeStamp?

You can follow the below given: '{:%Y-%m}'.format(dt.strptime(str(key), '%Y-%m-%d ...READ MORE

answered Nov 4, 2020 in Python by Gitika
• 65,890 points
480 views
+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,720 points
5,030 views
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,720 points
2,305 views
+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
• 58,100 points
1,543 views
+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
• 58,100 points
16,365 views
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,300 points
1,147 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP