python - pytesseract : unexpected keyword "config"

标签 python image python-imaging-library tesseract conda

我正在尝试将配置参数传递给 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() 得到了一个意外的关键字参数“config”

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

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

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

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

最佳答案

我是第一次使用 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

关于python - pytesseract : unexpected keyword "config",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49680181/

相关文章:

python - 用 Pillow 像素化图像

python - 使用 pipelinenv 安装 Pillow 时出现问题

python - 如何在 Pillow Image.quantize 中使用 kmeans 参数?

python - 从工具导入任务,ImportError : cannot import name tasks

python - Mongoengine Q类 'OR'

Android Webview - 使用一个 loadUrl 缩放图像以适合屏幕

python - 使用 Pillow 查找 DPI

Python 和 matplotlib 以及 Arduino

python - 如何在 pytest 中使用测试资源(如固定的 yaml 文件)?

python - 除了 python 中的文本,我如何删除图像上的所有内容?