[英]real time video processing using multithreading in Python
I am working on real time video processing using multithreading in Python.我正在使用 Python 中的多线程进行实时视频处理。 Here the processes are:
这里的过程是:
Threads put these frames in a priority queue ( input_queue
).线程将这些帧放入优先级队列 (
input_queue
)。 (I keep frames in sequential order) (我按顺序保持帧)
Threads begin to take frames from queue and process.线程开始从队列中获取帧并进行处理。
output_queue
for showing.output_queue
进行显示。output_queue
and shows.output_queue
读取帧并显示。 Here, output needs to be displayed instantaneously as processed video when capturing images from the camera. 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.
但是我运行我的项目,10 个线程从队列中非常快速地处理帧,我的输出视频在 5 秒后关闭。 Because of
output_queue
is empty.因为
output_queue
是空的。
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.我尝试将
time.sleep()
放在处理之前或读取帧之前,或者如果队列为空但此时输出视频开始很晚并再次关闭或视频反复打开和关闭。
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. Queue.get()
方法在队列为空时引发Queue.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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.