【问题标题】:cv2.destroyAllWindows() is not implemented when installing opencv-python-headless [duplicate]安装 opencv-python-headless 时未实现 cv2.destroyAllWindows() [重复]
【发布时间】:2021-04-29 20:37:58
【问题描述】:

为了解决:https://pastebin.com/raw/my6VXj3H错误简述如下:

Got keys from plugin meta data ("xcb")
loaded library "/home/mona/venv/vision/lib/python3.8/site-packages/cv2/qt/plugins/platforms/libqxcb.so"
QObject::moveToThread: Current thread (0x34390e0) is not the object's thread (0x3527410).
Cannot move to target thread (0x34390e0)

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/mona/venv/vision/lib/python3.8/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.

根据 Qt 论坛中的建议,我决定删除 opencv-python 并安装 opencv-python-headless

这最初解决了问题,但现在抛出以下 opencv 错误。

如何解决这个 opencv 错误?

(vision) mona@goku:~/research/code/vision/integration$ pip install --upgrade pip
Requirement already satisfied: pip in /home/mona/venv/vision/lib/python3.8/site-packages (20.3.3)
Collecting pip
  Downloading pip-21.0-py3-none-any.whl (1.5 MB)
     |████████████████████████████████| 1.5 MB 3.6 MB/s 
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 20.3.3
    Uninstalling pip-20.3.3:
      Successfully uninstalled pip-20.3.3
Successfully installed pip-21.0
(vision) mona@goku:~/research/code/vision/integration$ pip install opencv-python-headless
Collecting opencv-python-headless
  Using cached opencv_python_headless-4.5.1.48-cp38-cp38-manylinux2014_x86_64.whl (37.6 MB)
Requirement already satisfied: numpy>=1.17.3 in /home/mona/venv/vision/lib/python3.8/site-packages (from opencv-python-headless) (1.19.5)
Installing collected packages: opencv-python-headless
Successfully installed opencv-python-headless-4.5.1.48

运行我的代码后,出现以下错误:

    cv2.destroyAllWindows()
cv2.error: OpenCV(4.5.1) /tmp/pip-req-build-jhawztrk/opencv/modules/highgui/src/window.cpp:645: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa 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'

【问题讨论】:

  • 您引用的链接似乎已损坏。你能更新一下吗?
  • headless = 不支持 GUI(它甚至在 package description 中解释了这一点)......但由于某种原因,您试图调用 GUI 函数。
  • @YunusTemurlenk 链接没有损坏我现在又试了一次
  • @MonaJalal 您是否尝试过此处显示的任何建议:How to fix the error “QObject::moveToThread:” in opencv in python?。看起来这可能是由您的系统 pyqt 和 opencv 内置的系统之间的冲突引起的。
  • @MonaJalal 不要只看接受的答案,因为“接受”通常并不意味着“正确”。通读所有答案以及 cmets,因为您可能会从中学到更多。

标签: python qt opencv computer-vision pyqt5


【解决方案1】:

我安装的最新版本的 opencv-python 导致了 pyqt5 的问题。所以我卸载了它并安装了以下版本:

$ pip install opencv-python==4.3.0.36

添加以下信息以防对未来的读者有所帮助。

这是我的 pyqt 版本:

$ pip list|grep Qt
PyQt5                  5.15.2
PyQt5-sip              12.8.1


$ python
Python 3.8.5 (default, Jul 28 2020, 12:59:40) 
[GCC 9.3.0] on linux

$ pip --version
pip 21.0 from /home/mona/venv/vision/lib/python3.8/site-packages/pip (python 3.8)

$ lsb_release -a
LSB Version:    core-11.1.0ubuntu2-noarch:security-11.1.0ubuntu2-noarch
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.1 LTS
Release:    20.04
Codename:   focal

致谢:https://stackoverflow.com/a/63350799/2414957

【讨论】:

    猜你喜欢
    • 2014-05-06
    • 2021-07-12
    • 2023-02-01
    • 2021-02-15
    • 2021-11-26
    • 2016-10-13
    • 1970-01-01
    • 1970-01-01
    • 2019-07-22
    相关资源
    最近更新 更多