当我 运行 cv.imshow 时,出现错误 "QSocketNotifier: Can only be used with threads started with QThread"

When i run cv.imshow, I got error "QSocketNotifier: Can only be used with threads started with QThread"

我用dnf安装opencv

sudo dnf install opencv opencv-contrib opencv-core opencv-devel opencv-doc python3-opencv

然后我运行 python 代码:

import cv2 as cv
img = cv.imread('/home/a/dog.jpeg')
cv.imshow('dog', img)

然后我得到如下错误:

QSocketNotifier: Can only be used with threads started with QThread

我的系统是 Fedora 34.

为什么以及如何解决?

问题出在韦兰身上。您的显示服务器很可能是默认使用 Wayland 的 Gnome。 Solution 1:

switched the session to Gnome with Xorg which uses X11 as the display server, the Qt GUI looks normal.

方案二: 我想这是 fedora 中的一个常见错误。通过快速搜索不同的 fedora 版本(30、31, 32 SO thread、33),我发现了许多类似的问题。这就是为什么,您可以尝试从源代码而不是 dnf 包管理器构建 opencv 并设置 WITH_QT 标志为 OFF。

不确定 backbone 问题,但如果 R​​edHat 关心,the bug tracker 可能会有所帮助。