Pytesseract not able to recognize characters in captcha

17 Views Asked by At

captcha.pngIn the following captcha, I tried using pytesseract to get characters from captcha but it failed, I am looking for possible solutions using pytesseract or any other libraries.

import cv2
import pytesseract
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
image = cv2.imread('./captcha.png')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (3,3), 0)
thresh = cv2.threshold(blur, 124, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]

kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3,3))
opening = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, kernel, iterations=1)
invert = 255 - opening

data = pytesseract.image_to_string(invert, lang='eng', config='--psm 3')
print(data)

0

There are 0 best solutions below