example12.py 848 B

1234567891011121314151617181920212223242526272829
  1. import base64
  2. from PIL import Image, ImageFilter
  3. from pytesseract import image_to_string
  4. import requests
  5. from io import BytesIO
  6. def main():
  7. guido_img = Image.open(open('guido.jpg', 'rb'))
  8. guido2_img = guido_img.filter(ImageFilter.GaussianBlur)
  9. guido2_img.save(open('guido2.jpg', 'wb'))
  10. img1 = Image.open(open('tesseract.png', 'rb'))
  11. img2 = img1.point(lambda x: 0 if x < 128 else 255)
  12. img2.save(open('tesseract2.png', 'wb'))
  13. print(image_to_string(img2))
  14. resp = requests.get('https://pin2.aliyun.com/get_img?type=150_40&identity=mailsso.mxhichina.com&sessionid=k0xHyBxU3K3dGXb59mP9cdeTXxL9gLHSTKhRZCryHxpOoyk4lAVuJhgw==')
  15. img3 = Image.open(BytesIO(resp.content))
  16. img3.save('captcha.jpg')
  17. print(image_to_string(img3))
  18. print(base64.b64encode(resp.content))
  19. if __name__ == '__main__':
  20. main()