How to get the co-ordinates of the text recogonized from Image using OCR in python

好久不见. 提交于 2019-12-08 06:17:21

问题


I am trying to get the coordinates or positions of text character from an Image using Tesseract. I want to know the exact pixel position, so that i can click that text using some other tool.

Edit :

import pytesseract
from pytesseract import pytesseract
import PIL
from PIL import Image
import cv2
import csv

img = 'E:\\OCR-DATA\\sample.jpg'
imge = Image.open(img)
    data=pytesseract.image_to_string(imge,lang='eng',boxes=True,config='hocr')

print(data)

data contains recognized text with box boundary value. But i am not sure , how to use that boundary value to get the co-ordinates of the text.

Value of the data variable is as follows:

O 100 356 115 373 0

u 117 356 127 368 0

t 130 356 138 372 0

p 141 351 152 368 0

u 154 356 164 368 0

t 167 356 175 371 0

回答1:


You have the coordinates of the bounding box in every line.

From: Training Tesseract – Make Box Files

character, left, bottom, right, top, page

So for each character you get the character, followed by its bounding box characters, followed by the 0-based page number.



来源:https://stackoverflow.com/questions/48928592/how-to-get-the-co-ordinates-of-the-text-recogonized-from-image-using-ocr-in-pyth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!