OcrResult


interface OcrResult


Represents the complete result of an OCR process, providing methods to query text spatially.

This interface manages the mapping between the raw recognized text and its visual coordinates in the original image.

Summary

Public functions

OcrText

Returns all recognized text and its corresponding bounding boxes.

List<List<Rect>>
@WorkerThread
getSearchBounds(searchTerm: String, ignoreCase: Boolean)

Searches for occurrences of the searchTerm and returns their bounding boxes.

OcrText
getText(startX: Int, startY: Int, endX: Int, endY: Int)

Returns the text and its bounding boxes within the selection range defined by two points.

OcrText?
getWordAt(x: Int, y: Int)

Returns the word and its bounding boxes at the specified coordinate.

Public functions

getAllText

Added in 1.0.0-alpha19
fun getAllText(): OcrText

Returns all recognized text and its corresponding bounding boxes.

Returns
OcrText

An OcrText object containing all recognized text in the image.

getSearchBounds

Added in 1.0.0-alpha19
@WorkerThread
fun getSearchBounds(searchTerm: String, ignoreCase: Boolean = true): List<List<Rect>>

Searches for occurrences of the searchTerm and returns their bounding boxes.

Parameters
searchTerm: String

The string to search for.

ignoreCase: Boolean = true

true to ignore case when searching, false otherwise.

Returns
List<List<Rect>>

A list of lists of Rect objects, where each inner list represents the visual bounding boxes for one occurrence of the search term.

getText

Added in 1.0.0-alpha19
fun getText(startX: Int, startY: Int, endX: Int, endY: Int): OcrText

Returns the text and its bounding boxes within the selection range defined by two points.

The selection range is determined by finding the closest characters to the provided start and end coordinates.

Parameters
startX: Int

The starting X coordinate, relative to image dimensions.

startY: Int

The starting Y coordinate, relative to image dimensions.

endX: Int

The ending X coordinate, relative to image dimensions.

endY: Int

The ending Y coordinate, relative to image dimensions.

Returns
OcrText

An OcrText object containing the selected text and its bounds.

getWordAt

Added in 1.0.0-alpha19
fun getWordAt(x: Int, y: Int): OcrText?

Returns the word and its bounding boxes at the specified coordinate.

If the (x, y) coordinate lies within a word, that entire word is returned. If the point is on whitespace or outside any recognized text, null is returned.

Parameters
x: Int

The X coordinate to query, relative to image dimensions.

y: Int

The Y coordinate to query, relative to image dimensions.

Returns
OcrText?

An OcrText object containing the word at the point, or null if no word is found.