Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/yushulx/flutter_document_scan_sdk

A Flutter Document Detection SDK built with Dynamsoft Document Normalizer
https://github.com/yushulx/flutter_document_scan_sdk

dart document-detection document-rectification flutter

Last synced: 3 months ago
JSON representation

A Flutter Document Detection SDK built with Dynamsoft Document Normalizer

Awesome Lists containing this project

README

        

# Flutter Document Detection 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 detection and rectification applications for **Windows**, **Linux**, **web**, **Android** and **iOS**.

## License Key
To use the SDK, you need a [license key for Dynamsoft Document Normalizer](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.

## Try Document Rectification Example

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

![Flutter web document edge detection and normalization](https://www.dynamsoft.com/codepool/img/2024/10/flutter-document-scanner-detection-rectification.png)

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

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

```yml
dependencies:
...
flutter_document_scan_sdk:
```

### One More Step for Web
Include the JavaScript library of Dynamsoft Document Normalizer in your `index.html` file:

```html

```

## API Compatibility
| Methods | Android | iOS | Windows | Linux | Web|
| ----------- | ----------- | ----------- | ----------- |----------- |----------- |
| `Future init(String key)` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |:heavy_check_mark: |
| `Future?> detectFile(String file)` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |:heavy_check_mark: | :heavy_check_mark: |
| `Future normalizeFile(String file, dynamic points)` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |:heavy_check_mark: | :heavy_check_mark: |
| `Future setParameters(String params)` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |:heavy_check_mark: |
| `Future getParameters()` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |:heavy_check_mark: |
| `Future?> 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 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 document rectification SDK with a valid license key:

```dart
final _flutterDocumentScanSdkPlugin = FlutterDocumentScanSdk();
await _flutterDocumentScanSdkPlugin.init(
"LICENSE-KEY");

await _flutterDocumentScanSdkPlugin.setParameters(Template.grayscale);
```

- Do document edge detection and return quadrilaterals:

```dart
List? detectionResults =
await _flutterDocumentScanSdkPlugin
.detectFile(file);
```
- Detect document edges from a buffer:

```dart
List? detectionResults =
await _flutterDocumentScanSdkPlugin
.detectBuffer(bytes, width, height, stride, format);
```
- Rectify the document based on document corners:

```dart
NormalizedImage? normalizedImage = await _flutterDocumentScanSdkPlugin.normalizeFile(
file, detectionResults[0].points);
```
- Rectify the document based on document corners from a buffer:

```dart
NormalizedImage? normalizedImage = await _flutterDocumentScanSdkPlugin.normalizeBuffer(
bytes, width, height, stride, format, detectionResults[0].points);
```
- Save the rectified document image to a file:

```dart
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);
}
}
```