Search code examples
pythontesseractwhitelist

set white list in python tesserocr pkg


I have create a config file in tessdata to set the white list. And I also know how to use it in command line shell. But I don't know how to use it in python with tesserocr package. The function tesserocr.image_to_text() seems no parameters for white list.


Solution

  • Seems that image_to_text doesn't accept white list parameter, please use SetVariable for that, see the solution of the setting white list over the tesseroct base api below:

    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)