Pytesseract在Windows和Linux中的表现不同

2024-05-01 21:46:09 发布

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

我正在尝试使用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))))

linux screenshot

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

windows screenshot

代码在python3环境中的两台机器上执行。你知道吗

在我的Windows机器上安装Tesseract时,是否有一个明显的步骤我可能错过了,可以解释这种行为?你知道吗

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

在Linux中,我只是使用: yum install tesseract


Tags: installtopath代码importimglinuxwindows
1条回答
网友
1楼 · 发布于 2024-05-01 21:46:09

我遇到了同样的问题,结果发现如果我将tesseract\u cmd link设置为tesseract ocrv5.0文件夹(我从here安装),效果会非常好。你知道吗

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

相关问题 更多 >