【问题标题】:pytesseract: unexpected keyword "config"pytesseract:意外关键字“config”
【发布时间】:2018-09-15 17:42:11
【问题描述】:

我正在尝试将配置参数传递给 pytesseract 的 image_to_string 函数。

我运行的代码如下。

filename = 'address1_203.png'
img = Image.open(cam_img+filename)

ocr_out = ocr.image_to_string(img, lang='por', config='-psm 7')

print(ocr_out)

错误信息是

TypeError: image_to_string() got an unexpected keyword argument 'config'

stackoverflow 中还有另一个similar question,但我认为它不能解决我遇到的问题。

我通过 conda 使用conda install -c auto pytesseract 安装了 pytesseract

如果我删除 config 参数,代码就可以工作

P.S.:这是我发布的第一个问题,如果我做得正确,请给我反馈。谢谢=)

【问题讨论】:

  • -psm 7 应该是--psm 7
  • 谢谢。这种方式也不行。
  • this link 告诉 conda 有非常旧的 pytesseract 版本(v0.1),而当前版本是 v0.2.1。尝试按照pytesseract github page 中的说明使用 pip 安装

标签: python image python-imaging-library tesseract conda


【解决方案1】:

这是我第一次使用 tesseract,也许你应该试试这个符号。

image_url = 'test2.png'
custom_config = r'-l por --psm 7'
print(pytesseract.image_to_string(image_url, config=custom_config))

重要的是要知道环境(Windows、linux 等)应该安装 tesseract 在我的情况下我使用 ubuntu 并且我以这些方式安装

sudo apt install tesseract-ocr
sudo apt-get install tesseract-ocr-por -y

然后你可以检查安装的语言

tesseract --list-langs

https://github.com/NanoNets/ocr-with-tesseract/blob/master/tesseract-tutorial.ipynb

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-11
    • 1970-01-01
    • 2011-08-25
    • 1970-01-01
    • 2020-11-06
    • 2013-10-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多