多处理管理器无法 pickle <class 'cv2.Mat'>

问题描述 投票:0回答:1

我制作了一个多进程程序来分析来自相机的图像。第一个进程不断地从相机读取图像,第二个进程分析该图像,第三个进程包含用于返回图像的 HTTP 服务器。使用 multiprocessing.Manager 交换帧。

self.manager = multiprocessing.Manager()
self.frame = self.manager.Value(cv2.typing.MatLike, None)

以下代码初始化 ValueProxy 以在进程之间交换帧。这段代码在我的电脑上运行良好。但是,当将此程序部署到另一台机器上时,出现以下错误:

Traceback (most recent call last):
  File "/home/tablo/Apps/rvp-camera-service/src/main.py", line 7, in <module>
    camera_service = CameraService()
  File "/home/tablo/Apps/rvp-camera-service/src/camera_service.py", line 53, in __init__
    self.frame = self.manager.Value(cv2.typing.MatLike, None)
  File "/usr/lib/python3.10/multiprocessing/managers.py", line 723, in temp
    token, exp = self._create(typeid, *args, **kwds)
  File "/usr/lib/python3.10/multiprocessing/managers.py", line 608, in _create
    id, exposed = dispatch(conn, None, 'create', (typeid,)+args, kwds)
  File "/usr/lib/python3.10/multiprocessing/managers.py", line 89, in dispatch
    c.send((id, methodname, args, kwds))
  File "/usr/lib/python3.10/multiprocessing/connection.py", line 206, in send
    self._send_bytes(_ForkingPickler.dumps(obj))
  File "/usr/lib/python3.10/multiprocessing/reduction.py", line 51, in dumps
    cls(buf, protocol).dump(obj)
_pickle.PicklingError: Can't pickle <class 'cv2.Mat'>: it's not the same object as cv2.Mat

两个系统都有opencv 4.9.0和python 3.10.6。到目前为止我不明白为什么行为不同

python-3.x opencv multiprocessing synchronization pickle
1个回答
0
投票

对我有帮助的是更改 ValueProxy 声明中的第一个参数(从 cv2.typing.MatLike 到 cv2.Mat)

© www.soinside.com 2019 - 2024. All rights reserved.