0

I'm doing some python work for real-time video analysis.

About for 1 month... I've revised same code everyday, but there was no improvement. So I decided to write a question here.

**My Question : ** I finally got a real-time data (max intensity) from video camera, but I failed to draw a real-time graph using this data.

I tried to use Pipe(multiprocessing), but everytime I try this the python says '!_src.empty() in function 'cv::cvtColor', and other errors...

This is a code for extracting a max intensity from camera(video) in realtime.

import numpy as np
import cv2
import matplotlib.pyplot as plt

cap = cv2.VideoCapture(0)
fps = cap.get(cv2.CAP_PROP_FPS)

count = 0

while(True):
    ret, frame = cap.read()    

    vid = cv2.cvtColor(frame, cv2.IMREAD_COLOR)
    
    cv2.imshow('Interference',vid)  
    
    h, s, v = cv2.split(vid)  
    
    if(int(cap.get(1)) % fps == 0):
        for i in np.arange(fps):
            print(np.max(v))   
    
    if cv2.waitKey(1) & 0xFF == ord('q'):   
        break

And this is my failed code to extract the realtime data and make a realtime graph.

import numpy as np
import cv2
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from itertools import count
from multiprocessing import Process, Pipe

cap = cv2.VideoCapture(0)
fps = cap.get(cv2.CAP_PROP_FPS)
plt.style.use('fivethirtyeight')

count = 0


while(True):
 ret, frame = cap.read()  
 gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
 cv2.imshow('gray', gray)  
 h, s, v = cv2.split(vid)  
 def func0(pipe): 
    if(int(cap.get(1)) % fps == 0):
       px = np.max(v)
       for i in np.arange(fps):
         pipe.send(px)
         pipe.close(px)
         
 if cv2.waitKey(1) & 0xFF == ord('q'):   
        break    
    
    
 def func1(pipe):
    x_val = []
    y_val = [] 
    def animate():
        x_val.append(count())
        y_val.append(pipe)
        plt.cla()
        plt.plot(x_val, y_val)
        ani = FuncAnimation(plt.gcf(),animate,interval = 1000)
        plt.tight_layout()
        plt.show()  
        
      
 if __name__ == '__main__':
      a_pipe, b_pipe = Pipe()
      p0 = Process(target=func0, args=(a_pipe,))
      p0.start()
      p1 = Process(target=func1, args=(b_pipe.recv(),))
      p1.start()
  
      p0.join()
      p1.join()            

How can I try to draw a realtime graph from this data ?

If you give me any hint of this, I will really appreciated about it. Thank you.

I tried some code for extracting a realtime data and making a realtime graph. Finally I succeed to extract a realtime data from video, but failed the other one.

Can you please help me to make a realtime graph using the extracted data in realtime?

J.HAE
  • 1

0 Answers0