在检测电话号码的同时,提高魔方的输出量。

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

我遇到了在图像中读取电话号码的问题。我试着用tesseract来检测图像中的电话号码,但有时它给我一个错误的答案。例如,号码是8 995 005-81-86,但是魔方给我的输出是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)

https:/i.stack.imgur.comkvhAq.png。

ocr tesseract python-tesseract
1个回答
1
投票

你应该通过白底黑字来达到最佳效果。

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.