flutter_ocr_sdk 0.1.0 flutter_ocr_sdk: ^0.1.0 copied to clipboard
A wrapper for Dynamsoft OCR SDK, detecting MRZ in passports, travel documents, and ID cards.
flutter_ocr_sdk #
A wrapper for Dynamsoft OCR SDK. It helps developers build Flutter applications to detect machine-readable zones (MRZ) in passports, travel documents, and ID cards.
Try MRZ Detection Example #
cd example
flutter run -d <device>
Usage #
-
Download the model folder to your project, and configure
assets
inpubspec.yaml
:assets: - model/
-
Initialize the MRZ detector with a valid license key:
FlutterOcrSdk _mrzDetector = FlutterOcrSdk(); int? ret = await _mrzDetector.init("", "DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==");
-
Load the MRZ detection model:
await _mrzDetector.loadModel('model/');
-
Recognize and parse MRZ information from an image file:
String? json = await _mrzDetector.recognizeByFile(photo.path); String results = getTextResults(json); String getTextResults(String json) { StringBuffer sb = StringBuffer(); List<dynamic>? obj = jsonDecode(json)['results']; if (obj != null) { for (dynamic tmp in obj) { List<dynamic> area = tmp['area']; if (area.length == 2) { String line1 = area[0]['text']; String line2 = area[1]['text']; return MRZ.parseTwoLines(line1, line2).toString(); } else if (area.length == 3) { String line1 = area[0]['text']; String line2 = area[1]['text']; String line3 = area[2]['text']; return MRZ.parseThreeLines(line1, line2, line3).toString(); } } } return 'No results'; }