pytesseract无法识别电话号码

问题描述 投票:0回答:1

我遇到一个问题,当我尝试使用pytesseract转换img时,有时会给我一个错误的答案。例如,数字是8 995 005-81-86,但是pytesseract给了我8 995 0005-81-86。我该如何解决?也许二值化?


代码是基本的

将pytesseract导入为pt

从PIL导入图像

img = Image.open('1.png')

数字= pt.image_to_string(img)

打印(编号)

https://i.stack.imgur.com/kvhAq.png

python-tesseract
1个回答
0
投票

为了获得最佳效果,您应该在白底白字之间传递:

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))

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.