#๐Ÿ”’ Tesseract Image Pre-Processing Help

10 messages ยท Page 1 of 1 (latest)

sleek pewter
#

Trying to pre-process an image and read it using tesseract and pillow. The image looks good to me, but it still keeps misreading some numbers. It keeps reading the value after Stamina as 7 instead of 17, same with Natural Fitness and Teamwork. The 1 looks very clear to me and I don't understand why it struggles to read the 1 in 17 specifically. What would be some steps in pre-processing i could take to make it more accurate?

image = Image.open(image_path)
    
    grayscale = image.convert('L')
    

    enhancer = ImageEnhance.Contrast(grayscale)
    image_contrasted = enhancer.enhance(1.5) 
    
    enhancer = ImageEnhance.Brightness(image_contrasted)
    image_brightened = enhancer.enhance(1.1) 
    image_sharpened = image_brightened.filter(ImageFilter.SHARPEN)
    
    image_np = np.array(image_sharpened)
    

    _, img_thresholded = cv2.threshold(image_np, 190, 255, cv2.THRESH_BINARY) 
    

    img_inverted = cv2.bitwise_not(img_thresholded)
    
    img_resized = cv2.resize(img_inverted, None, fx=2, fy=2, interpolation=cv2.INTER_CUBIC)
    
    processed_image_path = 'images/processed_for_ocr.png'
    cv2.imwrite(processed_image_path, img_resized)
native emberBOT
#

@sleek pewter

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

zinc plank
#

I'd try changing a few Tesseract options before trying to further improve pre-processing if you haven't yet

sleek pewter
zinc plank
sleek pewter
#

i saw that but not seeing anything i could do that would solve my problem. Honestly I don't really understand why it is struggling with those numbers specifically and not others

zinc plank
#

idk have you tried the Tables recognition suggestions?

sleek pewter
#

yea ive looked into it but am not sure it really works in my case since in my image there arent really any separating lines so im not sure if the problems of reading tables apply to me and the solutions also don't really work

native emberBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.