我正在尝试将配置参数传递给 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/