gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 17:47:36 25 4
gpt4 key购买 nike

我在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com