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?
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)
Apparently
pip install python-opencv
is not working at all and should not be used. After I installed Opencv from their website it worked
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
Related
I dont know what to import and how to do this. How do I print and add a image in python.
I have tried nothing im just looking for suggestions.
In the console it's impossible, but you can use OpenCV, PIL, or matplotlib to display images.
With OpenCV you can display the pixel value in the console:
If you are interested in image manipulation check out Pillow. It's an image manipulation/processing library.
You can install it with:
python -m pip install Pillow
To load an image and show it use this:
from PIL import Image
im = Image.open("image.png")
im.show()
For more examples and information check out the official documentation.
I've been going round in circles for ages trying to figure this out. Why am I getting this attribute error? I've tried using absolute references, and get the same issue. PyCharm is also highlighting CascadeClassifier, cvtColor and COLOR_BGR2GRAY saying it cannot find reference in cv2.py. I'm not sure if more information is relevant to solving this problem, so please ask if more is needed.
import cv2
face_cascade = cv2.CascadeClassifier('read_only/haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('read_only/haarcascade_eye.xml')
grayed_images = []
for x in np_images:
gray_img = cv2.cvtColor(x, cv2.COLOR_BGR2GRAY)
grayed_images.append(gray_img)
print(x)
If I am correct, you are using an environment different from where you run.
Step1: In command line/terminal where you see the opencv-python when you run pip list:
run python command. Copy your code, check if it works (you can simply import cv2 alternatively)
If it works, my idea should be correct. Otherwise, there is something bigger.
Step 2: (Assuming step1 works.) In Pycharm, Under Run > Edit Configurations, change python interpreter to whichever interpreter is you are that has opencv.
Step2 better alternative: On Pycharm, open the terminal, pip install opencv-python. After that you should have the opencv.
Downgrade opencv to the version 4.5.5.64.
You can install opencv using
pip install opencv-python==4.5.5.64.
This works for me
I'm using Python 3.7.1 and OpenCV 4.0.0
I'm just testing FAST algorithm with various configurations, and I have problems with the drawKeypoints function. In fact, I copied OPenCV tutorial code, just to realize that the function needs a third argument, the output image. After that, everything was working, and I commited to the repo.
Later on, I had to format my pc, and reinstall everything. Now, whenever I try to run that code, it complains about module 'cv2' has no attribute 'drawKeypoints'. Here is the most basic code I had running after the format.
import numpy as np
import cv2
import sys
img = cv2.imread(sys.argv[1], 0)
fast = cv2.FastFeatureDetector_create()
kp = fast.detect(img,None)
img2 = cv2.drawKeypoints(img, kp, None, color=(255,0,0))
cv2.imshow('Original',img)
cv2.imshow('Detected',img2)
cv2.waitKey(0)
cv2.destroyAllWindows()
I've been looking, and I have no clue about what could be wrong with this code.
It looks related to this bug which has a solution in the git repository (sources), but not necessarily is updated in the installation using pip. It was merged on Dec 11 2018, so for the time of this question it was probably not updated.
Maybe getting an updated wheel could solve the problem or you can build it yourself from sources. Here you can also see how this is generated (the one from pip install) and also offers you the tool to build your own opencv wheel.
I am using opencv and Python3 to read webcam.
The webcam light keeps on even though I released the webcam.
I am doing:
webcam = cv2.VideoCapture(0)
webcam.release()
After the release command, if I try to read the cam I get: (False, None) but the webcam itself is still <VideoCapture 0EE62DC0>. I don't know if this is the issue, but the light keeps on until I kill all python script or python terminal.
I am on a Windows 10, python 3.5, opencv 4.0.1. Am I doing something wrong?
I had exactly the same problem. Was using python3.6 and opencv 3.4.2 (also on Windows10), reinstalled opencv-python version to 3.4.0.14. That worked for me.
Seems that there is a problem with opencv 3.4.2.
That specific version you can install by running the command:
pip install opencv-python==3.4.0.14
Same here, using c++ and OpenCV 3.4.3 on Windows10.
Problem seems related to MSMF backend, disabling creating a environment variable with value:
OPENCV_VIDEOIO_PRIORITY_MSMF=0
solve the problem. Source: here
I had the same problem.
My problem was solved when I changed the while loop condition from:
while(cap.isOpened()):
#Your code
with:
while(True):
ret, img = cap.read()
#Your code
Before changing the loop I also applied the following command on cmd prompt:
setx OPENCV_VIDEOIO_PRIORITY_MSMF 0
Please restart the PC once you applied the above command!
Hope this work for you too.
Cheers!!
I am trying to use scikit-image to do some research. The system is Windows 7 64bit, and the python version is 2.7, 64bit.
The first program I run is from: http://scikit-image.org/
The code is
from skimage import data, io, filter
image = data.coins() # or any NumPy array!
edges = filter.sobel(image)
io.imshow(edges)
io.show()
However, the problem happens, and the error message is:
C:\Python27\lib\site-packages\skimage\io_plugins\null_plugin.py:14:
RuntimeWarning: No plugin has been loaded. Please refer to
skimage.io.plugins()
for a list of available plugins.
warnings.warn(RuntimeWarning(message))
I believe that both Python and scikit-image are correctly installed. So, may I know what is wrong with it?
Any suggestion is appreciated. Many thanks.
Just had precisely the same issue on amazon linux. The issue is that skimage requires PIL, and PIL is not installed. In the latest skimage they added the dependency, but the version that I got installed with pip didn't have it yet.
The solution is
pip install Pillow
EDIT: and after that you will probably immediately face another issue, with skimage loading image, but not being able to read it (in particular, shape being empty tuple). Here's the solution
Why does scipy.ndimage.io.imread return PngImageFile, not an array of values