Merevoli

Untitled

May 25th, 2022 (edited)
147
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from PIL import Image
  2. import requests
  3.  
  4. IMAGE_FILE_NAME = "input_image.png"
  5.  
  6. def get_captcha_image():
  7.     response = requests.get("http://www.hhddb.com/default/index/verify-code")
  8.     f = open(IMAGE_FILE_NAME, "wb")
  9.     f.write(response.content)
  10.     f.close()
  11.  
  12. def preprocess_image():
  13.     image = Image.open(IMAGE_FILE_NAME)
  14.     width, height = image.size
  15.     ignored_colors = set()
  16.    
  17.     x = 1
  18.    
  19.     while len(ignored_colors) != 2 and x <= 5:
  20.         for y in range(height):
  21.             pixel_color = image.getpixel((x, y))
  22.             ignored_colors.add(pixel_color)
  23.         x += 1
  24.        
  25.     for x in range(width):
  26.         for y in range(height):
  27.             if image.getpixel((x, y)) in ignored_colors:
  28.                 image.putpixel((x, y), (255, 255, 255))
  29.             else:
  30.                 image.putpixel((x, y), (0, 0, 0))
  31.                
  32.     image.save("output_image.png")
  33.                
  34. get_captcha_image()
  35. preprocess_image()
RAW Paste Data Copied