react-native-smart-ocr
v0.1.0
Published
react-native-smart-ocr is a high-performance React Native OCR library for Android and iOS focused on image enhancement, accurate text recognition, and number plate detection.
Readme
react-native-smart-ocr
react-native-smart-ocr is an on-device OCR library for React Native (Android) with optional OpenCV-based preprocessing (resize, contrast/CLAHE, adaptive threshold, sharpen, deskew).
Note: iOS is currently a stub (returns "iOS OCR not implemented yet"). Android is fully supported.
Installation
npm install react-native-smart-ocrPlatform setup
Android
No extra steps required. This package includes:
- Google ML Kit Text Recognition
- OpenCV (used when
enhance: true)
iOS
The native iOS implementation is not available yet.
If you still install on iOS, make sure Pods are installed:
cd ios && pod installUsage
import { SmartOCR } from 'react-native-smart-ocr';
// Simple (default preprocessing enabled)
const result = await SmartOCR.scanImage('file:///path/to/image.jpg');
// Advanced (tune preprocessing)
const tuned = await SmartOCR.scanImage({
path: 'file:///path/to/image.jpg',
enhance: true,
preprocess: {
contrast: { enabled: true, clipLimit: 2.5, tileGridSize: 8 },
adaptiveThreshold: { enabled: true, method: 'gaussian', blockSize: 31, c: 7 },
sharpen: { enabled: true, amount: 1.0 },
denoise: { enabled: false },
deskew: { enabled: true, maxAngle: 10 },
},
});
console.log(result.text, tuned.confidence);Example output
{
"text": "MH01DX7247",
"confidence": 0.91
}API
SmartOCR.scanImage(pathOrOptions)
Accepts either:
stringimage path/URI (recommended:file://URI from image picker), orSmartOCRScanOptionsobject.
Returns Promise<SmartOCRScanResult>:
text: full recognized textconfidence: heuristic score in[0..1]processingTime: msblocks: text blocks withboundingBox,cornerPoints, nestedlinesandelements
SmartOCR.scanImageWithOptions(options)
Alias for scanImage(options).
Preprocessing options
When enhance: true, preprocessing runs on Android (best-effort; if OpenCV init fails it falls back to the original image).
resize: downscale long side (helps performance / stability on very large images)grayscale: convert to grayscale before OCRdenoise: Gaussian/median blur (can help noisy images, but may hurt plates)contrast: CLAHE (helps low-contrast / night images)adaptiveThreshold: binarization (can help invoices / scanned docs)sharpen: kernel sharpen (can help slight blur)deskew: best-effort rotation correction
Errors
Android rejects promises with standardized error codes:
SMART_OCR_INVALID_PATHSMART_OCR_IMAGE_LOAD_FAILEDSMART_OCR_OCR_FAILED
React Native compatibility
- React Native:
>= 0.74
Screenshots
Add screenshots/GIFs here (recommended):
- Original image + overlayed block bounding boxes
- Example JSON output
Roadmap
- iOS OCR implementation
- Optional number-plate oriented post-processing helpers
- Optional debug overlay helpers (render ML Kit block/line/element boxes)
Contributing
License
MIT
