React Native Vision SDK
VisionSDK provides a simple and efficient way to detect barcodes and QR codes in both manual and
automatic capturing modes. It also includes AI capabilities to extract information from logistic
documents.
Some key features of the VisionSDK Integration include:
- Barcode and QR code scanning
- Focus on a specific area of camera preview
- Document detection
- Capturing of image
- Information extraction from logistic documents (via both local ML models (offline) and REST API)
- Shipping Label
- Bill of Lading
- Price Tag (under progress)

Installation
Install the Vision SDK for React Native using either npm or yarn:
npm install --save react-native-vision-sdk
yarn add react-native-vision-sdk
Manual Installation
iOS
iOS Development Requirements:
- iOS: 15.0+
- Swift: 5.7
- Xcode: 13.0 or newer
Android
Edit your android/build.gradle file to set the minSdkVersion to 29 or higher:
buildscript {
ext {
buildToolsVersion = "35.0.0"
minSdkVersion = 29 // Minimum version required by Vision SDK
compileSdkVersion = 35
targetSdkVersion = 35
ndkVersion = "26.1.10909125"
kotlinVersion = "1.9.0"
}
}
Android Setup
In the build.gradle file of your Android project, add the following dependencies for Android integration:
dependencies {
// Existing dependencies
implementation 'com.github.packagexlabs:vision-sdk-android:v2.4.26'
implementation 'com.github.asadullahilyas:HandyUtils:1.1.6'
}
After making these changes, sync the project to download the necessary libraries.
Permissions
To use the camera,
Android
Add the following permission to AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA" />
iOS
Update Info.plist with a usage description for the camera:
<key>NSCameraUsageDescription</key>
<string>Your description of the purpose for camera access</string>
Basic Usage Example
Hereβs an example of setting up the Vision SDK for barcode scanning in React Native.
import React, { useEffect, useRef, useState } from 'react';
import VisionSdkView, { VisionSdkRefProps } from 'react-native-vision-sdk';
const ScannerView = () => {
const visionSdk = useRef<VisionSdkRefProps>(null);
useEffect(() => {
visionSdk?.current?.setFocusSettings({
shouldDisplayFocusImage: true,
shouldScanInFocusImageRect: true,
showCodeBoundariesInMultipleScan: true,
validCodeBoundaryBorderColor: '#2abd51',
validCodeBoundaryBorderWidth: 2,
validCodeBoundaryFillColor: '#2abd51',
inValidCodeBoundaryBorderColor: '#cc0829',
inValidCodeBoundaryBorderWidth: 2,
inValidCodeBoundaryFillColor: '#cc0829',
showDocumentBoundaries: true,
documentBoundaryBorderColor: '#241616',
documentBoundaryFillColor: '#e3000080',
focusImageTintColor: '#ffffff',
focusImageHighlightedColor: '#e30000',
});
visionSdk?.current?.setObjectDetectionSettings({
isTextIndicationOn: true,
isBarCodeOrQRCodeIndicationOn: true,
isDocumentIndicationOn: true,
codeDetectionConfidence: 0.5,
documentDetectionConfidence: 0.5,
secondsToWaitBeforeDocumentCapture: 2.0,
});
visionSdk?.current?.setCameraSettings({
nthFrameToProcess: 10,
});
visionSdk?.current?.startRunningHandler();
}, []);
return (
<VisionSdkView
ref={visionSdk}
mode="barcode"
captureMode="auto"
flash={false}
zoomLevel={1.8}
flash={true}
onDetected={(event) => {
console.log('onDetected', event);
setDetectedData(event);
}}
onBarcodeScan={(event) => {
console.log('onBarcodeScan', event);
visionSdk.current?.restartScanningHandler();
}}
onError={(error) => {
console.log('onError', error);
}}
/>
);
};
Headless OCR Example
Here's a complete example demonstrating how to use the new headless OCR functionality:
import React, { useState } from 'react';
import { View, Button, Text, Alert } from 'react-native';
import { VisionCore } from 'react-native-vision-sdk';
const HeadlessOCRExample = () => {
const [isModelLoaded, setIsModelLoaded] = useState(false);
const [prediction, setPrediction] = useState('');
const loadModel = async () => {
try {
VisionCore.setEnvironment('sandbox');
VisionCore.addListener('onModelDownloadProgress', (progress) => {
console.log('Download progress:', progress);
if (progress.isReady) {
setIsModelLoaded(true);
Alert.alert('Success', 'Model loaded and ready!');
}
});
await VisionCore.loadModel({
token: 'your-auth-token',
apiKey: 'your-api-key',
modelType: 'shipping_label',
modelSize: 'large'
});
} catch (error) {
console.error('Failed to load model:', error);
Alert.alert('Error', 'Failed to load model');
}
};
const runPrediction = async () => {
if (!isModelLoaded) {
Alert.alert('Warning', 'Please load model first');
return;
}
try {
const imagePath = 'path/to/your/image.jpg';
const barcodes = ['1234567890'];
const result = await VisionCore.predict(imagePath, barcodes);
setPrediction(result);
} catch (error) {
console.error('Prediction failed:', error);
Alert.alert('Error', 'Prediction failed');
}
};
const runHybridPrediction = async () => {
try {
const imagePath = 'path/to/your/image.jpg';
const barcodes = ['1234567890'];
const enhancedResult = await VisionCore.predictWithCloudTransformations(
imagePath,
barcodes,
{
token: 'your-token',
apiKey: 'your-api-key',
locationId: 'optional-location-id',
shouldResizeImage: true
}
);
setPrediction(enhancedResult);
} catch (error) {
console.error('Hybrid prediction failed:', error);
}
};
return (
<View style={{ padding: 20 }}>
<Button
title="Load Model"
onPress={loadModel}
disabled={isModelLoaded}
/>
<Button
title="Run On-Device Prediction"
onPress={runPrediction}
disabled={!isModelLoaded}
/>
<Button
title="Run Hybrid Prediction"
onPress={runHybridPrediction}
disabled={!isModelLoaded}
/>
<Text style={{ marginTop: 20 }}>
Model Status: {isModelLoaded ? 'Ready' : 'Not Loaded'}
</Text>
{prediction ? (
<Text style={{ marginTop: 10 }}>
Prediction Result: {prediction}
</Text>
) : null}
</View>
);
};
export default HeadlessOCRExample;
Key Benefits of Headless OCR
- π No Camera Dependency: Process existing images without camera component
- β‘ Fast On-Device Processing: Local ML models for instant predictions
- π Cloud Enhancement: Optional cloud processing for higher accuracy
- π Hybrid Workflows: Combine on-device speed with cloud intelligence
- π± Flexible Integration: Use in any part of your app, not just camera screens
Model Management
NEW: The Vision SDK now supports unloading on-device models to free up memory and disk space when they're no longer needed.
Unloading Models
import { VisionCore } from 'react-native-vision-sdk';
const unloadSpecificModel = async () => {
try {
const result = await VisionCore.unLoadModel(
'shipping_label',
true
);
console.log(result);
} catch (error) {
console.error('Failed to unload model:', error);
}
};
const unloadAllModels = async () => {
try {
const result = await VisionCore.unLoadModel(
null,
true
);
console.log(result);
} catch (error) {
console.error('Failed to unload models:', error);
}
};
VisionCore.unLoadModel Parameters
modelType | string | null | Yes | The type of model to unload (e.g., 'shipping_label', 'bill_of_lading'). Pass null to unload all models. |
shouldDeleteFromDisk | boolean | No (default: false) | If true, deletes model files from disk. If false, keeps files for faster reloading. |
Use Cases:
- Free up memory when switching between different model types
- Clean up disk space after processing
- Prepare for app updates or model version changes
- Optimize app performance by removing unused models
VisionCamera - Minimal Camera Component
NEW: VisionCamera is a lightweight, minimal camera component designed for barcode scanning and OCR. Unlike the full VisionSDK component, it provides a streamlined API without requiring API keys or cloud configuration for basic scanning functionality.
Basic VisionCamera Example
import React, { useRef, useState } from 'react';
import { Button } from 'react-native';
import { VisionCamera, VisionCameraRefProps, CameraFacing } from 'react-native-vision-sdk';
const SimpleScannerView = () => {
const cameraRef = useRef<VisionCameraRefProps>(null);
const [cameraFacing, setCameraFacing] = useState<CameraFacing>('back');
return (
<>
<VisionCamera
ref={cameraRef}
scanMode="barcode"
autoCapture={false}
enableFlash={false}
zoomLevel={1.0}
cameraFacing={cameraFacing}
onBarcodeDetected={(event) => {
console.log('Barcodes detected:', event.codes);
// event.codes is an array of detected barcodes with enhanced metadata:
event.codes.forEach(code => {
console.log('Value:', code.scannedCode); // "1234567890"
console.log('Type:', code.symbology); // "CODE_128"
console.log('Position:', code.boundingBox); // { x, y, width, height }
console.log('GS1 Data:', code.gs1ExtractedInfo); // { "01": "12345", ... }
});
}}
onCapture={(event) => {
console.log('Image captured:', event.image);
console.log('Sharpness score:', event.sharpnessScore); // 0.0 - 1.0
console.log('Detected barcodes:', event.barcodes); // Array of barcodes in image
}}
onError={(error) => {
console.error('Error:', error.message);
console.error('Error code:', error.code); // Numeric error code
}}
/>
{/* Camera switch button */}
<Button
title={`Switch to ${cameraFacing === 'back' ? 'Front' : 'Back'} Camera`}
onPress={() => setCameraFacing(prev => prev === 'back' ? 'front' : 'back')}
/>
</>
);
};
VisionCamera Props
scanMode | 'photo' | 'barcode' | 'qrcode' | 'barcodeOrQrCode' | 'ocr' | 'photo' | Detection mode for the camera |
autoCapture | boolean | false | Automatically capture when detection is successful |
enableFlash | boolean | false | Enable/disable camera flash |
zoomLevel | number | 1.0 | Camera zoom level (device dependent, typically 1.0-5.0) |
cameraFacing | 'back' | 'front' | 'back' | Camera facing direction - 'back' for rear camera or 'front' for front-facing camera. iOS: β
Fully supported | Android: π§ Placeholder (not yet functional) |
scanArea | { x: number, y: number, width: number, height: number } | undefined | Restrict scanning to a specific region (coordinates in dp) |
detectionConfig | object | See below | Configure object detection settings |
frameSkip | number | undefined | Process every Nth frame for performance optimization |
Detection Config Object
detectionConfig={{
text: true,
barcode: true,
document: true,
barcodeConfidence: 0.5,
documentConfidence: 0.5,
documentCaptureDelay: 2.0
}}
VisionCamera Events
onBarcodeDetected | Fired when barcode(s) are detected | { codes: Array<BarcodeResult> } - See details below |
onCapture | Fired when image is captured | { image: string, nativeImage: string, sharpnessScore?: number, barcodes?: Array<BarcodeResult> } |
onRecognitionUpdate | Continuous updates of detected objects | { text: boolean, barcode: boolean, qrcode: boolean, document: boolean } |
onSharpnessScoreUpdate | Image sharpness score updates | { sharpnessScore: number } |
onBoundingBoxesUpdate | Bounding boxes for detected objects | { barcodeBoundingBoxes: Array<DetectedCodeBoundingBox>, qrCodeBoundingBoxes: Array<DetectedCodeBoundingBox>, documentBoundingBox: BoundingBox } |
onError | Error events | { message: string, code?: number } |
Enhanced Event Payloads
BarcodeResult Interface
interface BarcodeResult {
scannedCode: string;
symbology: string;
boundingBox: {
x: number;
y: number;
width: number;
height: number;
};
gs1ExtractedInfo?: {
[key: string]: string;
};
}
DetectedCodeBoundingBox Interface (for onBoundingBoxesUpdate)
interface DetectedCodeBoundingBox {
scannedCode: string;
symbology: string;
gs1ExtractedInfo: {
[key: string]: string;
};
boundingBox: {
x: number;
y: number;
width: number;
height: number;
};
}
Platform Note: As of Android VisionSDK v2.4.23, onBoundingBoxesUpdate now provides full barcode metadata including scannedCode, symbology, and gs1ExtractedInfo, achieving full feature parity with iOS!
Capture Event Enhancements
The onCapture event now includes:
sharpnessScore (number, 0-1): Image quality score - higher values indicate sharper images
barcodes (Array): Any barcodes detected in the captured image, available in both OCR and barcode modes
Error Event Enhancements
The onError event now includes:
code (number, optional): Numeric error code for programmatic handling
- iOS Note: Error codes 13, 14, 15, and 16 are automatically filtered and won't trigger the
onError callback
VisionCamera Methods (via ref)
The camera starts automatically when mounted - you don't need to call start() manually in most cases.
const cameraRef = useRef<VisionCameraRefProps>(null);
cameraRef.current?.capture();
cameraRef.current?.start();
cameraRef.current?.stop();
Note: Flash, zoom, and camera facing are controlled via props (enableFlash, zoomLevel, cameraFacing), not ref methods. Update the prop values to change these settings dynamically.
Camera Switching (Front/Back)
Both VisionCamera and VisionSdkView components support switching between front and back cameras.
VisionCamera (Prop-based)
Switch cameras by updating the cameraFacing prop:
import React, { useState, useRef } from 'react';
import { VisionCamera, VisionCameraRefProps, CameraFacing } from 'react-native-vision-sdk';
const CameraSwitchExample = () => {
const cameraRef = useRef<VisionCameraRefProps>(null);
const [cameraFacing, setCameraFacing] = useState<CameraFacing>('back');
const toggleCamera = () => {
setCameraFacing(prev => prev === 'back' ? 'front' : 'back');
};
return (
<>
<VisionCamera
ref={cameraRef}
scanMode="barcode"
cameraFacing={cameraFacing}
onBarcodeDetected={(event) => {
console.log('Barcode detected:', event.codes);
}}
/>
<Button title="Switch Camera" onPress={toggleCamera} />
</>
);
};
VisionSdkView (Ref-based)
Use the setCameraSettings method to switch cameras:
import React, { useRef } from 'react';
import VisionSdkView, { VisionSdkRefProps } from 'react-native-vision-sdk';
const LegacyCameraSwitchExample = () => {
const visionSdkRef = useRef<VisionSdkRefProps>(null);
const switchToFrontCamera = () => {
visionSdkRef.current?.setCameraSettings({
cameraPosition: 2
});
};
const switchToBackCamera = () => {
visionSdkRef.current?.setCameraSettings({
cameraPosition: 1
});
};
return (
<>
<VisionSdkView
ref={visionSdkRef}
mode="barcode"
onBarcodeScan={(event) => {
console.log('Barcode scanned:', event);
}}
/>
<Button title="Front Camera" onPress={switchToFrontCamera} />
<Button title="Back Camera" onPress={switchToBackCamera} />
</>
);
};
Platform Support:
- iOS: β
Fully functional - Switches between front and back cameras seamlessly
- Android: π§ Placeholder implementation - Prop/method is accepted but camera switching is not yet functional (awaiting VisionSDK Android support)
Type Export:
import { CameraFacing } from 'react-native-vision-sdk';
Advanced VisionCamera Example with Scan Area
import React, { useRef, useState } from 'react';
import { View, StyleSheet } from 'react-native';
import { VisionCamera, VisionCameraRefProps } from 'react-native-vision-sdk';
const AdvancedScannerView = () => {
const cameraRef = useRef<VisionCameraRefProps>(null);
const [flashEnabled, setFlashEnabled] = useState(false);
return (
<View style={styles.container}>
<VisionCamera
ref={cameraRef}
scanMode="barcode"
autoCapture={true}
enableFlash={flashEnabled}
zoomLevel={1.5}
// Restrict scanning to center region (200x100 dp area)
scanArea={{
x: 100,
y: 300,
width: 200,
height: 100
}}
detectionConfig={{
barcode: true,
barcodeConfidence: 0.7
}}
frameSkip={10} // Process every 10th frame for better performance
onBarcodeDetected={(event) => {
console.log(`Detected ${event.codes.length} barcode(s)`);
event.codes.forEach(code => {
console.log(`Type: ${code.symbology}, Value: ${code.scannedCode}`);
console.log(`Position:`, code.boundingBox);
});
}}
onBoundingBoxesUpdate={(event) => {
// Real-time bounding box updates for visual overlays
// Note: On Android, scannedCode/symbology will be empty strings
event.barcodeBoundingBoxes.forEach(box => {
console.log('Barcode position:', box.boundingBox);
// iOS: box.scannedCode and box.symbology available
// Android: Use onBarcodeDetected for metadata
});
}}
onError={(error) => {
console.error('Error:', error.message, 'Code:', error.code);
}}
/>
{/* Overlay UI for scan area visualization */}
<View style={[styles.scanAreaOverlay, {
left: 100,
top: 300,
width: 200,
height: 100
}]} />
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1
},
scanAreaOverlay: {
position: 'absolute',
borderWidth: 2,
borderColor: '#00FF00',
backgroundColor: 'transparent'
}
});
Key Differences: VisionCamera vs VisionSDK
| Setup Complexity | Minimal - no API keys needed | Requires API key/token for cloud features |
| Use Case | Simple barcode/QR scanning | Full OCR + cloud predictions |
| Bundle Size | Lightweight | Full-featured |
| Configuration | Props-based | Imperative methods + props |
| Cloud Integration | No | Yes (shipping labels, BOL, etc.) |
| Offline Capability | Full (barcode/QR only) | Partial (requires model download for OCR) |
When to Use VisionCamera
- β
Simple barcode or QR code scanning
- β
On-device OCR (when coupled with
VisionCore for predictions)
- β
No cloud OCR needed
- β
Want minimal setup
- β
Building a lightweight scanner
- β
Custom UI overlays for scanning region
When to Use VisionSDK (Full Component)
- β
Need OCR for shipping labels, bills of lading
- β
Cloud prediction API integration
- β
On-device ML model inference
- β
Complex document processing workflows
- β
Template management
Platform-Specific Limitations & Differences
While we strive to maintain feature parity across iOS and Android, certain limitations exist due to differences in the underlying native VisionSDK implementations.
Android Improvements
1. β
Bounding Box Metadata - FULL PARITY ACHIEVED (Android VisionSDK v2.4.23+)
Affected Events: onBoundingBoxesUpdate, onIndicationsBoundingBoxes
As of Android VisionSDK v2.4.23, the Android platform now provides full barcode metadata in bounding box events, achieving complete feature parity with iOS!
{
barcodeBoundingBoxes: [
{
scannedCode: "1234567890",
symbology: "CODE_128",
gs1ExtractedInfo: { },
boundingBox: { x: 10, y: 20, width: 100, height: 50 }
}
]
}
What Changed:
- Previous versions (v2.4.22 and earlier) only provided
List<Rect> coordinates
- Version v2.4.23+ now uses
List<ScannedCodeResult> with full metadata
- No workarounds needed - both
onBarcodeDetected and onBoundingBoxesUpdate provide complete data
2. Detection Configuration
Some detection config options are iOS-only:
detectionConfig.text - iOS only
detectionConfig.document - iOS only
detectionConfig.barcodeConfidence - iOS only
detectionConfig.documentConfidence - iOS only
detectionConfig.documentCaptureDelay - iOS only
These options are accepted on Android but have no effect.
iOS Limitations
1. Error Code Filtering
Affected Events: onError
iOS automatically filters error codes 13, 14, 15, and 16 to prevent excessive error callbacks during normal operation. These errors will not trigger the onError callback.
onError={(error) => {
console.log('Error code:', error.code);
console.log('Error message:', error.message);
}}
Model Management Differences
| Implementation | OnDeviceOCRManager | OnDeviceOCRManagerSingleton |
| Unload specific model | β
Supported | β οΈ Destroys all models |
| Unload all models | β
Supported | β
Supported |
| Delete from disk | β
Supported | β οΈ Limited |
Android Note: Due to the singleton pattern, calling VisionCore.unLoadModel() with a specific model type will still destroy the entire singleton instance, effectively unloading all models.
Feature Parity Table
| Barcode Detection | β
Full support | β
Full support |
| Bounding Boxes (coordinates) | β
Full support | β
Full support |
| Bounding Boxes (metadata) | β
Full metadata | β
Full metadata |
| Camera Switching (Front/Back) | β
Full support | π§ Placeholder |
| Error codes | β
With filtering | β
Full support |
| Sharpness score | β
Supported | β
Supported |
| GS1 extraction | β
Supported | β
Supported |
| Model management | β
Granular | β οΈ All-or-nothing |
| Detection config | β
Full support | β οΈ Partial support |
Legend:
- β
Fully supported
- β οΈ Limited or different behavior
- β Not available
Major Improvement: As of Android VisionSDK v2.4.23, bounding box metadata is now fully supported on both platforms!
SDK Methods
Camera Controls
- Start Camera: This method start camera session and scanning.
visionSdk.current.startRunningHandler();
- Restart Scanning: This method restart scanning after every scan.
visionSdk.current.restartScanningHandler();
- Stop Camera: This method stops camera session and scanning.
visionSdk.current.stopRunningHandler();
- Capture Image (manual mode only): Capture an image.
visionSdk.current.cameraCaptureHandler();
Headless OCR Workflows
NEW: The Vision SDK now supports headless OCR operations that work independently of the camera component. These methods allow you to perform predictions on existing images without needing the camera view.
import { VisionCore } from 'react-native-vision-sdk';
VisionCore.setEnvironment('sandbox');
await VisionCore.loadModel({
token: 'your-token',
apiKey: 'your-api-key',
modelType: 'shipping_label',
modelSize: 'large'
});
const result = await VisionCore.predict('/path/to/image.jpg', ['barcode1', 'barcode2']);
Available Headless Methods:
VisionCore.predict(imagePath, barcodes) - On-device prediction
VisionCore.predictShippingLabelCloud(imagePath, barcodes, options) - Cloud shipping label prediction
VisionCore.predictItemLabelCloud(imagePath, options) - Cloud item label prediction
VisionCore.predictBillOfLadingCloud(imagePath, barcodes, options) - Cloud bill of lading prediction
VisionCore.predictDocumentClassificationCloud(imagePath, options) - Cloud document classification
VisionCore.predictWithCloudTransformations(imagePath, barcodes, options) - Hybrid on-device + cloud prediction
Configuration Methods
Set Focus Settings (Optional)
You can customize camera focus settings.
visionSdk?.current?.setFocusSettings({
shouldDisplayFocusImage: true,
shouldScanInFocusImageRect: true,
showCodeBoundariesInMultipleScan: true,
validCodeBoundaryBorderColor: '#2abd51',
validCodeBoundaryBorderWidth: 2,
validCodeBoundaryFillColor: '#2abd51',
inValidCodeBoundaryBorderColor: '#cc0829',
inValidCodeBoundaryBorderWidth: 2,
inValidCodeBoundaryFillColor: '#cc0829',
showDocumentBoundaries: true,
documentBoundaryBorderColor: '#241616',
documentBoundaryFillColor: '#e3000080',
focusImageTintColor: '#ffffff',
focusImageHighlightedColor: '#e30000',
});
Set Object Detection Settings (Optional)
You can customize object detection indications to avoid extra processing.
visionSdk?.current?.setObjectDetectionSettings({
isTextIndicationOn: true,
isBarCodeOrQRCodeIndicationOn: true,
isDocumentIndicationOn: true,
codeDetectionConfidence: 0.5,
documentDetectionConfidence: 0.5,
secondsToWaitBeforeDocumentCapture: 2,
});
Set Camera Settings (Optional)
You can customize frames processing and camera position.
visionSdk?.current?.setCameraSettings({
nthFrameToProcess: 10,
cameraPosition: 1,
});
Parameters:
nthFrameToProcess (number): Process every Nth frame for performance optimization (default: 10)
cameraPosition (number): Camera position - 1 for back camera, 2 for front camera. iOS: β
Fully supported | Android: π§ Placeholder (not yet functional)
Configure On-Device Model
Configure on-device model by passing model type and model size in configureOnDeviceModel method, starts model configuration.
visionSdk.current.configureOnDeviceModel({
type: 'shipping_label',
size: 'large',
});
Prediction Methods
The SDK offers several prediction methods categorized based on the type of processing:
on-device
The methods in this category use on-device processing, allowing for fast, offline analysis of images and barcodes, suitable for situations without internet access.
getPrediction
This method uses an on-device model to perform predictions on the provided image and barcode data, ensuring fast, private processing.
visionSdk.current.getPrediction(image, barcode);
on-device-with-translation
Methods in this category use on-device models combined with synchronized cloud transformations, which enhance the prediction accuracy and add more context to the results.
getPredictionWithCloudTransformations
This method uses an on-device model with synchronized cloud transformations for more comprehensive and detailed analysis.
visionSdk.current.getPredictionWithCloudTransformations(image, barcode);
cloud
The methods in this category use cloud processing, which is ideal for complex analyses requiring more computational power or enhanced data resources.
getPredictionShippingLabelCloud
This method uses cloud processing to analyze a shipping label image and any associated barcodes.
visionSdk.current.getPredictionShippingLabelCloud(image, barcode);
bill-of-lading
The methods in this section are optimized specifically for Bill of Lading documents and use cloud processing tailored to the documentβs requirements.
getPredictionBillOfLadingCloud
This method applies cloud processing to analyze Bill of Lading images and associated barcodes, providing data relevant to logistics and shipping.
visionSdk.current.getPredictionBillOfLadingCloud(
image,
barcode,
withImageResizing
);
item_label
The methods in this section are optimized specifically for item label documents and use cloud processing tailored to the documentβs requirements.
getPredictionItemLabelCloud
This method analyzes item labels using cloud processing, focusing on logistics-specific details.
visionSdk.current.getPredictionItemLabelCloud(image, withImageResizing);
document_classification
The methods in this section are optimized specifically for document classification documents and use cloud processing tailored to the documentβs requirements.
getPredictionDocumentClassificationCloud
This method is tailored for analyzing document classification images and their associated barcodes using cloud processing.
visionSdk.current.getPredictionDocumentClassificationCloud(image);
Error Reporting
reportError
handle errors on the device. It supports capturing relevant UI information and logs for debugging.
visionSdk.current.reportError(data);
Template Management
createTemplate
This method is used to create a new template for use in cloud predictions.
visionSdk.current.createTemplate();
getAllTemplates
This method is used to get all saved templates.
visionSdk.current.getAllTemplates();
deleteTemplateWithId
This method is used to delete a specific template by its ID.
visionSdk.current.deleteTemplateWithId(id);
deleteAllTemplates
This method is used to delete all templates from storage.
visionSdk.current.deleteAllTemplates();
Configuration
Use the VisionSdkView component to configure and manage Vision SDKβs features.
Props
ref | Function | Catch the reference of the component to manipulate modes or to access callback functions. |
mode | string: (ocr, barcode, qrcode, barCodeOrQrCode, photo) | Default mode is βbarcodeβ, you can either use other like ocr, qrcode, photo. |
captureMode | string: (manual, auto) | Default captureMode is βmanualβ, you can either use βautoβ. |
apiKey | string | In order to use the OCR API/MODEL, You must set your API key or either an Auth token.. |
token | string | In order to use the OCR API/MODEL, You must set your API key or either an Auth token. |
environment | string: (sandbox, prod) | If you are using OCR mode then you can set your development environment. (Default env is prod) |
ocrMode | string: (cloud, on-device, on-device-with-translation, item_label, document_classification) | ocrMode defines whether you want to scan using cloud API, on-Device Model or on-Device Model with response translation |
isMultipleScanEnabled | boolean: (true, false) | You can enable or disable multiple scan mode by using this prop. (Default value is false) |
isEnableAutoOcrResponseWithImage | boolean: (true, false) | You can enable or disable automatic OCR responses that include the image with the OCR result using the isEnableAutoOcrResponseWithImage property. It accepts a boolean value (true or false), with a default value of true. |
flash | boolean: (true, false) | You can turn ON/OFF camera flash by using this prop. (Default value is false) |
zoomLevel | number: (1 to 5) | You can set the Zoom value. Zoom value is device dependent. It will be vary between 1 to 5. |
locationId | string: (ex# loc_2rpHXFf6ith) | By default your location will get from apiKey or either you can set location id. |
options | Object: {x: number, y: string} | Option contains different other optional parameters you can provide along with the image. |
onDetected | function | Callback for detection events. |
onBarcodeScan | function | Callback when a barcode is scanned. |
onOCRScan | function | Callback for OCR events. |
onImageCaptured | function | Callback for image capture events. |
onModelDownloadProgress | function | Event to monitor model download progress. |
onError | function | Callback for handling errors. |
onCreateTemplate | function | Callback event handler that triggers when a template is successfully created. |
onGetTemplates | function | Callback event handler that triggers when templates are successfully retrieved. |
onDeleteTemplateById | function | Callback event handler that triggers when a template is successfully deleted using its ID. |
onDeleteTemplates | function | Callback event handler that triggers when multiple templates are successfully deleted. |
Event Handlers
The Vision SDK provides several event handlers to handle different types of responses from the SDK. Here is an explanation of each:
1. onDetected
Triggered when any target (barcode, document, QR code, etc.) is detected.
2. onBarcodeScan
Called when a barcode is successfully scanned.
- Response:
{
"code": []
}
code: The scanned barcode data.
3. onOCRScan
Triggered when OCR detects and returns text.
- Response:
{
"data": {}
}
data: Text recognized through OCR.
4. onImageCaptured
Fires when an image is captured.
5. onModelDownloadProgress
Tracks the download progress of the model.
6. onError
Called when an error occurs.
Example Usage
Here's how to set up the Vision SDK in your React Native component:
import React, { useEffect, useRef, useState } from 'react';
import VisionSdkView, { VisionSdkRefProps } from 'react-native-vision-sdk';
const ScannerView = () => {
const visionSdk = useRef<VisionSdkRefProps>(null);
useEffect(() => {
visionSdk?.current?.setFocusSettings({
shouldDisplayFocusImage: true,
shouldScanInFocusImageRect: true,
showCodeBoundariesInMultipleScan: true,
validCodeBoundaryBorderColor: '#2abd51',
validCodeBoundaryBorderWidth: 2,
validCodeBoundaryFillColor: '#2abd51',
inValidCodeBoundaryBorderColor: '#cc0829',
inValidCodeBoundaryBorderWidth: 2,
inValidCodeBoundaryFillColor: '#cc0829',
showDocumentBoundaries: true,
documentBoundaryBorderColor: '#241616',
documentBoundaryFillColor: '#e3000080',
focusImageTintColor: '#ffffff',
focusImageHighlightedColor: '#e30000',
});
visionSdk?.current?.setObjectDetectionSettings({
isTextIndicationOn: true,
isBarCodeOrQRCodeIndicationOn: true,
isDocumentIndicationOn: true,
codeDetectionConfidence: 0.5,
documentDetectionConfidence: 0.5,
secondsToWaitBeforeDocumentCapture: 2.0,
});
visionSdk?.current?.setCameraSettings({
nthFrameToProcess: 10,
});
visionSdk?.current?.startRunningHandler();
}, []);
return (
<VisionSdkView
ref={visionSdk}
mode="ocr"
captureMode="manual"
ocrMode="cloud"
environment="your-environment"
locationId="your-location-id"
apiKey="your-api-key"
flash={false}
zoomLevel={1.8}
onDetected={(event) => {
console.log('onDetected', event);
setDetectedData(event);
}}
onOCRScan={(event) => {
console.log('onOCRScan', event);
visionSdk.current?.restartScanningHandler();
}}
onImageCaptured={(event) => {
console.log('onImageCaptured', event);
visionSdk.current?.restartScanningHandler();
}}
onModelDownloadProgress={(event) => {
console.log('onModelDownloadProgress', event);
if (event.downloadStatus) {
visionSdk.current?.startRunningHandler();
}
}}
onError={(error) => {
console.log('onError', error);
}}
/>
);
};
API Key
In order to use the OCR API, you have to set API key. Also, you also need to specify the API
environment that you have the API key for. Please note that these have to be set before using the API call. You can
generate your own API key at cloud.packagex.io. You can find the instruction
guide here.
Mode Details
barCode - Detects barcode only in this mode.
qrCode - Detects qrcode only in this mode.
barCodeOrQrCode - Detects both qr and bar codes in this mode.
ocr - Use this mode to capture photos for later use in OCR API call.
photo - You can capture simple photos.
Contributing
See the contributing guide to learn how to contribute to the repository and the development workflow.
License
MIT