尝试在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'输出'未定义
知道我为什么会这样做? 谢谢!
答案 0 :(得分:4)
问题是您已安装original pytesseract package(使用pip下载)并参考madmaze GitHub version的文档,实际上两者都不同。
我建议通过以下步骤卸载当前版本并克隆GitHub仓库并安装它们:
卸载当前版本:
pip uninstall pytesseract
使用git:
克隆madmaze/pytesseract GitHub repo git clone https://github.com/madmaze/pytesseract.git
或点击here
转到克隆仓库的根目录并运行:
pip install .
答案 1 :(得分:-1)
添加。
from pytesseract import Output