【问题标题】:cv2.aruco and plt.figure causes qt.qpa.plugin: Could not load 'xcb'cv2.aruco 和 plt.figure 导致 qt.qpa.plugin: 无法加载 'xcb'
【发布时间】:2021-07-19 00:59:51
【问题描述】:

以下python代码:

import matplotlib.pyplot as plt
from cv2 import aruco

fig = plt.figure(figsize=(3,6))

导致以下错误:

QObject::moveToThread: Current thread (0x555e3d4d0a60) is not the object's thread (0x555e3db4a0f0).
Cannot move to target thread (0x555e3d4d0a60)

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/r00tr4t/.local/lib/python3.9/site-packages/cv2/qt/plugins" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: xcb, eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx.

Aborted (core dumped)

我测试了设置调试标志:

export QT_DEBUG_PLUGINS=1

完整的日志可以在这里找到http://ix.io/37V5

但是,如果您删除 cv2 部分一切正常,这是为什么呢?

import matplotlib.pyplot as plt
# from cv2 import aruco

fig = plt.figure(figsize=(3,6))

测试于:

  • ArchLinux 5.9.10-arch1-1
  • Python 3.9.3
  • cv2.version.opencv_version '4.5.1.48'
  • matplotlib.版本 '3.4.1'

编辑: 刚刚意识到我的代码有点简单,可以解释为 cv2.aruco 没有安装,但是,如果我实现这个代码:

import matplotlib.pyplot as plt
from cv2 import aruco

print(aruco.Dictionary_get(aruco.DICT_6X6_250))

fig = plt.figure(figsize=(3,6))

结果是<aruco_Dictionary 0x7f14d109db90> 即已安装。

【问题讨论】:

  • 尝试更改导入顺序:from cv2 import arucoimport matplotlib.pyplot as plt
  • 哈哈。对于那个特殊情况,它有效,但它在我的官方代码中不起作用(大约 2k 行)。它没有用。
  • 您能否提供您在执行export QT_DEBUG_PLUGINS=1 时获得的日志以及我向您指示的新导入顺序?您已经有类似的日志,但我的目标是比较它们。
  • 太长了,我在ix.io/37V5里面提供了

标签: python matplotlib pyqt cv2


【解决方案1】:

尝试安装opencv-contrib-python

pip3 install opencv-contrib-python

【讨论】:

  • 我请朋友在他的电脑上测试它,它在那里工作正常。也许我只需要重新启动计算机。 (正常运行时间 141 天)
猜你喜欢
  • 2022-06-23
  • 1970-01-01
  • 2021-09-03
  • 2021-07-20
  • 2016-01-16
  • 2022-08-11
  • 2022-06-15
  • 1970-01-01
  • 2013-07-23
相关资源
最近更新 更多