在 python tesserocr pkg 中设置白名单

set white list in python tesserocr pkg

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

似乎image_to_text不接受白名单参数,请使用SetVariable,请参见下面在tesseroct base 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)