Python 未定义PyteSeract输出

Python 未定义PyteSeract输出,python,ubuntu,tesseract,python-tesseract,pytesser,Python,Ubuntu,Tesseract,Python Tesseract,Pytesser,尝试在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'):

尝试在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:未定义名称“输出”

知道我为什么会得到这个吗?
谢谢大家!

问题在于,您已经安装(使用pip下载)并参考了的文档,实际上两者是不同的

我建议卸载当前版本,克隆GitHub repo,然后按照以下步骤安装:

  • 卸载当前版本:

    pip卸载pytesseract

  • 使用git克隆GitHub repo:

    git克隆https://github.com/madmaze/pytesseract.git

    或直接点击下载

  • 获取克隆的repo的根目录并运行:

    pip安装。

  • 加上


    尝试编写
    pytesseract.Output.STRING
    @VasilisG。更正为:output_type=pytesseract.output.STRING得到了这个(不同的错误!):AttributeError:“module”对象没有属性“output”,根据
    pytesseract
    的定义,
    output_type
    的默认值为
    output.STRING
    ,因此您可以忽略该参数,以及您案例中的
    nice
    参数。@VasilisG。谢谢你的建议。问题是,当我这样做的时候,我得到了一个不同的错误。AttributeError:File“img_proce_clean2.py”,第35行,打印(pytesseract.image_to_字符串(threshold_manual,config='-psm 11'))文件“/home/manel/.local/lib/python2.7/site packages/pytesseract/pytesseract.py”,第104行,在image_to_字符串中,如果len(image.split())==4:AttributeError:'numpy.ndarray'对象没有属性'split'。这是一种比卸载然后从源代码安装更好的方法。
    from pytesseract import Output