问题
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?
回答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)
回答2:
Apparently
pip install python-opencv
is not working at all and should not be used. After I installed Opencv from their website it worked
回答3:
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
来源:https://stackoverflow.com/questions/48561126/python-opencv-imshow-fails