在python tesserocr pkg中设置白名单

时间:2018-08-20 11:34:37

标签: python tesseract whitelist

我已经在tessdata中创建了一个配置文件来设置白名单。而且我也知道如何在命令行shell中使用它。但是我不知道如何在带有tesserocr包的python中使用它。函数tesserocr.image_to_text()似乎没有白名单参数。

1 个答案:

答案 0 :(得分:2)

似乎image_to_text不接受白名单参数,请使用SetVariable,请参阅下面的tesseroct基本api上设置白名单的解决方案:

api = tesserocr.PyTessBaseAPI()
api.ReadConfigFile('digits')
# Consider having string with the white list chars in the config_file, for instance: "0123456789"
while_list = open(config_file_path).read()
api.SetVariable("tessedit_char_whitelist", while_list)