vision-camera-dynamsoft-label-recognizer
React Native Vision Camera Frame Processor Plugin of Dynamsoft Label Recognizer
Demo video
Installation
npm install vision-camera-dynamsoft-label-recognizer
make sure you correctly setup react-native-reanimated and add this to your babel.config.js
[
'react-native-reanimated/plugin',
{
globals: ['__recognize'],
},
]
Proguard Rules for Android
-keep class androidx.camera.core.** {*;}
Usage
-
Live scanning using React Native Vision Camera.
import * as React from 'react';
import { StyleSheet } from 'react-native';
import { Camera, useCameraDevices, useFrameProcessor } from 'react-native-vision-camera';
import { recognize, ScanConfig } from 'vision-camera-dynamsoft-label-recognizer';
import * as REA from 'react-native-reanimated';
export default function App() {
const [hasPermission, setHasPermission] = React.useState(false);
const devices = useCameraDevices();
const device = devices.back;
const frameProcessor = useFrameProcessor((frame) => {
'worklet'
const config:ScanConfig = {};
config.license = "<license>"
const result = recognize(frame,config);
}, [])
React.useEffect(() => {
(async () => {
const status = await Camera.requestCameraPermission();
setHasPermission(status === 'authorized');
})();
}, []);
return (
device != null &&
hasPermission && (
<>
<Camera
style={StyleSheet.absoluteFill}
device={device}
isActive={true}
frameProcessor={frameProcessor}
frameProcessorFps={1}
/>
</>
)
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
});
-
Recognizing text from static images.
import type { ScanConfig } from "vision-camera-dynamsoft-label-recognizer";
import * as DLR from "vision-camera-dynamsoft-label-recognizer";
const config:ScanConfig = {};
config.license = "<license>"
const result = await DLR.decodeBase64(base64,config);
Interfaces
Scanning configuration:
export interface ScanRegion{
left: number;
top: number;
width: number;
height: number;
}
export interface ScanConfig{
template?: string;
license?: string;
scanRegion?: ScanRegion;
customModelConfig?: CustomModelConfig;
includeImageBase64?: boolean;
}
export interface CustomModelConfig {
customModelFolder: string;
customModelFileNames: string[];
}
You can use a custom model like a model for MRZ passport reading using the CustomModelConfig
prop. You can find the MRZ model in the example.
You need to put the model folder in the assets
folder for Android or the root for iOS.
About the result:
export interface ScanResult {
results: DLRResult[];
imageBase64?: string;
}
export interface DLRResult {
referenceRegionName: string;
textAreaName: string;
pageNumber: number;
location: Quadrilateral;
lineResults: DLRLineResult[];
}
export interface Quadrilateral{
points:Point[];
}
export interface Point {
x:number;
y:number;
}
export interface DLRLineResult {
text: string;
confidence: number;
characterModelName: string;
characterResults: DLRCharacherResult[];
lineSpecificationName: string;
location: Quadrilateral;
}
export interface DLRCharacherResult {
characterH: string;
characterM: string;
characterL: string;
characterHConfidence: number;
characterMConfidence: number;
characterLConfidence: number;
location: Quadrilateral;
}
Supported Platforms
Detailed Installation Guide
Let's create a new react native project and use the plugin.
- Create a new project:
npx react-native init MyTestApp
- Install required packages:
npm install vision-camera-dynamsoft-label-recognizer react-native-reanimated react-native-vision-camera
. Update relevant files following the react-native-reanimated installation guide. You can use jsc instead of hermes - Update the
babel.config.js
file - Add camera permission for both Android and iOS
- Update
App.tsx
to use the camera and the plugin - For Android, register the plugin in
MainApplication.java
following the guide - Run the project:
npx react-native run-andoid/run-ios
You can check out the example for more details.
Blogs on How the Plugin is Made
Contributing
See the contributing guide to learn how to contribute to the repository and the development workflow.
License
MIT
Made with create-react-native-library