【发布时间】:2017-07-31 05:52:07
【问题描述】:
我使用以下代码在后台线程中运行网络摄像头。我必须进行繁重的处理,所以我这样做了,希望它能提高 fps
import cv2
import time
from threading import Thread
cap = cv2.VideoCapture(0)
threads = []
class WorkerThread(Thread):
def run(self):
print("start")
ret, frame = cap.read()
cv2.imshow('Face', frame)
if __name__ == '__main__':
try:
print("Trying to open camera")
while(cap.isOpened()):
thread = WorkerThread()
thread.start()
threads.append(thread)
time.sleep(0.35)
except KeyboardInterrupt:
for thread in threads:
thread.join()
cap.release()
问题是框架不可见。如何让它可见?
【问题讨论】:
-
sigh 每天至少有一个。
imshow没有waitKey。阅读documentation:“这个函数后面应该有waitKey函数,它会显示指定毫秒的图像。否则,它不会显示图像。”
标签: python multithreading opencv python-multithreading