Prompt
How do I get OCR text plus coordinates for each word in JSON?
Latest observation
Oct 11, 2026
OpenAI APIWeb search: off
Use an OCR engine that can return word-level bounding boxes and then serialize the results to JSON.
Common options
1) Tesseract
Tesseract can output word coordinates via hOCR, TSV, or BOX.
Best easy option: TSV
- Each word includes:
left,top,width,height,conf,text - You can convert this to JSON
Example with Python:
import pytesseract
from pytesseract import Output
from PIL import Image
import json
img = Image.open("image.png")
data = pytesseract.image_to_data(img, output_type=Output.DICT)
words = []
n = len(data["text"])
for i in range(n):
text = data["text"][i].strip()
if text:
words.append({
"text": text,
"bbox": {
"x": data["left"][i],
"y": data["top"][i],
"w": data["width"][i],
"h": data["height"][i]
},
"conf": float(data["conf"][i])
})
print(json.dumps({"words": words}, indent=2))
2) Google Cloud Vision / Azure OCR / AWS Textract
These cloud OCR APIs typically return:
- detected text
- word/line bounding polygons
- confidence scores
They’re good if you want:
- better OCR quality
- structured JSON directly
- support for rotated text and complex layouts
3) EasyOCR / PaddleOCR
These libraries can also return text plus bounding boxes.
Example with EasyOCR:
import easyocr
import json
reader = easyocr.Reader(['en'])
results = reader.readtext('image.png')
words = []
for bbox, text, conf in results:
words.append({
"text": text,
"bbox": bbox,
"conf": conf
})
print(json.dumps({"words": words}, indent=2))
Recommended JSON format
A simple schema is:
{
"words": [
{
"text": "Hello",
"bbox": { "x": 10, "y": 20, "w": 50, "h": 15 },
"confidence": 96.4
}
]
}
Or if you need polygons:
{
"words": [
{
"text": "Hello",
"points": [[10,20], [60,20], [60,35], [10,35]],
"confidence": 96.4
}
]
}
If you want, I can give you:
- a Python script for Tesseract,
- a Node.js example, or
- a JSON schema for word-level OCR output.