ImportError: cannot import name 'image_to_data' using pytesseract

ImportError: cannot import name 'image_to_data' using pytesseract

我正在使用 OCR 从 image.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 之外,没有其他函数被导入。

好的,我自己解决了这个问题。我有一个 4.0 的 tesseract 版本。我卸载了它,然后安装了 3.05.02 的旧版 tesseract。在那之后,一切似乎都很好。此外,一旦执行此操作,请同时卸载并安装 pytesseract。