Skip to content

Instantly share code, notes, and snippets.

@deanhume
Created May 22, 2017 14:16
Show Gist options
  • Save deanhume/f0ac798ccfd6e3b44a6beb04d2b7f422 to your computer and use it in GitHub Desktop.
Save deanhume/f0ac798ccfd6e3b44a6beb04d2b7f422 to your computer and use it in GitHub Desktop.
Text Detection - Shape Detection API
var image = document.getElementById('image');
// Does the current browser support the text detection API?
if (window.TextDetector) {
let textDetector = new TextDetector();
textDetector.detect(theImage)
.then(detectedTextBlocks => {
// Loop through the results
for (const textBlock of detectedTextBlocks) {
console.log(
'text @ (${textBlock.boundingBox.x}, ${textBlock.boundingBox.y}), ' +
'size ${textBlock.boundingBox.width}x${textBlock.boundingBox.height}');
}
}).catch(() => {
console.error("Text Detection failed, boo.");
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment