我偶然发现了在图像中读取电话号码的问题。我试着用tesseract在图像中检测到它们,但有时它给了我一个错误的答案。例如,这个数字是8 995 005-81-86,但tesseract给了我8 995 0005-81-86作为输出。我怎么才能修好它?也许是二值化?
代码是基本的
import pytesseract as pt
from PIL import Image
img = Image.open('1.png')
number = pt.image_to_string(img)
print(number)发布于 2020-06-14 10:47:58
您应该在白色文本上传递一个黑色以获得最佳结果:
import cv2
from PIL import Image
img = cv2.imread('kvhAq.png')
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(img, 100, 255, cv2.THRESH_BINARY)
im = Image.fromarray(thresh.astype("uint8"))
print(pytesseract.image_to_string(im))

https://stackoverflow.com/questions/62365474
复制相似问题