Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image
- import requests
- IMAGE_FILE_NAME = "input_image.png"
- def get_captcha_image():
- response = requests.get("http://www.hhddb.com/default/index/verify-code")
- f = open(IMAGE_FILE_NAME, "wb")
- f.write(response.content)
- f.close()
- def preprocess_image():
- image = Image.open(IMAGE_FILE_NAME)
- width, height = image.size
- ignored_colors = set()
- x = 1
- while len(ignored_colors) != 2 and x <= 5:
- for y in range(height):
- pixel_color = image.getpixel((x, y))
- ignored_colors.add(pixel_color)
- x += 1
- for x in range(width):
- for y in range(height):
- if image.getpixel((x, y)) in ignored_colors:
- image.putpixel((x, y), (255, 255, 255))
- else:
- image.putpixel((x, y), (0, 0, 0))
- image.save("output_image.png")
- get_captcha_image()
- preprocess_image()
RAW Paste Data
Copied