A wrapper for Dynamsoft Label Recognizer v2.x with MRZ detection model. It helps developers build Flutter applications to detect machine-readable zones (MRZ) in passports, travel documents, and ID cards.
To use the SDK, you need a license key for Dynamsoft Label Recognizer. Make sure to get your trial or commercial license before using the library.
cd example
flutter run # for Android
flutter run -d chrome # for Web
flutter run -d windows # for Windows
Add flutter_ocr_sdk
as a dependency in your pubspec.yaml
file.
dependencies:
...
flutter_ocr_sdk:
To support web functionality, include the JavaScript library of Dynamsoft Label Recognizer in your index.html
file:
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-label-recognizer@2.2.31/dist/dlr.js"></script>
Methods | Android | iOS | Windows | Linux | macOS | Web |
---|---|---|---|---|---|---|
Future<int?> init(String key) |
:heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
Future<int?> loadModel() |
:heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
Future<List<List<MrzLine>>?> recognizeByFile(String filename) |
:heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
Future<List<List<MrzLine>>?> recognizeByBuffer(Uint8List bytes, int width, int height, int stride, int format) |
:heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
Initialize the MRZ detector with a valid license key:
FlutterOcrSdk _mrzDetector = FlutterOcrSdk();
int? ret = await _mrzDetector.init( "DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==");
await _mrzDetector.loadModel();
Recognize MRZ from an image file:
List<List<MrzLine>>? results = await _mrzDetector.recognizeByFile(photo.path);
Recognize MRZ from an image buffer:
ui.Image image = await decodeImageFromList(fileBytes);
ByteData? byteData =
await image.toByteData(format: ui.ImageByteFormat.rawRgba);
List<List<MrzLine>>? results = await _mrzDetector.recognizeByBuffer(
byteData.buffer.asUint8List(),
image.width,
image.height,
byteData.lengthInBytes ~/ image.height,
ImagePixelFormat.IPF_ARGB_8888.index);
Parse MRZ information:
String information = '';
if (results != null && results.isNotEmpty) {
for (List<MrzLine> area in results) {
if (area.length == 2) {
information =
MRZ.parseTwoLines(area[0].text, area[1].text).toString();
} else if (area.length == 3) {
information = MRZ
.parseThreeLines(area[0].text, area[1].text, area[2].text)
.toString();
}
}
}