Search code examples
pythonpython-tesseract

Extract text from captcha image with python


Hello i am trying to learn python Currently i want to extract text from images like captcha. But i tried ocr-pytesseract and 1 more which i dont remember name. When i try to extract text from image 1 it works fine but when i want to extract text from image it gives me nothing. Any advice ? Thank you! And here is my code.

from PIL import Image
from pytesseract import pytesseract

path_to_tesseract = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
pytesseract.tesseract_cmd = path_to_tesseract

path_to_image = 'alz.png'
img = Image.open(path_to_image)

#image to text
text = pytesseract.image_to_string(img)
print(text)

image_1image 2


Solution

  • I used yolov5 and with 100 images dataset I have achieved 60% accuracy on test data.

    Example image