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.
答案 0 :(得分:0)
当队列为空时,Queue.get()
方法引发Queue.Empty
异常。您可能需要抓住并处理该问题,或者阻止它被提出。
try:
image = output_queue.get()
# display image
except Queue.Empty:
pass
为防止其发生:
if not output_queue.empty():
image = output_queue.get()
# display image