Skip to content

Commit

Permalink
Revise docs
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkRunWu committed Jan 10, 2024
1 parent 2999217 commit 370c83a
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 33 deletions.
15 changes: 3 additions & 12 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ Created `.env` in example project then configure the FormX SDK using the `form i
FORMX_FORM_ID=<FORM ID>
FORMX_ACCESS_TOKEN=<ACCESS TOKEN>
```
## Capture & Extract Documents

## Capture Documents

By default, the camera view detect object using offline ML models. To detect documents using FormX API, pass `DetectMode.online` as detectMode argument and make sure network is up.
With `FormXCameraView`you can detect documents on the fly. By default offline ML models is used to detect documents, pass `DetectMode.online` to detectMode argument to using FormX API and make sure network is up.

```dart
import 'package:formx_sdk_flutter/formx_sdk_flutter.dart';
Expand All @@ -42,10 +41,7 @@ FormXCameraView(
)
```


## Extract Documents

Once the image is ready, we can utilize FormX SDK to further extract document structures.
To extract document, modified `_onCaptured` callback:

```
_onCaptured(Uri imagePath) async {
Expand All @@ -58,8 +54,3 @@ Once the image is ready, we can utilize FormX SDK to further extract document st
}
```






2 changes: 1 addition & 1 deletion lib/src/formx_camera_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:formx_sdk_flutter/src/formx_camera_view_android.dart';
import 'package:formx_sdk_flutter/src/formx_camera_view_ios.dart';
import 'package:formx_sdk_flutter/src/formx_camera_view_platform.dart';

/// A controller used to manipulate native camera view
/// A controller used to manipulate native formx camera view
class FormXCameraController {
final FormXCameraViewPlatform platform;
FormXCameraController()
Expand Down
13 changes: 4 additions & 9 deletions lib/src/formx_sdk.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
import 'package:formx_sdk_flutter/formx_sdk_flutter.dart';
import 'package:formx_sdk_flutter/src/formx_sdk_flutter_platform_interface.dart';

// A SDK wrapper to communicate with the FormX API
class FormXSDK {
/// Initialize FormX SDK with [formId] and [accessToken] retrieved from https://formextractorai.com.
/// By default offical FormX api is used when [endpoint] is null.
/// Setup SDK with [formId] and [accessToken]. if [endpoint] is null, official formx api endpoint is used.
static Future<void> init(
{required String formId, required String accessToken, String? endpoint}) {
return FormxSdkFlutterPlatform.instance.init(formId, accessToken, endpoint);
}

/// Detect documents from given image
/// Detect documents by FormX API
static Future<FormXDetectDocumentsResult?> detect(String imagePath) {
return FormxSdkFlutterPlatform.instance.detect(imagePath);
}

/// Extract document structures from given image
/// Extract form data from documents by FormX API
static Future<FormXExtractionResult?> extract(String imagePath) {
return FormxSdkFlutterPlatform.instance.extract(imagePath);
}

/// Check whether the given image is blurry
static Future<bool?> isBlurry(String imagePath, double threshold) async {
return FormxSdkFlutterPlatform.instance.isBlurry(imagePath, threshold);
}
}
12 changes: 10 additions & 2 deletions lib/src/models/detect_mode.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
/// Document detection mode used in FormX camera view
enum DetectMode { online, offline }
import 'package:formx_sdk_flutter/formx_sdk_flutter.dart';

/// Document detection mode used in [FormXCameraView]
enum DetectMode {
/// using FormX API
online,

/// using offline ML models
offline
}
2 changes: 1 addition & 1 deletion lib/src/models/document.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:formx_sdk_flutter/src/models/bbox.dart';

/// Recognized Document by FormX
/// Recognized Document by FormX API
class Document {
Document(this.type, this.bbox);
final String type;
Expand Down
4 changes: 3 additions & 1 deletion lib/src/models/error.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/// Error returned from FormX camera view
import 'package:formx_sdk_flutter/formx_sdk_flutter.dart';

/// Error threw by [FormXCameraView]
class FormXCameraViewError extends Error {
final String code;
final String message;
Expand Down
7 changes: 3 additions & 4 deletions lib/src/models/formx_auto_extraction_item.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
sealed class FormXAutoExtractionItem {}

/// The value of extraction structure of a single purchase info item
class FormXAutoExtractionPurchaseInfoItemValue {
final String name;
final double amount;
Expand All @@ -17,7 +16,7 @@ class FormXAutoExtractionPurchaseInfoItemValue {
unitPrice = json["unitPrice"] as double;
}

/// Extraction structure of a set of purchase info item
/// The purchase inforamtion of a receipt
class FormXAutoExtractionPurchaseInfoItem extends FormXAutoExtractionItem {
final String name;
final List<FormXAutoExtractionPurchaseInfoItemValue> value;
Expand All @@ -39,7 +38,7 @@ class FormXAutoExtractionIntValue extends FormXAutoExtractionItem {
value = json["value"] as int;
}

/// Extraction structure of a single string value
/// An auto extracted string value
class FormXAutoExtractionStringValue extends FormXAutoExtractionItem {
final String name;
final String value;
Expand All @@ -48,7 +47,7 @@ class FormXAutoExtractionStringValue extends FormXAutoExtractionItem {
value = json["value"] as String;
}

/// Extraction structure of unknown value
/// An unknown extracted value
class FormXAutoExtractionUnsupportedValue extends FormXAutoExtractionItem {
final String name;
final String value;
Expand Down
3 changes: 2 additions & 1 deletion lib/src/models/formx_detect_documents_result.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:formx_sdk_flutter/formx_sdk_flutter.dart';
import 'package:formx_sdk_flutter/src/models/bbox.dart';
import 'package:formx_sdk_flutter/src/models/document.dart';

/// FormX Document Detector Result
/// The response returned by [FormXSDK.detect]
class FormXDetectDocumentsResult {
final String status;
final List<Document> documents;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/models/formx_extraction_result.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:formx_sdk_flutter/src/models/formx_auto_extraction_item.dart';
import 'package:formx_sdk_flutter/formx_sdk_flutter.dart';

/// FormX Extraction Result
/// The response returned by [FormXSDK.extract]
class FormXExtractionResult {
String formId;
String status;
Expand Down

0 comments on commit 370c83a

Please sign in to comment.