问题重述
QObject::moveToThread: Current thread (0x4d7ef90) is not the object's thread (0x54eb7b0).
Cannot move to target thread (0x4d7ef90)
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/xilm/anaconda3/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, webgl.
Aborted (core dumped)
解决方案
参考了这篇博客,发现是opencv和pyqt5同时使用的问题;
于是在代码中添加:
import os
from PyQt5.QtCore import QLibraryInfo
# from PySide2.QtCore import QLibraryInfo
import cv2
os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = QLibraryInfo.location(
QLibraryInfo.PluginsPath
)
效果
成功运行