I have been trying to convert image to text using pytesseract library. I have managed to photocapture the captcha and try to translate it, however. It can't translate the text well and makes the captcha fail, I don't know what I'm doing wrong, I've searched many sites and I can't find something specific :s. I really need help
This is my code on python:
from PIL import Image, ImageFilter
import pytesseract as pt
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
rif = 'J400607396'
browser = webdriver.Chrome('C:\\Users\\USUARIO\\Desktop\\chromedriver.exe') -> driver on chrome
browser.get('http://contribuyente.seniat.gob.ve/BuscaRif/BuscaRif.jsp') -> page
# completar el rif y presionar el siguiente botón
p_rif = browser.find_element_by_id('p_rif') -> input p rif
p_rif.send_keys(rif)
# Imagen captcha
screenshot_name = "captcha.png"
browser.save_screenshot(screenshot_name)
img = Image.open("captcha.png")
area = (143, 205, 263, 235)
cropped_img = img.crop(area)
cropped_img.save('captcha.png')
img = Image.open("captcha.png")
captcha = pt.image_to_string(img,config='--psm 10 -c tessedit_char_whitelist=0123456789abcdefghijklmnopkrstuvwxyz') -> this is the problem
captcha = captcha.replace(" ", "").strip()
print(captcha)
codigo = browser.find_element_by_id('codigo')
codigo.send_keys(captcha)
nextButton = browser.find_element_by_name('busca')
nextButton.click()
browser.close()
I need convert a image in text, is all
I will attach an example captcha, the captcha always changes with each update
--psm 7
(for text in one line). I tested also with resizing 200% (and--psm 7
) but it doesn't give text.