OcrResult


public 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 methods

abstract @NonNull OcrText

Returns all recognized text and its corresponding bounding boxes.

abstract @NonNull List<@NonNull List<@NonNull Rect>>
@WorkerThread
getSearchBounds(@NonNull String searchTerm, boolean ignoreCase)

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

abstract @NonNull OcrText
getText(int startX, int startY, int endX, int endY)

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

abstract OcrText
getWordAt(int x, int y)

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

Public methods

getAllText

Added in 1.0.0-alpha19
abstract @NonNull OcrText getAllText()

Returns all recognized text and its corresponding bounding boxes.

Returns
@NonNull OcrText

An OcrText object containing all recognized text in the image.

getSearchBounds

Added in 1.0.0-alpha19
@WorkerThread
abstract @NonNull List<@NonNull List<@NonNull Rect>> getSearchBounds(@NonNull String searchTerm, boolean ignoreCase)

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

Parameters
@NonNull String searchTerm

The string to search for.

boolean ignoreCase

true to ignore case when searching, false otherwise.

Returns
@NonNull List<@NonNull List<@NonNull 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
abstract @NonNull OcrText getText(int startX, int startY, int endX, int endY)

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
int startX

The starting X coordinate, relative to image dimensions.

int startY

The starting Y coordinate, relative to image dimensions.

int endX

The ending X coordinate, relative to image dimensions.

int endY

The ending Y coordinate, relative to image dimensions.

Returns
@NonNull OcrText

An OcrText object containing the selected text and its bounds.

getWordAt

Added in 1.0.0-alpha19
abstract OcrText getWordAt(int x, int y)

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
int x

The X coordinate to query, relative to image dimensions.

int y

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.