【问题标题】:pytesseract can't recognice number 1pytesseract 无法识别数字 1
【发布时间】:2020-11-30 03:05:10
【问题描述】:

我正在运行一个脚本,该脚本会返回数字键盘中数字的数量和位置,但它是杂乱无章的。但在识别 1 时,它给了我 71 或 7。

这是我正在运行的脚本

numero.save(r'C:\imagenes\numeros\numero.png')
image = Image.open(r'C:\imagenes\numeros\numero.png')
inverted_image = PIL.ImageOps.invert(image)
inverted_image.save(r'C:\imagenes\numeros\numero.png')

image = cv2.imread(r'C:\imagenes\numeros\numero.png')

numero = int(pytesseract.image_to_string(image, lang='spa', config='--psm 6 digits'))
print("numero :", numero)

if numero == 7 or numero not in numeros:
     numero_1_eng = int(pytesseract.image_to_string(image, lang='eng', config='--psm 6 digits'))
if numero_eng != 7:
     numero = 1
else:
     numero = numero_eng
print("numero:", numero)

vector = 930, 425, numero
vector_de_vectores.append(vector)

【问题讨论】:

    标签: python image python-tesseract


    【解决方案1】:

    解决方案


    1- 申请adaptive-thresholding

    2- 将 tesseract 配置设置为 --psm 7(因为您试图识别单个文本行。查看全部 psm modes


    adaptive-thresholding 的结果:

    当你阅读时:

    txt = pytesseract.image_to_string(thr, config="--psm 7")
    print(txt)
    

    结果:

    1
    

    代码:


    import cv2
    import pytesseract
    
    img = cv2.imread("tUh0U.png")
    gry = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    thr = cv2.adaptiveThreshold(gry, 252, cv2.ADAPTIVE_THRESH_MEAN_C,
                                cv2.THRESH_BINARY_INV, 31, 61)
    txt = pytesseract.image_to_string(thr, config="--psm 7")
    print(txt)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多