API Docs

The result of a text recognition operation on an image.

An HSOCRResult is returned by hs.ocr.recognizeText() and bundles the full recognized text together with an array of per-region observations, each carrying its own confidence score and bounding box.

  • Example:
const result = await hs.ocr.recognizeText('/tmp/image.png')
console.log('Full text: ' + result.text)
console.log('Regions found: ' + result.observations.length)
result.observations.forEach(obs => {
    console.log(obs.text + ' (' + (obs.confidence * 100).toFixed(0) + '%)')
})

Properties

typeName

string
The Swift type name, for JavaScript introspection.

text

string
The full recognized text from the image, with each observation's text joined by newlines in the order Vision returned them. Use this when you only need the raw text and don't care about bounding boxes or per-region confidence scores.

observations

HSOCRObservation[]
The individual text observations that make up this result. Each entry in the array is an `HSOCRObservation` with its own `text`, `confidence`, and `bounds` properties. Observations are returned in the order Vision produced them (typically top-to-bottom, left-to-right, but this is image-dependent).

Methods

toJSON() -> {[key: string]: any}

Returns a plain object describing this result, for JSON serialisation `JSON.stringify()` calls this automatically, so you rarely need to call it yourself.
toJSON() -> {[key: string]: any}
{[key: string]: any}
An object with the result's `text` and `observations`
const result = await hs.ocr.recognizeText('/tmp/image.png')
console.log(JSON.stringify(result, null, 2))