【问题标题】:ImportError: cannot import name 'image_to_data' using pytesseractImportError:无法使用 pytesseract 导入名称“image_to_data”
【发布时间】:2019-04-01 12:00:17
【问题描述】:

我正在使用 OCR 从图像中提取文本及其坐标(边界框)。image_to_string 工作正常,但 image_to_data 输出错误,它是提取文本边界框所必需的。知道为什么会发生这种情况吗?我正在为此使用 Windows 10。

import pytesseract
import cv2
pytesseract.pytesseract.tesseract_cmd = 'C:/Users/Anwer/AppData/Local/Tesseract-OCR/tesseract.exe'
from PIL import Image
from pytesseract import image_to_data
img = cv2.imread('C:/Users/Anwer/Desktop/Density Plot.png', 1) 
cv2.imwrite("Graph.jpeg",img)
img=Image.open('Graph.jpeg')
d=image_to_data(img,output_type=Output.DICT)
n_boxes = len(d['level'])
for i in range(n_boxes):
    (x, y, w, h) = (d['left'][i], d['top'][i], d['width'][i], d['height'][i])
    cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)
cv2.imshow('img', img)
cv2.waitKey(0)

我希望结果输出边界框坐标,但 image_to_data 函数没有被导入。事实上除了 image_to_string 之外没有任何函数被导入。

【问题讨论】:

    标签: python-3.x ocr python-tesseract


    【解决方案1】:

    好的,我自己解决了这个问题。我有一个 4.0 的 tesseract 版本。我卸载了它,然后安装了 3.05.02 的旧 tesseract 版本。在那之后,一切似乎都运行良好。另外,一旦这样做,请卸载并安装 pytesseract。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-03
      • 2016-03-31
      • 2013-04-24
      • 2014-01-08
      • 2023-04-05
      • 2016-03-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多