1

I installed opencv on my Ubuntu 14.04 system system with

pip install python-opencv

my Python version is 2.7.14

import cv2
cv2.__version__

tells me that I have the OpenCV version 3.4.0.

After that I wanted to follow the tutorial on the OpenCV website

import numpy as np
import cv2 as cv
img = cv.imread('messi5.jpg',0)
print img

It works fine until this point, but then I am supposed to enter

cv.imshow('image',img)

and I get the following error:

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

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

QPixmap: Must construct a QApplication before a QPaintDevice

Does anyone know what the problem is?

9
  • what does "print img" show? Commented Feb 1, 2018 at 11:02
  • Unrelated : why 2.7? why not 3.6.x ? Commented Feb 1, 2018 at 11:03
  • Try from matplotlib import pyplot as plt. Commented Feb 1, 2018 at 11:03
  • @jms print img shows the rgb values Commented Feb 1, 2018 at 11:06
  • @Thomas Kühn this doesnt appear to change anything Commented Feb 1, 2018 at 11:07

3 Answers 3

1

Try checking if the image you are reading is loading

image = cv2.imread(filepath,0) #0 for gray scale
if image is None:
    print "Cant Load Image"  
else:
    cv2.imshow("Image", image)
    cv2.waitKey(0)
Sign up to request clarification or add additional context in comments.

Comments

1

Apparently

pip install python-opencv

is not working at all and should not be used. After I installed Opencv from their website it worked

Comments

0

seems hard to install opencv on ubuntu, I finally get it with a docker image

https://hub.docker.com/r/jjanzic/docker-python3-opencv/

or you can download sources and make install as described on https://milq.github.io/install-opencv-ubuntu-debian/ using bash script

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.