Generating a 3D CAPTCHA [pic]

captcha, graphics, python

Solution

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..

Problem

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

Original source