Skip to content

Instantly share code, notes, and snippets.

@linxlunx
Created November 7, 2014 09:24
Show Gist options
  • Save linxlunx/877f9b38f8ece52809c7 to your computer and use it in GitHub Desktop.
Save linxlunx/877f9b38f8ece52809c7 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# Captcha breaker for ziddu
# Need tesseract-ocr installed
# Need PIL and pytesser module installed
# usage:
# $ python ziddu.py ziddu.jpeg
# Tesseract Open Source OCR Engine v3.02.02 with Leptonica
# captcha: pswx5
from PIL import Image
from PIL import ImageEnhance
from pytesser import *
import sys
import re
gambar = sys.argv[1]
image = Image.open(gambar)
image = image.convert('L')
image.save('kapca2.jpg')
test = Image.open('kapca2.jpg')
img = ImageEnhance.Contrast(test)
img.enhance(1.5).save("kapca3.jpg")
img = Image.open("kapca3.jpg")
img = img.convert('RGBA')
pixdata = img.load()
for y in xrange(img.size[1]):
for x in xrange(img.size[0]):
if pixdata[x, y] >= (50, 50, 50, 255):
pixdata[x, y] = (255, 255, 255, 255)
img.save("kapca.gif","GIF")
img = Image.open("kapca.gif")
img.resize((300,120), Image.NEAREST)
img.save("kapca.tif")
image = Image.open('kapca.tif')
hasil = image_to_string(image)
final = re.sub("[^a-zA-Z0-9]+","",hasil)
print "captcha: {0}".format(final)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment