pytesseract 输出未定义

pytesseract Output is not defined

尝试 运行 在 python 上进行 tesseract,这是我的代码:

import cv2
import os
import numpy as np
import matplotlib.pyplot as plt
import pytesseract
import Image
# def main():
jpgCounter = 0
    for root, dirs, files in os.walk('/home/manel/Desktop/fotografias etiquetas'):
    for file in files:
        if file.endswith('.jpg'):
        jpgCounter += 1

for i in range(1, 2):

    name                = str(i) + ".jpg"
    nameBW              = str(i) + "_bw.jpg"
    img                 = cv2.imread(name,0) #zero -> abre em grayscale
    # img                 = cv2.equalizeHist(img)
    kernel = np.array([[0,-1,0], [-1,5,-1], [0,-1,0]])
    img = cv2.filter2D(img, -1, kernel)
    cv2.normalize(img,img,0,255,cv2.NORM_MINMAX)
    med                 = np.median(img)



    retval, threshold_manual    = cv2.threshold(img, med*0.6, 255, cv2.THRESH_BINARY)
    cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY,11,2)
    print(pytesseract.image_to_string(threshold_manual, lang='eng', config='-psm 11', nice=0, output_type=Output.STRING))

我收到的错误如下:

NameError: name 'Output' is not defined

知道我为什么会收到这个吗? 谢谢!

问题是你安装了original pytesseract package (downloaded using pip) and referring documentation of madmaze GitHub version,其实两者是不一样的

我建议按照以下步骤卸载当前版本并克隆 GitHub 存储库并安装它:

  1. 卸载当前版本:

    pip uninstall pytesseract

  2. 使用 git:

    克隆 madmaze/pytesseract GitHub 仓库

    git clone https://github.com/madmaze/pytesseract.git

    或点击here

  3. 直接下载
  4. 进入克隆仓库的根目录,运行:

    pip install .

添加。

from pytesseract import Output