给出一张像这样的图片,你建议如何使用pytess改进字符识别

2024-04-25 13:01:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在测试的图像如下。你知道吗

enter image description here

我对OCR非常陌生,我想知道我可以应用什么样的技术来尝试提高python中方法的准确性,可能是使用PIL,但可以接受建议。使用原始图像时,根本无法识别任何字符。你知道吗

抱歉,如果这个问题有点开放性,但正如我提到的,非常了解OCR的一般。你知道吗

编辑1:根据建议,这里是我迄今为止的代码:

from PIL import Image
import cv2
import pytesseract
image_file=Image.open('rsTest.jpg')
image_file=image_file.convert('1')
image_file.save('PostPro.jpg',dpi=(400,400))
image_file.show

new_image=Image.open('PostPro.jpg')
print pytesseract.image_to_string(new_image)

Tags: 图像imageimportnewpilopen建议技术
1条回答
网友
1楼 · 发布于 2024-04-25 13:01:28

你的图像有多稳定?如果它们看起来都像你发布的,你首先需要做的是裁剪它:

#Since you are importing cv2
image_file=cv.imread('rsTest.jpg')
crop_image = full_image[start_y:end_y,start_x:end_x]

然后你可以只保留白色(也就是字母),把其他的都变成黑色。你知道吗

crop_image[np.where((crop_image != [255,255,255]).all(axis = 2))] = [0,0,0]

然后使用tesseract应用OCR

img = Image.fromarray(crop_image)
captchaText = pytesseract.image_to_string(img)

您需要导入cv2、numpy、pytesseract和PIL。你知道吗

相关问题 更多 >