【问题标题】:Pytesseract behaving differently in Windows vs. LinuxPytesseract 在 Windows 和 Linux 中的行为不同
【发布时间】:2019-05-23 05:40:04
【问题描述】:

我正在尝试使用 Pytesseract 进行一些非常基本的字符识别。当我在 Linux 中运行以下代码时,输​​出是有意义的:

import matplotlib.pyplot as plt
import pandas as pd

import sys
import pytesseract
# need to add tesseract install location to path in windows.
if sys.platform == 'win32':
    tesseract_path = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
    pytesseract.pytesseract.tesseract_cmd = tesseract_path

img = pd.read_csv('https://www.dropbox.com/s/fcs5bcmy73j75o0/two.csv?dl=1').values
fig,ax=plt.subplots()
ax.imshow(img.astype(float),cmap='gray')

print('identified as {}'.format(pytesseract.image_to_string(img.astype(float))))

但在 Windows 中对 pytesseract.image_to_string 的相同调用返回一个空字符串:

代码在 Python 3 环境中的两台机器上执行。

在我的 Windows 机器上安装 Tesseract 时,我可能遗漏了一个明显的步骤来解释这种行为吗?

Windows 中的 Tesseract 是使用以下安装程序安装的: https://github.com/UB-Mannheim/tesseract/wiki

在 Linux 中,我简单地使用了: yum install tesseract

【问题讨论】:

  • 我的猜测是文件夹结构存在差异。虽然在这里抓住稻草

标签: python python-3.x ocr tesseract python-tesseract


【解决方案1】:

我遇到了同样的问题,结果证明如果我将 tesseract_cmd 链接设置为 Tesseract-ocr v5.0 文件夹(我从 here 安装),它工作得很好。

pytesseract.pytesseract.tesseract_cmd = 'C:\\Users\\minh.nguyen\\AppData\\Local\\Tesseract-OCR\\tesseract.exe'
  • 请注意,我使用 tesseract v5 而不是 v4.1,因为它的结果更好。

【讨论】:

    猜你喜欢
    • 2016-04-16
    • 1970-01-01
    • 2021-04-26
    • 2019-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多