Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Latest commit

 

History

History
109 lines (85 loc) · 4.51 KB

README.md

File metadata and controls

109 lines (85 loc) · 4.51 KB

Flutter Document Detection SDK

The Flutter plugin is a wrapper for Dynamsoft's Document Normalizer SDK v1.x. 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. Make sure to get your trial or commercial license before using the library.

Try Document Rectification Example

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

Supported Platforms

  • Web
  • Windows
  • Linux
  • Android
  • iOS

Installation

Add flutter_document_scan_sdk as a dependency in your pubspec.yaml file.

dependencies:
    ...
    flutter_document_scan_sdk:

One More Step for Web

Include the JavaScript library of Dynamsoft Document Normalizer in your index.html file:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/ddn.js"></script>

API Compatibility

Methods Android iOS Windows Linux Web
Future<int?> init(String key) ✔️ ✔️ ✔️ ✔️ ✔️
Future<List<DocumentResult>?> detectFile(String file) ✔️ ✔️ ✔️ ✔️ ✔️
Future<NormalizedImage?> normalizeFile(String file, dynamic points) ✔️ ✔️ ✔️ ✔️ ✔️
Future<int?> setParameters(String params) ✔️ ✔️ ✔️ ✔️ ✔️
Future<String?> getParameters() ✔️ ✔️ ✔️ ✔️ ✔️
Future<List<DocumentResult>?> detectBuffer(Uint8List bytes, int width, int height, int stride, int format) ✔️ ✔️ ✔️ ✔️ ✔️
Future<NormalizedImage?> normalizeBuffer(Uint8List bytes, int width, int height, int stride, int format, dynamic points) ✔️ ✔️ ✔️ ✔️ ✔️

Usage

  • Initialize the document rectification SDK with a valid license key:

    final _flutterDocumentScanSdkPlugin = FlutterDocumentScanSdk();
    await _flutterDocumentScanSdkPlugin.init(
       "LICENSE-KEY");
    
    await _flutterDocumentScanSdkPlugin.setParameters(Template.grayscale);
  • Do document edge detection and return quadrilaterals:

    List<DocumentResult>? detectionResults =
            await _flutterDocumentScanSdkPlugin
                .detectFile(file);
  • Detect document edges from a buffer:

    List<DocumentResult>? detectionResults =
            await _flutterDocumentScanSdkPlugin
                .detectBuffer(bytes, width, height, stride, format);
  • Rectify the document based on document corners:

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

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

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