pytesseract tessedit_char_白名单不接受qu

2024-10-01 07:43:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经开始在python中使用pyteserract。当我传递单引号或双引号时

from PIL import Image
import pytesseract
import numpy as np

tesseract_config = r"""-c tessedit_char_whitelist=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ#'<>(){};:"""
tesseract_language = "eng"

text = pytesseract.image_to_string(Image.open('res/outc001.jpg'), lang=tesseract_language, config=tesseract_config)
print text

它回来了

^{pr2}$

我一直在寻找摆脱单引号和双引号的方法,但没有一个有效。在

当我和泰瑟拉克一样

tesseract res/outc001.jpg tesseract_out/out001 -c "tessedit_char_whitelist=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ#\'\"<>(){};:"

它很好用。在


Tags: textimageimportconfigreslanguagejpgwhitelist
1条回答
网友
1楼 · 发布于 2024-10-01 07:43:45

Pytesseract使用shlex分隔配置参数。在

shlex的转义符是\,如果要在shlex.split()函数中插入引号,则必须用\对其进行转义。在

  • 如果您只想'出现在白名单中:

    tesseract_config = "-c tessedit_char_whitelist=blahblah\\'")
    
  • 如果您只想",请:

    tesseract_config = '-c tessedit_char_whitelist=blahblah\\"')
    
  • 如果您同时想要'"

    tesseract_config = '''-c tessedit_char_whitelist=blahblah\\'\\"''')
    

    或者

    tesseract_config = """-c tessedit_char_whitelist=blahblah\\"\\'""")
    

相关问题 更多 >