Tesseract本以为简单的图像结果是错误的数字

2024-09-27 07:31:57 发布

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

请在下面找到一些图片,泰瑟拉克不正确地认识它。在

47

47被认为是“4]”。在

55

55被认为是“S55”。在

90

90被认为是“智商”。在

我觉得这些图像很好,应该很容易被Tesseract识别。但结果却是错误的。我使用的代码如下所示。在

import cv2
import pytesseract
from PIL import Image
import glob

for i in glob.glob('*.png'):
    img = cv2.imread(i, 0)
    tessdata_dir_config = '--tessdata-dir "C:\Program Files (x86)\Tesseract-OCR\" --psm 10'
    result = pytesseract.image_to_string(Image.fromarray(img), config=tessdata_dir_config)
    print result

有人知道发生了什么事以及如何提高绩效吗?在


Tags: 图像imageimportconfigimgdir图片result
2条回答

我读android设备屏幕上的文本时遇到了问题。 在一些设备上,其他设备却没有。 我在tesseractdocumentation中发现它与图像dpi有关。在

Tesseract works best on images which have a DPI of at least 300 dpi, so it may be beneficial to resize images. For more information see the FAQ.

所以我使用了cv2的resize函数来重新缩放图像。在

    path = "/home/share/workspace/NNW4JJ4T4LR4G66H_ZTE_Blade_L5/clock_present_cropped.png"
    path2 = "/home/share/workspace/NNW4JJ4T4LR4G66H_ZTE_Blade_L5/clock_present_cropped_2.png"
    crop_img2 = cv2.imread(str(path))
    img_scaled = cv2.resize(crop_img2, None, fx=0.5, fy=0.5, interpolation=cv2.INTER_LINEAR)
    cv2.imwrite(str(path2), img_scaled)
    crop_img2 = Image.open(path2)
    result = pytesseract.image_to_string(crop_img2)

现在它可以很好地与所有设备配合使用。在

好吧,我为我的问题找到了答案。看来泰瑟拉克不喜欢粗体字,所以你得稍微腐蚀一下黑体字。但是要注意cv2.erode会腐蚀字符的白色部分,所以我们必须使用cv2.dilate来达到这个目的。在

for i in ['47-4].png', '55-S55.png', '90-IQ.png']:
    img = cv2.imread(i, 0)

    ### After apply dilation using 3X3 kernal. The recognition results are improved.##
    kernel = np.ones((3, 3), np.uint8)
    img = cv2.dilate(img, kernel, iterations=2)

    cv2.imwrite("./output/" + i[:-4]+'_dilate.png', img)
    tessdata_dir_config = ' tessdata-dir "D:\Program Files\Tesseract-ocr\"  psm 10'
    result = pytesseract.image_to_string(Image.fromarray(img), config=tessdata_dir_config)
    print result

我想看看对这个问题有没有更好的分析。所以我会让它打开一段时间,然后选择最好的答案。在

相关问题 更多 >

    热门问题