【发布时间】: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