4

I'm getting a segmentation fault when I try to read and show an image with opencv in Python. I installed using:

pip3 install opencv-contrib-python

The code is only three lines:

import cv2 

im = cv2.imread('1.jpg')
cv2.imshow("image",im)

But I get this error:

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


Command terminated

Pillow shows the image fine, so I am assuming something secret went wrong with the installation. Does anybody know what the problem could be?

Memduh
  • 101
  • 1
  • 6
  • 1
    Same error has been reported [here](https://github.com/skvark/opencv-python/issues/46). It seems there is no straightforward way to solve it. but I suggest uninstall any version of installed OpenCV and then install opencv using pip: `sudo pip uninstall opencv-python ` – Salman May 05 '18 at 13:32
  • I get the same segfault at home on Ubuntu 16.04. So I tend to use the matplotlib calls to display an image on that machine. At work on Windows 7, it works fine. The [first few tutorials from the official docs](https://docs.opencv.org/3.4.1/d6/d00/tutorial_py_root.html) all use imshow, but by the time you get [to this tutorial](https://docs.opencv.org/3.4.1/d3/df2/tutorial_py_basic_ops.html), they occasionally use matplotlib. For my apps, I usually display my image in pyqt, so knocking up prototypes in matplotlib is not too annoying. – bfris May 05 '18 at 19:16

2 Answers2

0

if you are using anaconda:

$ conda install pyqt

tnx for:

https://stackoverflow.com/a/56544875/13510675

ashkan_sl
  • 21
  • 3
-4

I had the same issue and solved it uninstalling the libqt5x11extras5l library:

sudo apt-get remove libqt5x11extras5l
Cube
  • 28
  • 3
  • 3
    Those running linux distributions like Kubuntu would not want to do this since it uninstalls basically every aspect of the desktop environment. This breaks Plasma and any other Qt based environment. – smallpants Apr 02 '19 at 22:24