Photos and images constitute the largest chunk of the Web, and many include recognisable features, such as human faces, QR codes or text. Detecting these features is computationally expensive, but would lead to interesting use cases e.g. face tagging, or web URL redirection. This document deals with text detection whereas the sister document [SHAPE-DETECTION-API] specifies the Face and Barcode detection cases and APIs.
TextDetector represents an underlying accelerated platform’s component for detection in images of Latin-1 text as defined in [iso8859-1]. It provides a single detect() operation on an ImageBitmapSource of which the result is a Promise. This method must reject this Promise in the cases detailed in § 2.1 Image sources for detection; otherwise it may queue a task using the OS/Platform resources to resolve the Promise with a sequence of DetectedTexts, each one essentially consisting on a rawValue and delimited by a boundingBox and a series of Point2Ds.
A sequence of corner points of the detected feature, in clockwise direction and starting with top-left. This is not necessarily a square due to possible perspective distortions.
3. Examples
This section is non-normative.
Slightly modified/extended versions of these examples (and more) can be found in
e.g. this codepen collection.
3.1. Platform support for a text detector
The following example can also be found in e.g. this codepen with minimal modifications.
if(window.TextDetector ==undefined){
console.error('Text Detection not supported on this platform');}
3.2. Text Detection
The following example can also be found in e.g. this codepen.
let textDetector =new TextDetector();// Assuming |theImage| is e.g. a <img> content, or a Blob.
textDetector.detect(theImage).then(detectedTextBlocks =>{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.");})
Conformance
Document conventions
Conformance requirements are expressed
with a combination of descriptive assertions
and RFC 2119 terminology.
The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL”
in the normative parts of this document
are to be interpreted as described in RFC 2119.
However, for readability,
these words do not appear in all uppercase letters in this specification.
All of the text of this specification is normative
except sections explicitly marked as non-normative, examples, and notes. [RFC2119]
Examples in this specification are introduced with the words “for example”
or are set apart from the normative text
with class="example",
like this:
This is an example of an informative example.
Informative notes begin with the word “Note”
and are set apart from the normative text
with class="note",
like this: