Skip to main content
Version: Next

OCRModule

TypeScript API implementation of the useOCR hook.

API Reference

High Level Overview

import { OCRModule, OCR_ENGLISH } from 'react-native-executorch';
const imageUri = 'path/to/image.png';

// Creating an instance
const ocrModule = new OCRModule();

// Loading the model
await ocrModule.load(OCR_ENGLISH);

// Running the model
const detections = await ocrModule.forward(imageUri);

Methods

All methods of OCRModule are explained in details here: OCRModule API Reference

Loading the model

To load the model, use the load method. It accepts an object:

This method returns a promise, which can resolve to an error or void.

For more information on loading resources, take a look at loading models page.

Running the model

To run the model, you can use the forward method. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image. The method returns a promise, which can resolve either to an error or an array of OCRDetection objects. Each object contains coordinates of the bounding box, the label of the detected object, and the confidence score.