Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
yushulx committed Oct 9, 2024
2 parents 5731341 + 7aa250d commit 8dd6316
Showing 1 changed file with 89 additions and 54 deletions.
143 changes: 89 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,102 +1,137 @@
# Flutter MRZ SDK
# flutter_document_scan_sdk
The Flutter plugin is a wrapper for Dynamsoft's [Document Normalizer SDK v1.x](https://www.dynamsoft.com/document-normalizer/docs/introduction/). It enables you to build document rectification applications for **Windows**, **Linux**, **web**, **Android** and **iOS**.

A wrapper for [Dynamsoft Label Recognizer v2.x](https://www.dynamsoft.com/label-recognition/overview/) with MRZ detection model. It helps developers build Flutter applications to detect machine-readable zones (**MRZ**) in passports, travel documents, and ID cards.
## Try Document Rectification Example

## License Key
To use the SDK, you need a [license key for Dynamsoft Label Recognizer](https://www.dynamsoft.com/customer/license/trialLicense/?product=dcv&package=cross-platform). Make sure to get your trial or commercial license before using the library.
### Desktop: Windows & Linux

## Try Flutter MRZ Detection Example

**Windows**

```bash
cd example
flutter run -d windows
```

![Flutter windows document edge detection and normalization](https://www.dynamsoft.com/codepool/img/2022/12/flutter-windows-desktop-document-scanner.png)


**Linux**

```bash
cd example
flutter run # for Android
flutter run -d chrome # for Web
flutter run -d windows # for Windows
flutter run -d linux
```

![Flutter Passport MRZ recognition](https://www.dynamsoft.com/codepool/img/2024/10/flutter-passport-mrz-reader-scanner.png)
![Flutter Linux document edge detection and normalization](https://www.dynamsoft.com/codepool/img/2022/12/flutter-linux-desktop-document-scanner.png)

### Web
```bash
cd example
flutter run -d chrome
```

![Flutter web document edge detection and normalization](https://www.dynamsoft.com/codepool/img/2023/05/document-edge-edit.png)

### Mobile: Android & iOS

```bash
cd example
flutter run
```

![Flutter document rectification for Android and iOS](https://www.dynamsoft.com/codepool/img/2023/02/flutter-document-rectification-android-ios.jpg)

## Getting a License Key for Dynamsoft Document Normalizer
[![](https://img.shields.io/badge/Get-30--day%20FREE%20Trial-blue)](https://www.dynamsoft.com/customer/license/trialLicense/?product=dcv&package=cross-platform)

## Supported Platforms
- Android
- Web
- Windows
- Linux
- Android
- iOS

## Installation
Add `flutter_ocr_sdk` as a dependency in your `pubspec.yaml` file.
Add `flutter_document_scan_sdk` as a dependency in your `pubspec.yaml` file.

```yml
dependencies:
...
flutter_ocr_sdk:
flutter_document_scan_sdk:
```
### Additional Step for Web
To support web functionality, include the JavaScript library of Dynamsoft Label Recognizer in your `index.html` file:
### One More Step for Web
Include the JavaScript library of Dynamsoft Document Normalizer in your `index.html` file:

```html
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-label-recognizer@2.2.31/dist/dlr.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-document-normalizer@1.0.12/dist/ddn.js"></script>
```


## API Compatibility
| 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: |

| Methods | Android | iOS | Windows | Linux | Web|
| ----------- | ----------- | ----------- | ----------- |----------- |----------- |
| `Future<int?> init(String key)` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |:heavy_check_mark: |
| `Future<List<DocumentResult>?> detectFile(String file)` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |:heavy_check_mark: | :heavy_check_mark: |
| `Future<NormalizedImage?> normalizeFile(String file, dynamic points)` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |:heavy_check_mark: | :heavy_check_mark: |
| `Future<int?> setParameters(String params)` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |:heavy_check_mark: |
| `Future<String?> getParameters()` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |:heavy_check_mark: |
| `Future<List<DocumentResult>?> detectBuffer(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: |
| `Future<NormalizedImage?> normalizeBuffer(Uint8List bytes, int width, int height, int stride, int format, dynamic points)` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |:heavy_check_mark: | :heavy_check_mark: |

## Usage
- Initialize the MRZ detector with a valid license key:
- Initialize the document rectification SDK with a valid license key:

```dart
FlutterOcrSdk _mrzDetector = FlutterOcrSdk();
int? ret = await _mrzDetector.init( "DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==");
```dart
final _flutterDocumentScanSdkPlugin = FlutterDocumentScanSdk();
await _flutterDocumentScanSdkPlugin.init(
"LICENSE-KEY");
await _flutterDocumentScanSdkPlugin.setParameters(Template.grayscale);
```
- Load the MRZ detection model:

- Do document edge detection and return quadrilaterals:

```dart
await _mrzDetector.loadModel();
List<DocumentResult>? detectionResults =
await _flutterDocumentScanSdkPlugin
.detectFile(file);
```
- Recognize MRZ from an image file:
- Detect document edges from a buffer:

```dart
List<List<MrzLine>>? results = await _mrzDetector.recognizeByFile(photo.path);
List<DocumentResult>? detectionResults =
await _flutterDocumentScanSdkPlugin
.detectBuffer(bytes, width, height, stride, format);
```
- Recognize MRZ from an image buffer:
- Rectify the document based on document corners:

```dart
ui.Image image = await decodeImageFromList(fileBytes);
ByteData? byteData =
await image.toByteData(format: ui.ImageByteFormat.rawRgba);
NormalizedImage? normalizedImage = await _flutterDocumentScanSdkPlugin.normalizeFile(
file, detectionResults[0].points);
```
- Rectify the document based on document corners from a buffer:

List<List<MrzLine>>? results = await _mrzDetector.recognizeByBuffer(
byteData.buffer.asUint8List(),
image.width,
image.height,
byteData.lengthInBytes ~/ image.height,
ImagePixelFormat.IPF_ARGB_8888.index);
```dart
NormalizedImage? normalizedImage = await _flutterDocumentScanSdkPlugin.normalizeBuffer(
bytes, width, height, stride, format, detectionResults[0].points);
```
- Parse MRZ information:
- Save the rectified document image to a file:

```dart
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();
}
if (normalizedUiImage != null) {
const String mimeType = 'image/png';
ByteData? data = await normalizedUiImage!
.toByteData(format: ui.ImageByteFormat.png);
if (data != null) {
final XFile imageFile = XFile.fromData(
data.buffer.asUint8List(),
mimeType: mimeType,
);
await imageFile.saveTo(path);
}
}
```



0 comments on commit 8dd6316

Please sign in to comment.