from PIL import Image import sys i, o = sys.argv[1:] im = Image.open(i) # In pass.hust.edu.cn verification code, the second frame is COMPLETE! # let's get the second frame. im.seek(im.tell()+1) im.save(o) im = Image.open(o) # To white-black im = im.convert('L') im = im.point(lambda x: 0 if x<254 else 255, '1') # Try to crop w, h = im.size if w == 90 and h == 58: im = im.crop((0, 18, w, 39)) else: print('WARNING: Expected image w=90, h=58, Got image w={}, h={}.'.format(w, h)) # Save for OCR im.save(o)