【发布时间】: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