I am doing a robotic project on raspberry pi in which i need frame from a webcam, attached to raspberry pi, continuously so i am extracting frames from videocapture()
in a separate thread than main program and saving the frames in a queue. The problem is that, when i run the program , initially CPU usage is normal i.e. 30-40 max in each core of pi but after a while CPU usage on one core reaches to 100 % while other 3 cores are less than 20% which slows down the program.
I've searched a lot but couldn't find any related solution. I am not able to understand what the problem is, is it thread (python
GIL
problem) or there is something else.
Any suggestions would be helpful.
These are the function in camera module which are getting the frame and saving in queue
self.framerate_ms = 1.0/float(20)
def start(self):
if self.t:
return
f = None
if self.camera_type == USB:
f = self.update_usb
self.t = Thread(target=f, args=())
#self.t.daemon = True
self.t.start()
def update_usb(self):
while True:
if self.stopped:
return
(grabbed, frame) = self.camera.read()
if not grabbed:
self.stop()
return
if self.Q.full():
self.Q.get()
self.Q.put(frame)
self.ready = True
#sleep(self.framerate_ms)
ps sorry for bad English i am not native English speaker.