I am using Tesseract.js using a realtime video stream. I want to draw a box around the words that have been recognised. I found the below code but perhaps it's old so I can't get the bbox nor data.words properties. I only have data.text which then doesn't have bbox.
try {
const { data } = await Tesseract.recognize(dataUrl, "eng");
const found: string[] = [];
const overlayCtx = overlay.getContext("2d");
if (!overlayCtx) return;
overlayCtx.clearRect(0, 0, overlay.width, overlay.height);
data.words.forEach((word) => {
const lowerWord = word.toLowerCase();
overlayCtx.strokeStyle = "red";
overlayCtx.lineWidth = 2;
overlayCtx.strokeRect(
word.bbox.x0,
word.bbox.y0,
word.bbox.x1 - word.bbox.x0,
word.bbox.y1 - word.bbox.y0
);
overlayCtx.font = "16px sans-serif";
overlayCtx.fillStyle = "red";
overlayCtx.fillText(word, word.bbox.x0, word.bbox.y0 - 4);
}
}