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
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:
-
model- Object containing:detectorSource- Location of the used detector.recognizerSource- Location of the used recognizer.language- Language used in OCR.
-
onDownloadProgressCallback- Callback to track download progress.
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.