简体   繁体   中英

Python OCR issues with Pytesseract

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!

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.

脱粒

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM