python - 如何修复python中opencv中的错误 "QObject::moveToThread:"?

标签 python qt opencv

我在 python 中使用 opencv2 和代码

import cv2
cv2.namedWindow("output", cv2.WINDOW_NORMAL)       
cv2.imshow("output",im)
cv2.resizeWindow('output', 400,400)
cv2.waitKey(0)
cv2.destroyAllWindows()

我的错误是

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

我调试发现在使用cv2.waitKey(0)时出现了。我该如何解决?谢谢

更新:我使用的是 3.3.0.0。如果我使用旧版本,我会出错

OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvDestroyAllWindows, file /io/opencv/modules/highgui/src/window.cpp, line 577
Traceback (most recent call last):
  File "tools/demo_handbone.py", line 220, in <module>
    demo(net, im_name)
  File "tools/demo_handbone.py", line 159, in demo
    cv2.destroyAllWindows()
cv2.error: /io/opencv/modules/highgui/src/window.cpp:577: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvDestroyAllWindows

最佳答案

我遇到了同样的问题,对我来说是 opencv-python 版本问题。
我的 Linux 机器的环境如下:

$ cat /etc/lsb-release 
...
DISTRIB_DESCRIPTION="Ubuntu 18.04.5 LTS"
$ date
Tue Aug 11 11:43:16 KST 2020
$ python --version
Python 3.7.8
$ pip list|grep Qt
PyQt5                5.15.0
PyQt5-sip            12.8.0
$ pip list|grep opencv-python
opencv-python        4.3.0.38

我将 opencv-python 4.3.0.38 降级为 4.3.0.36

$ pip uninstall opencv-python
$ pip install opencv-python==4.3.0.36
$ pip list|grep opencv-python
opencv-python        4.3.0.36

关于python - 如何修复python中opencv中的错误 "QObject::moveToThread:"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46449850/

相关文章:

Python:通过搜索 XML 树将值附加到现有字典条目

python - 为什么 scipy.optimize.curve_fit 没有产生最适合我的点的线?

qt - 将 -std=gnu++11 编译器标志添加到 QMake

python - 如何使用同一图片的二进制蒙版图像裁剪图像以去除python中的背景?

macos - OpenCV VideoWriter write() 函数在 C++ 中的 MAC 操作系统上失败

c++ - 在openCV中计算字符串的长度(以像素为单位)

Python数组: Take two and skip two

python - 你能在 tkinter 的形状上添加回调/命令吗

c++ - 按下 QDialog Cancel 或 OK 时如何调用函数?

c++ - QListWidget共享同一个模型