【发布时间】:2018-06-21 08:46:52
【问题描述】:
我对这里发生的事情感到茫然。我正在尝试运行 opencv VideoCapture 进程来读取帧并放入队列以供工作人员处理。
应用程序永远不会完成运行,因为 CameraProcess 实例似乎永远不会终止。经过一番调查,看起来相机在调用#release()后报告为关闭,但在主进程中被认为是打开的。
我不应该在 Process 中创建 VideoCapture 实例吗?
示例应用程序:
import cv2
from multiprocessing import Process, Event
from time import sleep
class CameraProcess(Process):
def __init__(self, camera_id, *args, **kwargs):
super(CameraProcess, self).__init__(*args, **kwargs)
self.shutdown = Event()
self.camera = cv2.VideoCapture(camera_id)
sleep(1)
print('Camera is opened? {}'.format(self.camera.isOpened()))
def run(self):
while not self.shutdown.wait(0.05):
print('Doing camera stuff')
sleep(1)
self.camera.release()
print('Camera is closed? {}'.format(not self.camera.isOpened()))
try:
camera = CameraProcess(0)
camera.start()
sleep(5)
camera.shutdown.set()
sleep(2)
print('Camera is closed? {}'.format(not camera.camera.isOpened()))
except KeyboardInterrupt:
pass
finally:
camera.terminate()
应用程序输出:
相机打开了?真的 做相机的东西 做相机的东西 做相机的东西 做相机的东西 做相机的东西 相机关了?真的 相机关了?错误的环境:
- Debian 延伸
- Python:3.5.3
- cv2:3.4.0
【问题讨论】:
标签: python opencv multiprocessing