Neural Network Model for solving captchas in Python
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

24 lines
901B

  1. import cv2
  2. import os
  3. import glob
  4. import numpy as np
  5. def tratar_imagens(pasta_origem, pasta_destino='captcha_tratado'):
  6. arquivos = glob.glob(f'{pasta_origem}/*')
  7. for arquivo in arquivos:
  8. imagem = cv2.imread(arquivo)
  9. imagem_cinza = cv2.cvtColor(imagem, cv2.COLOR_RGB2GRAY)
  10. _, imagem_tratada = cv2.threshold(imagem_cinza, 127, 255, cv2.THRESH_BINARY or cv2.THRESH_OTSU)
  11. image = imagem_tratada
  12. _, binary_image = cv2.threshold(image, 128, 255, cv2.THRESH_BINARY_INV)
  13. kernel = np.ones((2, 2), np.uint8)
  14. opened_image = cv2.morphologyEx(binary_image, cv2.MORPH_OPEN, kernel)
  15. result_image = cv2.bitwise_not(opened_image)
  16. nome_arquivo = os.path.basename(arquivo)
  17. cv2.imwrite(f'{pasta_destino}/{nome_arquivo}', result_image)
  18. if __name__ == "__main__":
  19. tratar_imagens('captcha_images')