HSOCRResult
TypeThe 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:
hs.ocr.recognizeText('/tmp/image.png').then(result => {
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
text
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
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}
text and observationshs.ocr.recognizeText('/tmp/image.png')
.then(result => console.log(JSON.stringify(result, null, 2)))