生成3D CAPTCHA [图片] [英] Generating a 3D CAPTCHA [pic]
问题描述
我想编写一个Python脚本来生成这样的3D
有很多方法。我将亲自在Python Imaging Library中使用 ImageDraw 创建图像draw.text,转换为 NumPy 数组(usint NumPy's asarray ),然后使用 Matplotlib 。 (需要Matplotlib 维护包)。
完整代码(2.5):
import numpy,pylab
从PIL导入Image,ImageDraw,ImageFont
导入matplotlib.axes3d作为axes3d
sz =(50,30)
img = Image.new 'L',sz,255)
drw = ImageDraw.Draw(img)
font = ImageFont.truetype(arial.ttf,20)
drw.text (5,3),'text',font = font)
img.save('c:/test.png')
X,Y = numpy.meshgrid(range(sz (b
$ = axes3d.Axes3D(fig)
ax.plot_wireframe(X,-Y,Z,rstride = 1,cstride = 1)
ax.set_zlim((0,50))
fig.savefig ('c:/test2.png')
显然有一些工作要做,消除坐标轴,改变视角等等。
I would like to write a Python script that would generate a 3D CAPTCHA like this one:
Which graphics libraries can I use?
Source: ocr-research.org.ua
There are many approaches. I would personally create the image in Python Imaging Library using ImageDraw's draw.text, convert to a NumPy array (usint NumPy's asarray) then render with Matplotlib. (Requires Matplotlib maintenance package).
Full code (in 2.5):
import numpy, pylab
from PIL import Image, ImageDraw, ImageFont
import matplotlib.axes3d as axes3d
sz = (50,30)
img = Image.new('L', sz, 255)
drw = ImageDraw.Draw(img)
font = ImageFont.truetype("arial.ttf", 20)
drw.text((5,3), 'text', font=font)
img.save('c:/test.png')
X , Y = numpy.meshgrid(range(sz[0]),range(sz[1]))
Z = 1-numpy.asarray(img)/255
fig = pylab.figure()
ax = axes3d.Axes3D(fig)
ax.plot_wireframe(X, -Y, Z, rstride=1, cstride=1)
ax.set_zlim((0,50))
fig.savefig('c:/test2.png')
Obviously there's a little work to be done, eliminating axes, changing view angle, etc..
这篇关于生成3D CAPTCHA [图片]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!