TL; DR:我需要一种方法来解码使用(最好是纯粹的)Python的图像文件中的QR码.
我有一个带有QR码的jpg文件,我想用Python解码.我找到了几个声称这样做的图书馆:
PyQRCode(这里的网站)据说可以通过简单地提供这样的路径来解码图像中的qr代码:
import sys, qrcode
d = qrcode.Decoder()
if d.decode('out.png'):
print 'result: ' + d.result
else:
print 'error: ' + d.error
Run Code Online (Sandbox Code Playgroud)
所以我只是使用它安装它sudo pip install pyqrcode.然而,我对上面的示例代码感到奇怪的是,它只导入qrcode(而不是导入pyqrcode)因为我认为qrcode引用这个只能生成 qr代码图像的库,这让我很困惑.所以,我想上面两个密码pyqrcode和qrcode,但双方未能在第二条线的说法AttributeError: 'module' object has no attribute 'Decoder'.此外,该网站是指Ubuntu 8.10(超过6年前推出),我找不到它的公共(git或其他)存储库来检查最新的提交.所以我转到了下一个图书馆:
ZBar(这里的网站)声称是,"an open source software suite for reading bar codes from various sources, such as image files." …
当我使用easy_install或buildout安装PIL时,它会以这种方式安装,我必须执行'import Image',而不是'来自PIL import Image'.
但是,如果我做"apt-get install python-imaging"或使用"pip -E test_pil install PIL",一切正常.
以下是我尝试使用virtualenv安装PIL的示例:
# virtualenv --no-site-packages test_pil
# test_pil/bin/easy_install PIL
# test_pil/bin/python
Python 2.5.1 (r251:54863, Feb 6 2009, 19:02:12)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named PIL
Run Code Online (Sandbox Code Playgroud)
我明白了,easy_install将PIL打包到Egg中,而PIP则没有.与buildbot相同,它使用鸡蛋.
如何使用easy_install或buildout正确安装PIL?
我试图从得到样品heatmap.py运行: http://jjguy.com/heatmap/
#image.py
import heatmap
import random
if __name__ == "__main__":
pts = []
for x in range(400):
pts.append((random.random(), random.random() ))
print "Processing %d points..." % len(pts)
hm = heatmap.Heatmap()
img = hm.heatmap(pts)
img.save("classic.png")
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Processing 400 points...
Traceback (most recent call last):
File "/home/ec2usr/workspace/image/image.py", line 14, in <module>
img.save("classic.png")
File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 1437, in save
save_handler(self, fp, filename)
File "/usr/local/lib/python2.7/dist-packages/PIL/PngImagePlugin.py", line 572, in _save
ImageFile._save(im, _idat(fp, chunk), [("zip", (0,0)+im.size, 0, rawmode)])
File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFile.py", line 481, in _save
e = …Run Code Online (Sandbox Code Playgroud) 我在ubuntu上使用PIL通过virtualenv,安装了pip.我已将setup.py文件更改为指向解码器库.我在安装PIL时收到此消息:
PIL 1.1.7 SETUP SUMMARY
version 1.1.7
platform linux2 2.6.7 (r267:88850, Aug 11 2011, 12:16:10)
[GCC 4.6.1]
--- TKINTER support available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support available
--- LITTLECMS support available
Run Code Online (Sandbox Code Playgroud)
PIL 1.1.7 SETUP SUMMARY
version 1.1.7
platform linux2 2.6.7 (r267:88850, Aug 11 2011, 12:16:10)
[GCC 4.6.1]
--- TKINTER support available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support available
--- LITTLECMS support available
Run Code Online (Sandbox Code Playgroud)
但是当我保存文件时,我仍然会收到"IOError:decoder jpeg not available"和"IOError:'decoder zip …
.gif我正在尝试使用 python从一组 PIL 图像创建动画。
这是我到目前为止所拥有的:
from images2gif import writeGif
from PIL import Image, ImageDraw
import os
import sys
import random
import argparse
import webbrowser
filename = ""
def makeimages():
for z in range(1, 31):
dims = (400, 400) # size of image
img = Image.new('RGB', dims) # crete new image
draw = ImageDraw.Draw(img)
r = int(min(*dims)/100)
print "Image img%d.png has been created" % z
n = 1000
for i in range(n):
x, y = random.randint(0, dims[0]-r), random.randint(0, dims[1]-r)
fill …Run Code Online (Sandbox Code Playgroud) 我安装了django-photologue.但是当我尝试在django admin中保存照片时,它会抛出此错误:
'解码器拉链不可用'
我已经卸载并重新安装了PIL.我希望有人可以帮助我完成如何克服这个错误的完整步骤.