-1

in order to resolve: https://pastebin.com/raw/my6VXj3H error briefly stated below:

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.

I decided to remove opencv-python and install opencv-python-headless based on a suggestion in Qt Forum.

This solved the problem initially but now throws the following opencv error.

How can I solve this opencv error?

(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

After running my code, here's the error:

    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'
Mona Jalal
  • 34,860
  • 64
  • 239
  • 408
  • The link you refered seems broken. can you update it ? – Yunus Temurlenk Jan 26 '21 at 06:14
  • 1
    `headless` = no GUI support (it even explains that in the [package description](https://pypi.org/project/opencv-python-headless/)) .... yet for some reason you're trying to call a GUI function. – Dan Mašek Jan 26 '21 at 10:38
  • @YunusTemurlenk the link is not broken I tried it again now – Mona Jalal Jan 26 '21 at 16:46
  • @DanMašek could you suggest how to handle that qt and cv2 problem other than using opencv-python-headless package? – Mona Jalal Jan 26 '21 at 16:46
  • 2
    @MonaJalal Have you tried any of the suggestions shown here: [How to fix the error “QObject::moveToThread:” in opencv in python?](https://stackoverflow.com/q/46449850/984421). It looks like this may be caused by a conflict between your system pyqt and the one built into opencv. – ekhumoro Jan 26 '21 at 17:26
  • @ekhumoro yeah I just did https://askubuntu.com/questions/1311142/libopencv-highgui2-4v5-depends-libpng12-0-1-2-13-4-but-it-is-not-going-t and ended up with further problems. Currently, working on it – Mona Jalal Jan 26 '21 at 17:34
  • 1
    @MonaJalal Don't just look at the asccepted answer, since "accepted" often does not mean "correct" on SO. Read through all the answers, and also the comments, as you will likely learn more from that. – ekhumoro Jan 26 '21 at 17:39

1 Answers1

2

The newest version of opencv-python that I had installed was causing the problem with pyqt5. So I uninstalled it and installed the following version:

$ pip install opencv-python==4.3.0.36

Adding the following info in case it might help future readers.

Here's my pyqt version:

$ 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

Credits: https://stackoverflow.com/a/63350799/2414957

Mona Jalal
  • 34,860
  • 64
  • 239
  • 408