Add a gradient to FancyCaptcha

This defeats naive thresholding, giving Tesseract break rate of 0 out of
1000, even if a sensible threshold value is hand-chosen. Reduced the
text value and noise to make room for the gradient, but kept an SNR of
1.3, as before, which provides good legibility.

Obviously the gradient can be removed with custom preprocessing -- the
point of these changes is to raise the bar from "unconfigured Tessearct"
to "some small amount of developer effort".

Change-Id: I30ebc904ca59bf29a2aa812f881a077a13493e68
This commit is contained in:
Tim Starling 2014-09-26 10:37:37 +10:00
parent df4806c64c
commit 6f286e52db

View file

@ -111,12 +111,13 @@ def gen_captcha(text, fontname, fontsize, file_name):
data = noise.load()
for x in range(nsize[0]):
for y in range(nsize[1]):
r = random.randint(0, 100)
data[x, y] = r
r = random.randint(0, 65)
gradient = 70 * x / nsize[0]
data[x, y] = r + gradient
# Turn speckles into blobs
noise = noise.resize(im.size, Image.BILINEAR)
# Add to the image
im = ImageMath.eval('convert(convert(a, "L") / 2 + b, "RGB")', a=im, b=noise)
im = ImageMath.eval('convert(convert(a, "L") / 3 + b, "RGB")', a=im, b=noise)
# and turn into black on white
im = ImageOps.invert(im)