在安装了Xcode 4的Mac Snow Leopard上安装PIL的最佳方法是什么?我已经看到很多关于在Mac上安装PIL有多困难的信息,但似乎没什么好看的.是否有任何方法可以使用Snow Leopard或Xcode 4附带的Python版本安装它?
我正在运行Debian 6并且最近安装了PIL.
我预先安装了zlib和jpeg库,它们都在/ usr/lib上
安装时,setup.py文件找到库,我得到标准:
--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version 1.1.7
platform linux2 2.7.3 (default, Jun 29 2012, 22:38:23)
[GCC 4.4.5]
--------------------------------------------------------------------
*** TKINTER support not available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support available
--- LITTLECMS support available
Run Code Online (Sandbox Code Playgroud)
zlib和jpeg按预期工作.运行selftest.py也会成功
--------------------------------------------------------------------
PIL 1.1.7 TEST SUMMARY
--------------------------------------------------------------------
Python modules loaded from ./PIL
Binary modules loaded from ./PIL
--------------------------------------------------------------------
--- PIL CORE support ok
*** TKINTER support not installed
--- JPEG support ok
--- ZLIB …Run Code Online (Sandbox Code Playgroud) 我需要一个用于python的Captcha解码器来读取简单的图像验证码,如下图所示:



你知道一个可以帮我读这个验证码的图书馆吗?
如果你不知道用于阅读验证码的图书馆,你能帮我用PIL阅读这个(以及其他类似的东西)吗?
python captcha image image-processing python-imaging-library
我正在尝试使用以下代码导出给定图像的已调整大小的JPEG(省略下载部分,因为它工作正常):
basewidth = 400 # user-defined variable
wpercent = (basewidth/float(img.size[0]))
hsize = int((float(img.size[1])*float(wpercent)))
img = img.resize((basewidth,hsize), Image.ANTIALIAS)
theitemishere = "/home/myusername/public_html/resizer/" + filename
img.save(theitemishere + extension, extension_caps)
Run Code Online (Sandbox Code Playgroud)
但是,当需要保存新图像时,我收到以下错误(这里是回溯):
File "/home/myusername/public_html/cgi-bin/PIL/Image.py", line 1467, in save
save_handler(self, fp, filename)
File "/home/myusername/public_html/cgi-bin/PIL/JpegImagePlugin.py", line 557, in _save
ImageFile._save(im, fp, [("jpeg", (0,0)+im.size, 0, rawmode)])
File "/home/myusername/public_html/cgi-bin/PIL/ImageFile.py", line 466, in _save
e = Image._getencoder(im.mode, e, a, im.encoderconfig)
File "/home/myusername/public_html/cgi-bin/PIL/Image.py", line 395, in _getencoder
return encoder(mode, *args + extra)
TypeError: function takes at most 11 arguments (13 given) …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
im = Image.new("RGBA", (800,600))
draw = ImageDraw.Draw(im,"RGBA")
draw.polygon([(10,10),(200,10),(200,200),(10,200)],(20,30,50,125))
draw.polygon([(60,60),(250,60),(250,250),(60,250)],(255,30,50,0))
del draw
im.show()
Run Code Online (Sandbox Code Playgroud)
但多边形之间的alpha /透明度没有任何差异。是否可以使用这些多边形执行此操作,或者Alpha级别仅适用于合成图像(我知道此解决方案,但仅查看基于PIL的注释,并认为我已经在Pillow中看到了此问题)。
如果没有这样的东西,是否有一种很好,简单,有效的方式将类似这样的东西放入库中?
使用ubuntu 13.10,python 2.7.5:
>>> import _imaging, Image
>>> from PIL import Image, ImageDraw, ImageFilter, ImageFont
>>> im = Image.new('RGB', (300,300), 'white')
>>> draw = ImageDraw.Draw(im)
>>> font = ImageFont.truetype('arial.ttf', 14)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.py", line 218, in truetype
return FreeTypeFont(filename, size, index, encoding)
File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.py", line 134, in __init__
self.font = core.getfont(file, size, index, encoding)
File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.py", line 34, in __getattr__
raise ImportError("The _imagingft C module is not installed")
**ImportError: The …Run Code Online (Sandbox Code Playgroud) 我是Tkinter的新手,我正在尝试将图像添加到Tkinter python 2.7中的文本小部件中.我在互联网上查找了一些资源,据我所知,这是代码,但它给出了错误 - "
File "anim.py", line 11, in <module>
text.image_create(END,image=photoImg)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 2976, in image_create
*self._options(cnf, kw))
TypeError: __str__ returned non-string (type file)
Run Code Online (Sandbox Code Playgroud)
"
请告诉我哪里出错了.提前致谢 :)
from PIL import Image,ImageTk
from Tkinter import *
root = Tk()
root.geometry("900x900+100+100")
image1 = open('IMG_20160123_170503.jpg')
photoImg = PhotoImage(image1)
frame = Frame(root)
frame.pack()
text = Text(frame)
text.pack()
text.image_create(END,image=photoImg)
root.mainloop()
Run Code Online (Sandbox Code Playgroud) 有没有一种快速有效的方法来查找NxM Numpy数组中具有最高值的每一列中的行?
我目前正在通过Python中的嵌套循环执行此操作,这比较慢:
from PIL import Image
import numpy as np
img = Image.open('sample.jpg').convert('L')
width, height = size = img.size
y = np.asarray(img.getdata(), dtype=np.float64).reshape((height, width))
max_rows = [0]*width
for col_i in xrange(y.shape[1]):
max_vaue, max_row = max([(y[row_i][col_i], row_i) for row_i in xrange(y.shape[0])])
max_rows[col_i] = max_row
Run Code Online (Sandbox Code Playgroud)
对于640x480的图像,这大约需要5秒钟。虽然不是很大,但是在Numpy / PIL / C中完全实现的更复杂的图像操作(如模糊)需要0.01秒或更短的时间。我正在尝试对视频流执行此操作,因此这是一个巨大的瓶颈。如果不编写自己的C扩展名,如何加快速度?
我已经写了使用与组合蟒蛇脚本PyPDF2,PIL并pytesseract从中提取的第一页的文字the scanned pages一个的pdf文件.然而,当我尝试下面的脚本来从内容first scanned page指出的pdf文件,当它到达包含该行引发以下错误img = Image.open(pdfReader.getPage(0)).convert('L').
到目前为止我尝试过的脚本:
import PyPDF2
import pytesseract
from PIL import Image
pdfFileObj = open(r'C:\Users\WCS\Desktop\Scan project\Scanned.pdf', 'rb')
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
img = Image.open(pdfReader.getPage(0)).convert('L')
imagetext = pytesseract.image_to_string(img)
print(imagetext)
pdfFileObj.close()
Run Code Online (Sandbox Code Playgroud)
错误我有:
Traceback (most recent call last):
File "C:\Users\WCS\AppData\Local\Programs\Python\Python36-32\SO.py", line 8, in <module>
img = Image.open(pdfReader.getPage(0)).convert('L')
File "C:\Users\WCS\AppData\Local\Programs\Python\Python36-32\lib\site-packages\PIL\Image.py", line 2554, in open
fp = io.BytesIO(fp.read())
AttributeError: 'PageObject' object has no attribute 'read'
Run Code Online (Sandbox Code Playgroud)
我怎样才能成功?
我正在尝试使用quality=90OpenCV 的参数比较压缩前后的一堆图像的大小。但是在压缩之前,我想将它们全部裁剪为固定大小。但是,我不明白,为什么裁剪后的图像平均尺寸小于裁剪+压缩后的图像尺寸?
这是我在做什么:
import cv2
import PIL
from pathlib import Path
image_paths = [...]
cropped_imgs_size = 0
compressed_imgs_size = 0
# crop images
for orig_img_path in image_paths:
cropped_img_path = "cropped_" + orig_img_path
PIL.Image.open(orig_img_path).crop((0,0,256,256)).convert('RGB').save(cropped_img_path)
cropped_imgs_size += Path(cropped_img_path).stat().st_size
# compress cropped image
dest_path = "q90_" + cropped_img_path
cv2.imwrite(dest_path, cv2.imread(cropped_img_path), [int(cv2.IMWRITE_JPEG_QUALITY), 90])
compressed_imgs_size += Path(dest_path).stat().st_size
Run Code Online (Sandbox Code Playgroud)
compressed_imgs_size < copped_imgs_sizecompressed_imgs_size > copped_imgs_size我想念什么?