Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # for http://www.boomlings.com/database/accounts/accountManagement.php captcha's
- from PIL import Image
- chars = {36 : '0',
- 27 : '1',
- 32 : '2',
- 31 : '3',
- 35 : '4',
- 37 : '5',
- 39 : '6',
- 26 : '7',
- 40 : '8',
- 39 : '9'}
- def unrandomise(cpa):
- img = Image.new('RGB',cpa.size)
- for x in range(cpa.size[0]): # all pixels in the captcha are grey.
- for y in range(cpa.size[1]):
- if (cpa.getpixel((x,y))[0] <= 0x20):
- img.putpixel((x,y),(0,0,0))
- elif (cpa.getpixel((x,y))[0] >= 0xe0):
- img.putpixel((x,y),(0xff,0xff,0xff))
- else:
- img.putpixel((x,y),(0xff,0,0))
- return img
- def split_num(im,index):
- box = (5+(index*9),im.getbbox()[1],4+((index+1)*9),im.getbbox()[3])
- return im.crop(box)
- def read_num(split_im):
- t = 0
- for x in range(split_im.size[0]):
- for y in range(split_im.size[1]):
- if (split_im.getpixel((x,y)) == (255,255,255)):
- t += 1
- if (t == 39):
- if (split_im.getpixel((7,3)) == (255,255,255)):
- return '9'
- return '6'
- else:
- return chars[t]
- def read_captcha(im):
- img = unrandomise(im)
- res = ''
- for i in range(5):
- res += read_num(split_num(img,i))
- return res
- file_path = 'captcha.jpg'
- captcha = Image.open(file_path)
- print(read_captcha(captcha))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement