1

I am trying to read some characters that come out on the screen, but none of my attempts is successful. Example image here

And here is my code:

import pytesseract as tess
tess.pytesseract.tesseract_cmd = r'C:\Users\myuser\AppData\Local\Tesseract-OCR\tesseract.exe'
from PIL import Image


img = Image.open(r'E:\images\numbers.PNG')
text = tess.image_to_string(img)

print(text)

The "garbage" output that displays is:

C NCES IC DICIIED)
CK STOO TEED
@©O®D@O@O@O@O®

I suppose this is happening because of the color of the numbers, and the different background image they could appear on.

Unfortunately I do not know how to proceed further and how to get it working.

Can you please help? Your assistance is much appreciated!

Thanks!

Alex O
  • 39
  • 2
  • Read [improve-image-quality-to-extract-text-from-image-using-tesseract](https://stackoverflow.com/questions/54497882/how-improve-image-quality-to-extract-text-from-image-using-tesseract), [improving-pytesseract-correct-text-recognition-from-image](https://stackoverflow.com/questions/57210342/improving-pytesseract-correct-text-recognition-from-image) and [numerical-character-recognition-in-pytesser](https://stackoverflow.com/questions/34949453/numerical-character-recognition-in-pytesser) – stovfl Dec 23 '19 at 15:28

1 Answers1

0

I don't have Tesseract installed right now but try with the result of this code:

import cv2

img = cv2.imread('img.png')

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

thresh = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV, 3, 6)
cv2.imshow('threshold', thresh)

cv2.waitKey(0)

You can fine tune it to achieve your result.

thresh

lucians
  • 2,239
  • 5
  • 36
  • 64