Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Tesseract-本应容易的图像结果是错误的数字_Python_Tesseract - Fatal编程技术网

Python Tesseract-本应容易的图像结果是错误的数字

Python Tesseract-本应容易的图像结果是错误的数字,python,tesseract,Python,Tesseract,请在下面找到一些tesseract无法正确识别的图像 47被认为是“4]” 55被认为是“S55” 90被认为是“智商” 我认为这些图像非常好,应该很容易被Tesseract识别。但结果证明是错误的。我使用的代码如下所示 import cv2 import pytesseract from PIL import Image import glob for i in glob.glob('*.png'): img = cv2.imread(i, 0) tessdata_di

请在下面找到一些tesseract无法正确识别的图像

47被认为是“4]”

55被认为是“S55”

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

有人知道发生了什么以及如何提高性能吗?

好的,我找到了我问题的答案。看来Tesseract不喜欢粗体的字符,所以你必须稍微腐蚀字符的黑色部分。但是要小心
cv2。腐蚀
会腐蚀字符的白色部分,因此我们必须使用
cv2.deplate
来实现这一目标

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

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

好的,我找到了我问题的答案。看来Tesseract不喜欢粗体的字符,所以你必须稍微腐蚀字符的黑色部分。但是要小心
cv2。腐蚀
会腐蚀字符的白色部分,因此我们必须使用
cv2.deplate
来实现这一目标

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

我想看看对这个问题是否有更好的分析。因此,我会让它打开一段时间,然后选择最佳答案。

我有从android设备屏幕读取文本的问题。 在一些设备上它可以工作,而在其他设备上则不行。 我在tesseract中发现它与图像dpi有关

Tesseract最适用于DPI至少为300 DPI的图像,因此调整图像大小可能是有益的。有关更多信息,请参阅常见问题解答

因此,我使用cv2的调整大小功能来重新缩放图像

    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)

现在,它在所有设备上都能正常工作。

我遇到了从android设备屏幕读取文本的问题。 在一些设备上它可以工作,而在其他设备上则不行。 我在tesseract中发现它与图像dpi有关

Tesseract最适用于DPI至少为300 DPI的图像,因此调整图像大小可能是有益的。有关更多信息,请参阅常见问题解答

因此,我使用cv2的调整大小功能来重新缩放图像

    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)
现在,它可以与所有设备配合使用