PIL Image data can not convert to float - python

I am working through a few Python image tutorials. It seems that the greatest challenge every time I try something new in Python is just getting it to work! I have imported the PIL code and am trying to run the short snippet below in Spyder on Python 2.7.8
from PIL import Image
from pylab import *
im = array(Image.open('test.jpg'))
imshow(im)
show()
When I do so, I get "Image data can not convert to float" error.
I tried to do the same in an iPython notebook and received the same error. When I run pip freeze it shows that I have PIP 1.1.7 installed. Of note, I installed PIP using the executable at the host site, not with PIP. I am also using the Spyder instance that comes with Anaconda.
Any advice?

After trying other solutions posted I discovered that PIL may be out of date with my newer Python build (see link in comments). Once Pillow was installed the issue was resolved.

Related

Converting Python file to .exe

I have a Python file that I want to convert to .exe using pyinstaller.
I get this error,
I searched how to solve this and the solution was to install Pillow package. After I installed it, I face the same error again and I don't know what else to do.
Some versions of PIL have an exposed Image class. Try this:
import Image
You can get more info on this from the official tutorial.

How can I recognize numbers from a picture using python and an OCR engine?

Hi everyone what I'm trying to do is to make python recognize this picture just the number 96 in a white background. and to show me a "96" in string, that's all.
For that purpose I have installed pytesseract into python using the command prompt (pip install pytesseract), I also have installed Pil (which is pillow now, and also installed it using command prompt), Tesseract OCR engine is also installed on my computer, I downloaded it and installed it, is in my environmental variables (typing the path command in the command prompt it shows me Tesseract-OCR), and finally I also downloaded the pytesser, unzipped the file to the directory: C:\Python27\Lib. Almost forgot to mention, the version of python I have is 2.7.12 and the OpenCV version installed is 3.1.0.
What I did, is to run the following script:
from PIL import Image
import pytesseract
img=Image.open('E:\Alex2016\Python OpenCV\Scripts\imagenFinal.jpg')
a=pytesseract.image_to_string(img)
print(a)
img.show()
And it only shows me the image but no "96" string. I'm new at this guys, I don't even know if I'm really using the Tesseract-OCR which I know is a super powerful engine for these things. I'm runing my script in the python shell. I have to mention also that I couldn't be able to make pytesser work, because when trying to "import pytesser" or doing "from pytesser import *" like I've seen in other sites, I get this error
import pytesser
ImportError: No module named pytesser
I think this image is pretty understandable and noisy free, so guys if you could tell me how I can detect numbers with these tools or if there is any other that could make this, thanks a lot for your time guys I'm new at this stuff but I'm really interested on this field of science, the computer vision technology.

'ImportError: No module named pillow' in PyCharm

I'm getting an error while using PyCharm which doesn't allow me to import the pillow module even though I have it installed as a package in the project interpreter. Any help is greatly appreciated!
http://imgur.com/a/DfjC3
While the name of the package is pillow, it is a replacement for PIL and uses the PIL for the name of the base module
the usual way to use pillow is
from PIL import Image
im = Image.open("filename")
See the tutorial, and the documentation
You try to run code with default Python interpreter (/Library/Frameworks/Python.framework/Versions/3.2/bin/python3). You need to configure PyCharm to run Your code with anaconda (~/anaconda/bin/python)
And now (Like #JamesK say) read Pillow tutorial and documentation:
import PIL not import Pillow
For anybody still having trouble with this, I did the following which solved my problem.
Open up your Project Interpreter (⌘ + , on Mac).
At the bottom of this page you'll see the + symbol to the left of the anaconda logo. This will create a pop-up that allows you to search for available packages.
In this new window, search for 'Pillow'.
Click and Install Package.
You should now be able to use "from PIL import Image" or "import Pillow as pil" etc.
After running this command on your terminal
pip install pillow
and you are sure it was installed, but still having same problem of PIL module not found.
Go to your IDE and make sure existing interpreter is set to python interpreter and not anaconda

Error: No module named cv2

I have already found few questions at SO but i am unable to solve this problem using the answers there.
I am new to python. I am having python in Ubuntu 12.04. In my /usr/local/lib, there are two python folders python 2.7 and python 3.2. python 2.7 contains dist-packages and site-packages while python 3.2 contains only dist-packages.
I am trying to run a very simple opencv example with the following code:
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('image.JPG')
kernel = np.ones((5,5),np.float32)/25
dst = cv2.filter2D(img,-1,kernel)
plt.subplot(121),plt.imshow(img),plt.title('Original')
plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(dst),plt.title('Averaging')
plt.xticks([]), plt.yticks([])
plt.show()
Error: No module named cv2
NB : This answer is a short compilation of comments above. For more details, please refer to the comments below question.
Background : OP is using SPE Stani's python editor. OP has installed OpenCV /opt/ros/hydro/lib/python2.7/dist-packages which is not detected by the above mentioned editor. Adding this path to PYTHONPATH doesn't solve the issue.
Solution (any one of the below):
Add this path to sys.path and put it in every file.
import sys
sys.path.append('/opt/ros/hydro/lib/python2.7/dist-packages')
Copy cv2.so file to any directory in the sys.path.
I am able to resolve this problem of not loading cv2 dll by following below steps on my Win 64 machine.
Download the Unofficial Windows Binaries for Python Extension Packages from gohlke site.
In my case it is opencv_python-3.2.0-cp35-cp35m-win_amd64.whl downloaded it to some folder e.g. c:\py\lib
Install this .whl using below command
pip install c:\py\lib\opencv_python-3.2.0-cp35-cp35m-win_amd64.whl
Restart the kernel and error gone.
I had this issue and I fixed it by:
Finding where the openCV library was stored (did this through my IDE).
Deleting it.
Using "pip install opencv-python" again on the terminal in my IDE
Imported as normal
Hopefully this fixes other peoples issues too!

Image Module Python

I'm getting an error about a module and have searched for a solution for some time now and have come up empty handed. I'm coding in python and working in eclipse pydev. At the top of my code I typed.
import Image
I get a error that states ImportError: No module named Image
Here is just some screenshots of the Python Interpreter System Pythonpath
http://imageshack.us/a/img5/614/92989360.png
http://imageshack.us/f/545/79985417.png/
You need to install the Python Image Libray:
PIL
You can install it using pip via:
pip install PIL

Categories