I am working on real time video processing using multithreading in Python. Here the processes are:
Threads put these frames in a priority queue (input_queue
). (I keep frames in sequential order)
Threads begin to take frames from queue and process.
output_queue
for showing.output_queue
and shows. Here, output needs to be displayed instantaneously as processed video when capturing images from the camera. (maybe five seconds behind.)Actually I do these processes. But I run my project, 10 threads process frames very quickly from queue and my output video closes after 5 secs. Because of output_queue
is empty.
I try to put time.sleep()
before processing or before reading frames or if queue is empty but in this time the output video begins very late and again closes or video is repeatedly opening and closing.
How should I go about this? Thank you for your help.
The Queue.get()
method raises the Queue.Empty
exception when the queue is empty. You probably need to catch and handle that, or prevent it from being raised.
try:
image = output_queue.get()
# display image
except Queue.Empty:
pass
To prevent it from happening:
if not output_queue.empty():
image = output_queue.get()
# display image