OCRModule
TypeScript API implementation of the useOCR hook.
API Reference
- For detailed API Reference for
OCRModulesee:OCRModuleAPI Reference. - For all alphabets available in ocr out-of-the-box in React Native ExecuTorch see: OCR Supported Alphabets.
High Level Overview
import { OCRModule, OCR_ENGLISH } from 'react-native-executorch';
const imageUri = 'path/to/image.png';
// Creating an instance and loading the model
const ocrModule = await OCRModule.fromModelName(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
Use the static fromModelName factory method. It accepts a namedSources object (e.g. OCR_ENGLISH) containing:
modelName- Model name identifier.detectorSource- Location of the used detector.recognizerSource- Location of the used recognizer.language- Language used in OCR.
And an optional onDownloadProgress callback. It returns a promise resolving to an OCRModule instance.
For more information on loading resources, take a look at loading models page.
Running the model
To run the model, use the forward method. It accepts one argument — the image to recognize. The image can be a remote URL, a local file URI, a base64-encoded image (whole URI or only raw base64), or a PixelData object (raw RGB pixel buffer). The method returns a promise resolving to an array of OCRDetection objects, each containing the bounding box, recognized text, and confidence score.
For real-time frame processing, use runOnFrame instead.