From e27890cd35df7e3c12b1a564df09341b0e2698e5 Mon Sep 17 00:00:00 2001 From: DMGithubPublisher Date: Fri, 30 May 2025 17:37:46 +0800 Subject: [PATCH 1/3] update to internal commit 754e0603 --- .../deskewed-image-result-item.md | 72 +++ .../api-reference/detected-quads-result.md | 1 + .../enhanced-image-result-item.md | 54 ++ .../processed-document-result.md | 64 ++ programming/maui/user-guide-v2.6.1001.md | 391 ++++++++++++ programming/maui/user-guide.md | 577 ++++++++++-------- 6 files changed, 921 insertions(+), 238 deletions(-) create mode 100644 programming/maui/api-reference/deskewed-image-result-item.md create mode 100644 programming/maui/api-reference/enhanced-image-result-item.md create mode 100644 programming/maui/api-reference/processed-document-result.md create mode 100644 programming/maui/user-guide-v2.6.1001.md diff --git a/programming/maui/api-reference/deskewed-image-result-item.md b/programming/maui/api-reference/deskewed-image-result-item.md new file mode 100644 index 0000000..7e08360 --- /dev/null +++ b/programming/maui/api-reference/deskewed-image-result-item.md @@ -0,0 +1,72 @@ +--- +layout: default-layout +title: DeskewedImageResultItem - Dynamsoft Document Normalizer Android SDK API Reference +description: The class DeskewedImageResultItem represents a captured result item whose type is a deskewed image. It stores the deskewed image information. +keywords: deskewed image result item, csharp, kotlin +needGenerateH3Content: true +needAutoGenerateSidebar: true +noTitleIndex: true +--- + +# DeskewedImageResultItem + +The `DeskewedImageResultItem` class is an extension of [`CapturedResultItem`]({{ site.dcv_maui_api }}core/basic-structures/captured-result-item.html) that represents a deskewed image. This is the most basic unit of the deskewed image result, one of the captured result types that the Capture Vision Router can output. + +## Definition + +*Namespace:* com.dynamsoft.ddn + +*Assembly:* DynamsoftCaptureVisionBundle.aar + +```csharp +class DeskewedImageResultItem extends CapturedResultItem +``` + +## Properties + +| Property | Type | Description | +| -------- | ---- | ----------- | +| [`ImageData`](#imagedata) | *ImageData* | Represents an `ImageData` object as the deskewed image. | +| [`SourceDeskewQuad`](#location) | *Quadrilateral* | Represents the quadrilateral from which you get the deskewed image result item. | +| [`CrossVerificationStatus`](#crossverificationstatus) | *EnumCrossVerificationStatus* | Represents the cross verification status of the result item. | +| [`OriginalToLocalMatrix`](#originaltolocalmatrix) | *Matrix* | Represents the transformation matrix from the original image coordinate system to the local coordinate system. | + +The following properties are inherited from [`CapturedResultItem`]({{ site.dcv_maui_api }}core/captured-result-item.html). + +| Property | Type | Description | +| -------- | ---- | ----------- | +| [`Type`]({{ site.dcv_maui_api }}core/captured-result-item.html#type) | *[EnumCapturedResultItemType]({{ site.dcv_maui_api }}core/enum/captured-result-item-type.html)* | Get the type of the captured result item, indicating what kind of data it represents. | +| [`TargetROIDefName`]({{ site.dcv_maui_api }}core/captured-result-item.html#targetroidefname) | *string* | Gets the name of the [`TargetROIDef`]({{ site.dcv_parameters_reference }}target-roi-def/) object which includes a task that generated the result. | +| [`TaskName`]({{ site.dcv_maui_api }}core/captured-result-item.html#taskname) | *string* | The name of the task that generated the result. | + +### ImageData + +Represents an [`ImageData`]({{ site.dcv_maui_api }}core/basic-structures/image-data.html) object for the deskewed image. + +```csharp +ImageData ImageData { get; } +``` + +### SourceDeskewQuad + +Represents the soure [Quadrilateral]({{ site.dcv_maui_api }}core/basic-structures/quadrilateral.html) that used to deskew the image. + +```csharp +Quadrilateral Location { get; } +``` + +### CrossVerificationStatus + +Represents the cross verification status of the result item. The cross verification status determines whether the result item is approved by the multi-frame cross verification mechanism. If approved, the cross verification status is `CVS_PASSED`. Otherwise, it is `CVS_FAILED`. + +```csharp +EnumCrossVerificationStatus CrossVerificationStatus { get; } +``` + +### OriginalToLocalMatrix + +Represents the transformation matrix from the original image coordinate system to the local coordinate system. + +```csharp +Matrix OriginalToLocalMatrix { get; } +``` diff --git a/programming/maui/api-reference/detected-quads-result.md b/programming/maui/api-reference/detected-quads-result.md index 5a0a52e..f3c6377 100644 --- a/programming/maui/api-reference/detected-quads-result.md +++ b/programming/maui/api-reference/detected-quads-result.md @@ -6,6 +6,7 @@ keywords: detected quads result, java, kotlin needGenerateH3Content: true needAutoGenerateSidebar: true noTitleIndex: true +ignore: true --- # DetectedQuadsResult diff --git a/programming/maui/api-reference/enhanced-image-result-item.md b/programming/maui/api-reference/enhanced-image-result-item.md new file mode 100644 index 0000000..a2b7222 --- /dev/null +++ b/programming/maui/api-reference/enhanced-image-result-item.md @@ -0,0 +1,54 @@ +--- +layout: default-layout +title: EnhancedImageResultItem - Dynamsoft Document Normalizer MAUI SDK API Reference +description: The class EnhancedImageResultItem of DCV MAUI represents a captured result item whose type is a enhanced image. It stores the enhanced image information. +keywords: enhanced image result item, csharp, kotlin +needGenerateH3Content: true +needAutoGenerateSidebar: true +noTitleIndex: true +--- + +# EnhancedImageResultItem + +The `EnhancedImageResultItem` class is an extension of [`CapturedResultItem`]({{ site.dcv_maui_api }}core/basic-structures/captured-result-item.html) that represents a enhanced image. This is the most basic unit of the enhanced image result, one of the captured result types that the Capture Vision Router can output. + +## Definition + +*Namespace:* com.dynamsoft.ddn + +*Assembly:* DynamsoftCaptureVisionBundle.aar + +```csharp +class EnhancedImageResultItem extends CapturedResultItem +``` + +## Properties + +| Property | Type | Description | +| -------- | ---- | ----------- | +| [`ImageData`](#imagedata) | *ImageData* | Returns an `ImageData` object as the enhanced image. | +| [`OriginalToLocalMatrix`](#originaltolocalmatrix) | *Matrix* | Returns the transformation matrix from the original image coordinate system to the local coordinate system. | + +The following properties are inherited from [`CapturedResultItem`]({{ site.dcv_maui_api }}core/captured-result-item.html). + +| Property | Type | Description | +| -------- | ---- | ----------- | +| [`Type`]({{ site.dcv_maui_api }}core/captured-result-item.html#type) | *[EnumCapturedResultItemType]({{ site.dcv_maui_api }}core/enum/captured-result-item-type.html)* | Get the type of the captured result item, indicating what kind of data it represents. | +| [`TargetROIDefName`]({{ site.dcv_maui_api }}core/captured-result-item.html#targetroidefname) | *string* | Gets the name of the [`TargetROIDef`]({{ site.dcv_parameters_reference }}target-roi-def/) object which includes a task that generated the result. | +| [`TaskName`]({{ site.dcv_maui_api }}core/captured-result-item.html#taskname) | *string* | The name of the task that generated the result. | + +### ImageData + +Returns an [`ImageData`]({{ site.dcv_maui_api }}core/basic-structures/image-data.html) object for the enhanced image. + +```csharp +ImageData ImageData { get; } +``` + +### OriginalToLocalMatrix + +Returns the transformation matrix from the original image coordinate system to the local coordinate system. + +```csharp +Matrix OriginalToLocalMatrix { get; } +``` diff --git a/programming/maui/api-reference/processed-document-result.md b/programming/maui/api-reference/processed-document-result.md new file mode 100644 index 0000000..44b7967 --- /dev/null +++ b/programming/maui/api-reference/processed-document-result.md @@ -0,0 +1,64 @@ +--- +layout: default-layout +title: ProcessedDocumentResult - Dynamsoft Document Normalizer Android SDK API Reference +description: The class ProcessedDocumentResult represents a collection of captured result items whose types are detected boundaries, deskew images or enhanced images. +keywords: detected boundaries, deskew images, enhanced images, csharp, kotlin +needGenerateH3Content: true +needAutoGenerateSidebar: true +noTitleIndex: true +--- + +# ProcessedDocumentResult + +The class `ProcessedDocumentResult` represents a collection of captured result items whose types are detected boundaries, deskew images or enhanced images. + +## Definition + +*Namespace:* com.dynamsoft.ddn + +*Assembly:* DynamsoftCaptureVisionBundle.aar + +```csharp +class ProcessedDocumentResult : CapturedResultBase +``` + +## Methods + +| Methods | Description | +| ---------- | ----------- | +| [`DeskewedImageResultItems`](#deskewedimageresultitems) | Represents the deskew images with an array of [`DeskewedImageResultItem`](deskewed-image-result-item.md). | +| [`DetectedQuadResultItems`](#detectedquadresultitems) | Represents the detected boundaries with an array of [`DetectedImageResultItem`](detected-image-result-item.md). | +| [`EnhancedImageResultItems`](#enhancedimageresultitems) | Represents the enhanced images with an array of [`EnhancedImageResultItem`](enhanced-image-result-item.md). | + +The following properties are inherited from [`CapturedResultBase`]({{ site.dcv_maui_api }}core/captured-result-base.html): + +| Property | Type | Description | +| -------- | ---- | ----------- | +| [`OriginalImageHashId`]({{ site.dcv_maui_api }}core/captured-result-base.html#originalimagehashid) | *string* | Represents the hash id of the original image. | +| [`RotationTransformMatrix`]({{ site.dcv_maui_api }}core/captured-result-base.html#rotationtransformmatrix) | *Matrix* | Represents the rotation transformation matrix of the original image relative to the rotated image. | +| [`ErrorCode`]({{ site.dcv_maui_api }}core/captured-result-base.html#errorcode) | *int* | Represents the error code of this result. | +| [`ErrorMessage`]({{ site.dcv_maui_api }}core/captured-result-base.html#errormessage) | *string* | Represents the error message of this result. | + +### DeskewedImageResultItems + +Represents an array of [`DeskewedImageResultItem`](deskewed-image-result-item.md) objects, where each `DeskewedImageResultItem` represents a single deskewed image. + +```csharp +DeskewedImageResultItem[]? DeskewedImageResultItems { get; } +``` + +### DetectedQuadResultItems + +Represents an array of [`DetectedQuadResultItem`](detected-quad-result-item.md) objects, where each `DetectedQuadResultItem` represents a single detected boundary. + +```csharp +DetectedQuadResultItem[]? DetectedQuadResultItems { get; } +``` + +### EnhancedImageResultItems + +Represents an array of [`EnhancedImageResultItem`](enhanced-image-result-item.md) objects, where each `EnhancedImageResultItem` represents a single enhnanced image. + +```csharp +EnhancedImageResultItem[]? EnhancedImageResultItems { get; } +``` diff --git a/programming/maui/user-guide-v2.6.1001.md b/programming/maui/user-guide-v2.6.1001.md new file mode 100644 index 0000000..0f06561 --- /dev/null +++ b/programming/maui/user-guide-v2.6.1001.md @@ -0,0 +1,391 @@ +--- +layout: default-layout +title: Detect and Normalize Document - MAUI User Guide +description: This page introduce how to detect and normalize document with Dynamsoft Capture Vision MAUI SDK. +keywords: user guide, maui +needAutoGenerateSidebar: true +needGenerateH3Content: true +noTitleIndex: true +--- + +# MAUI User Guide for Document Scanner Integration + +## Table of Contents + +- [MAUI User Guide for Document Scanner Integration](#maui-user-guide-for-document-scanner-integration) + - [Table of Contents](#table-of-contents) + - [System Requirements](#system-requirements) + - [.Net](#net) + - [Android](#android) + - [iOS](#ios) + - [Installation](#installation) + - [Visual Studio for Mac](#visual-studio-for-mac) + - [Visual Studio for Windows](#visual-studio-for-windows) + - [Build Your Document Scanner App](#build-your-document-scanner-app) + - [Set up Development Environment](#set-up-development-environment) + - [Initialize the Project](#initialize-the-project) + - [Visual Studio](#visual-studio) + - [Visual Studio for Mac](#visual-studio-for-mac-1) + - [Include the Library](#include-the-library) + - [Initialize MauiProgram](#initialize-mauiprogram) + - [License Activation](#license-activation) + - [Initialize the Capture Vision SDK](#initialize-the-capture-vision-sdk) + - [Add the CameraView control in the Main Page](#add-the-cameraview-control-in-the-main-page) + - [Open the Camera and Start Document Detection and Normalization](#open-the-camera-and-start-document-detection-and-normalization) + - [Obtaining Normalized Document Image](#obtaining-normalized-document-image) + - [Add the Image control in the Image Page](#add-the-image-control-in-the-image-page) + - [Display the Normalized Document Image](#display-the-normalized-document-image) + - [Run the Project](#run-the-project) + - [Licensing](#licensing) + +## System Requirements + +### .Net + +- .NET 7.0, 8.0 and 9.0. + +### Android + +- Supported OS: **Android 5.0** (API Level 21) or higher. +- Supported ABI: **armeabi-v7a**, **arm64-v8a**, **x86** and **x86_64**. +- Development Environment: Visual Studio 2022 recommended. +- JDK: 1.8+ + +### iOS + +- Supported OS: **iOS 11.0** or higher. +- Supported ABI: **arm64** and **x86_64**. +- Development Environment: Visual Studio 2022 for Mac and Xcode 14.3+ recommended. + +## Installation + +### Visual Studio for Mac + +In the **NuGet Package Manager>Manage Packages for Solution** of your project, search for **Dynamsoft.CaptureVisionBundle.Maui**. Select it and click **install**. + +### Visual Studio for Windows + +You need to add the library via the project file and complete additional steps for the installation. + +1. Add the library in the project file: + + ```xml + + ... + + ... + + + + ``` + +2. Open the **Package Manager Console** and run the following commands: + + ```bash + dotnet build + ``` + +> Note: +> +> - Windows system have a limitation of 260 characters in the path. If you don't use console to install the package, you will receive error "Could not find a part of the path 'C:\Users\admin\.nuget\packages\dynamsoft.imageprocessing.ios\2.2.300\lib\net7.0-ios16.1\Dynamsoft.ImageProcessing.iOS.resources\DynamsoftImageProcessing.xcframework\ios-arm64\dSYMs\DynamsoftImageProcessing.framework.dSYM\Contents\Resources\DWARF\DynamsoftImageProcessing'" +> - The library only support Android & iOS platform. Be sure that you remove the other platforms like Windows, maccatalyst, etc. + +## Build Your Document Scanner App + +Now you will learn how to create a SimpleDocumentScanner using Dynamsoft Capture Vision MAUI SDK. + +>Note: +> +> - You can get the similar source code of the SimpleDocumentScanner app from the following link +> - [C#](https://github.com/Dynamsoft/capture-vision-maui-samples/tree/main/DocumentScanner/AutoNormalize){:target="_blank"}. + +### Set up Development Environment + +If you are a beginner with MAUI, please follow the guide on the .Net MAUI official website to set up the development environment. + +### Initialize the Project + +#### Visual Studio + +1. Open the Visual Studio and select **Create a new project**. +2. Select **.Net MAUI App** and click **Next**. +3. Name the project **SimpleDocumentScanner**. Select a location for the project and click **Next**. +4. Select **.Net 7.0** and click **Create**. + +#### Visual Studio for Mac + +1. Open Visual Studio and select **New**. +2. Select **Multiplatform > App > .Net MAUI App > C#** and click **Continue**. +3. Select **.Net 7.0** and click **Continue**. +4. Name the project **SimpleDocumentScanner** and select a location, click **Create**. + +### Include the Library + +Add NuGet package **Dynamsoft.CaptureVisionBundle.Maui** to your project. You can view the [installation section](#installation) on how to add the library. + +### Initialize MauiProgram + +In **MauiProgram.cs**, add a custom handler for the [`CameraView`]({{ site.dce_maui_api }}camera-view.html) control. Specifically, it maps the [`CameraView`]({{ site.dce_maui_api }}camera-view.html) type to the `CameraViewHandler` type. + +```c# +namespace SimpleDocumentScanner; +using Microsoft.Extensions.Logging; +using Dynamsoft.CameraEnhancer.Maui; +using Dynamsoft.CameraEnhancer.Maui.Handlers; + +public static class MauiProgram +{ + public static MauiApp CreateMauiApp() + { + var builder = MauiApp.CreateBuilder(); + builder + .UseMauiApp() + .ConfigureFonts(fonts => + { + fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); + fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); + }) + .ConfigureMauiHandlers(handlers => + { + handlers.AddHandler(typeof(CameraView), typeof(CameraViewHandler)); + }); + +#if DEBUG + builder.Logging.AddDebug(); +#endif + + return builder.Build(); + } +} +``` + +### License Activation + +The Dynamsoft Capture Vision SDK needs a valid license to work. Please refer to the [Licensing](#licensing) section for more info on how to obtain a license. + +Go to **MainPage.xaml.cs**. Add the following code to activate the license: + +```c# +namespace SimpleDocumentScanner; +using Dynamsoft.License.Maui; +using System.Diagnostics; + +public partial class MainPage : ContentPage, ILicenseVerificationListener +{ + public MainPage() + { + InitializeComponent(); + LicenseManager.InitLicense("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9", this); + } + public void OnLicenseVerified(bool isSuccess, string message) + { + if (!isSuccess) + { + Debug.WriteLine(message); + } + } +} +``` + +### Initialize the Capture Vision SDK + +In the **MainPage.xaml.cs**, add the following code to initialize the Capture Vision SDK: + +```c# +...... +using Dynamsoft.CaptureVisionRouter.Maui; +using Dynamsoft.CameraEnhancer.Maui; +using Dynamsoft.Core.Maui; +using Dynamsoft.Utility.Maui; + +public partial class MainPage : ContentPage, ILicenseVerificationListener, ICapturedResultReceiver +{ + CameraEnhancer enhancer; + CaptureVisionRouter router; + + public MainPage() + { + ...... + + // Create an instance of CameraEnhancer + enhancer = new CameraEnhancer(); + // Create an instance of CaptureVisionRouter + router = new CaptureVisionRouter(); + // Bind the router with the created CameraEnhancer + router.SetInput(enhancer); + // Add the result receiver to receive the document normalized image + router.AddResultReceiver(this); + // Add the result filter to verify the result across multiple frames + var filter = new MultiFrameResultCrossFilter(); + filter.EnableResultCrossVerification(EnumCapturedResultItemType.CRIT_NORMALIZED_IMAGE, true); + router.AddResultFilter(filter); + } +} +``` + +### Add the CameraView control in the Main Page + +In the **MainPage.xaml**, add a [`CameraView`]({{ site.dce_maui_api }}camera-view.html) control: + +```xml + + + + + + +``` + +### Open the Camera and Start Document Detection and Normalization + +In this section, we are going to add code to start document detection and normalization in the **MainPage.xaml.cs**. + +```c# +...... + +public partial class MainPage : ContentPage, ILicenseVerificationListener, ICapturedResultReceiver, ICompletionListener +{ + ...... + protected override void OnHandlerChanged() + { + base.OnHandlerChanged(); + + if (this.Handler != null) + { + enhancer.SetCameraView(cameraView); + } + } + + protected override async void OnAppearing() + { + base.OnAppearing(); + // Request camera permission + await Permissions.RequestAsync(); + // Open camera + enhancer?.Open(); + // Start document detection and normalization + router?.StartCapturing(EnumPresetTemplate.PT_DETECT_AND_NORMALIZE_DOCUMENT, this); + } + + protected override void OnDisappearing() + { + base.OnDisappearing(); + // Close camera + enhancer?.Close(); + // Stop document detection and normalization + router?.StopCapturing(); + } + + // It is called when StartCapturing is successful + public void OnSuccess() + { + Debug.WriteLine("Success"); + } + + // It is called when StartCapturing is failed + public void OnFailure(int errorCode, string errorMessage) + { + Debug.WriteLine(errorMessage); + } +} +``` + +Open the **Info.plist** file under the **Platforms/iOS/** folder (Open with XML Text Editor). Add the following lines to request camera permission on iOS platform: + +```xml +NSCameraUsageDescription +The sample needs to access your camera. +``` + +### Obtaining Normalized Document Image + +In **MainPage.xaml.cs**, implement [`ICapturedResultReceiver`]({{ site.dcv_maui_api }}capture-vision-router/auxiliary-classes/captured-result-receiver.html) to receive normalized images result in [`OnNormalizedImagesReceived`]({{ site.dcv_maui_api }}capture-vision-router/auxiliary-classes/captured-result-receiver.html#onnormalizedimagesreceived) callback function. + +```c# +...... +using Dynamsoft.DocumentNormalizer.Maui; + +public partial class MainPage : ContentPage, ILicenseVerificationListener, ICapturedResultReceiver, ICompletionListener +{ + ...... + public void OnNormalizedImagesReceived(NormalizedImagesResult result) + { + if (result?.Items?.Count > 0) + { + router?.StopCapturing(); + enhancer?.ClearBuffer(); + var data = result.Items[0].ImageData; + MainThread.BeginInvokeOnMainThread(async () => + { + await Navigation.PushAsync(new ImagePage(data)); + }); + } + } +} +``` + +### Add the Image control in the Image Page + +In the **ImagePage.xaml**, add a `Image` control and three buttons: + +```xml + + + + + + +``` + +### Display the Normalized Document Image + +```c# +namespace SimpleDocumentScanner; +using Dynamsoft.Core.Maui; + +public partial class ImagePage : ContentPage +{ + ImageData data; + + public ImagePage(ImageData data) + { + InitializeComponent(); + this.data = data; + } + + protected override void OnHandlerChanged() + { + base.OnHandlerChanged(); + image.Source = data.ToImageSource(); + } +} +``` + +### Run the Project + +Select your device and run the project. + +You can get the similar source code of the SimpleDocumentScanner app from the following link: + +- [C#](https://github.com/Dynamsoft/capture-vision-maui-samples/tree/main/DocumentScanner/AutoNormalize){:target="_blank"}. + +> Note: If you are running Android only on Visual Studio Windows, please manually exclude iOS and Windows platforms. Otherwise, the Visual Studio will report type or namespace not found errors. + +![Exclude iOS and Windows from targets](../assets/maui-exclude.png) + +## Licensing + +- A one-day trial license is available by default for every new device to try Dynamsoft Capture Vision SDK. +- You can request a 30-day trial license via the [Request a Trial License](https://www.dynamsoft.com/customer/license/trialLicense?product=dcv&package=mobile&utm_source=docs){:target="_blank"} link. +- [Contact us](https://www.dynamsoft.com/company/contact/){:target="_blank"} to purchase a full license. diff --git a/programming/maui/user-guide.md b/programming/maui/user-guide.md index 0f06561..1edab7d 100644 --- a/programming/maui/user-guide.md +++ b/programming/maui/user-guide.md @@ -28,13 +28,10 @@ noTitleIndex: true - [Visual Studio for Mac](#visual-studio-for-mac-1) - [Include the Library](#include-the-library) - [Initialize MauiProgram](#initialize-mauiprogram) - - [License Activation](#license-activation) - - [Initialize the Capture Vision SDK](#initialize-the-capture-vision-sdk) - - [Add the CameraView control in the Main Page](#add-the-cameraview-control-in-the-main-page) - - [Open the Camera and Start Document Detection and Normalization](#open-the-camera-and-start-document-detection-and-normalization) - - [Obtaining Normalized Document Image](#obtaining-normalized-document-image) - - [Add the Image control in the Image Page](#add-the-image-control-in-the-image-page) - - [Display the Normalized Document Image](#display-the-normalized-document-image) + - [Add a CameraPage for Capturing the Document](#add-a-camerapage-for-capturing-the-document) + - [Add a EditorPage for Detected Boundary Editing](#add-a-editorpage-for-detected-boundary-editing) + - [Add a ImagePage for Displaying the Processed Document](#add-a-imagepage-for-displaying-the-processed-document) + - [Configure the Camera Permission](#configure-the-camera-permission) - [Run the Project](#run-the-project) - [Licensing](#licensing) @@ -42,7 +39,7 @@ noTitleIndex: true ### .Net -- .NET 7.0, 8.0 and 9.0. +- .NET 8.0 and 9.0. ### Android @@ -74,7 +71,7 @@ You need to add the library via the project file and complete additional steps f ... ... - + ``` @@ -92,11 +89,11 @@ You need to add the library via the project file and complete additional steps f ## Build Your Document Scanner App -Now you will learn how to create a SimpleDocumentScanner using Dynamsoft Capture Vision MAUI SDK. +Now you will learn how to create a ScanDocument using Dynamsoft Capture Vision MAUI SDK. >Note: > -> - You can get the similar source code of the SimpleDocumentScanner app from the following link +> - You can get the similar source code of the ScanDocument app from the following link > - [C#](https://github.com/Dynamsoft/capture-vision-maui-samples/tree/main/DocumentScanner/AutoNormalize){:target="_blank"}. ### Set up Development Environment @@ -109,192 +106,365 @@ If you are a beginner with MAUI, please follow the guide on the + public static MauiApp CreateMauiApp() + { + var builder = MauiApp.CreateBuilder(); + builder + .UseMauiApp() + .ConfigureFonts(fonts => + { + fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); + fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); + }) + .ConfigureMauiHandlers(handlers => { - handlers.AddHandler(typeof(CameraView), typeof(CameraViewHandler)); + handlers.AddHandler(); + handlers.AddHandler(typeof(ImageEditorView), typeof(ImageEditorViewHandler)); }); #if DEBUG - builder.Logging.AddDebug(); + builder.Logging.AddDebug(); #endif - return builder.Build(); - } -} -``` - -### License Activation - -The Dynamsoft Capture Vision SDK needs a valid license to work. Please refer to the [Licensing](#licensing) section for more info on how to obtain a license. - -Go to **MainPage.xaml.cs**. Add the following code to activate the license: - -```c# -namespace SimpleDocumentScanner; -using Dynamsoft.License.Maui; -using System.Diagnostics; - -public partial class MainPage : ContentPage, ILicenseVerificationListener -{ - public MainPage() - { - InitializeComponent(); - LicenseManager.InitLicense("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9", this); - } - public void OnLicenseVerified(bool isSuccess, string message) - { - if (!isSuccess) - { - Debug.WriteLine(message); - } - } + return builder.Build(); + } } ``` -### Initialize the Capture Vision SDK - -In the **MainPage.xaml.cs**, add the following code to initialize the Capture Vision SDK: - -```c# -...... -using Dynamsoft.CaptureVisionRouter.Maui; -using Dynamsoft.CameraEnhancer.Maui; -using Dynamsoft.Core.Maui; -using Dynamsoft.Utility.Maui; - -public partial class MainPage : ContentPage, ILicenseVerificationListener, ICapturedResultReceiver -{ - CameraEnhancer enhancer; - CaptureVisionRouter router; - - public MainPage() - { - ...... - - // Create an instance of CameraEnhancer - enhancer = new CameraEnhancer(); - // Create an instance of CaptureVisionRouter - router = new CaptureVisionRouter(); - // Bind the router with the created CameraEnhancer - router.SetInput(enhancer); - // Add the result receiver to receive the document normalized image - router.AddResultReceiver(this); - // Add the result filter to verify the result across multiple frames - var filter = new MultiFrameResultCrossFilter(); - filter.EnableResultCrossVerification(EnumCapturedResultItemType.CRIT_NORMALIZED_IMAGE, true); - router.AddResultFilter(filter); - } -} -``` - -### Add the CameraView control in the Main Page - -In the **MainPage.xaml**, add a [`CameraView`]({{ site.dce_maui_api }}camera-view.html) control: - -```xml - - - - - - -``` - -### Open the Camera and Start Document Detection and Normalization - -In this section, we are going to add code to start document detection and normalization in the **MainPage.xaml.cs**. - -```c# -...... - -public partial class MainPage : ContentPage, ILicenseVerificationListener, ICapturedResultReceiver, ICompletionListener -{ - ...... - protected override void OnHandlerChanged() - { - base.OnHandlerChanged(); - - if (this.Handler != null) - { - enhancer.SetCameraView(cameraView); - } - } - - protected override async void OnAppearing() - { - base.OnAppearing(); - // Request camera permission - await Permissions.RequestAsync(); - // Open camera - enhancer?.Open(); - // Start document detection and normalization - router?.StartCapturing(EnumPresetTemplate.PT_DETECT_AND_NORMALIZE_DOCUMENT, this); - } - - protected override void OnDisappearing() - { - base.OnDisappearing(); - // Close camera - enhancer?.Close(); - // Stop document detection and normalization - router?.StopCapturing(); - } - - // It is called when StartCapturing is successful - public void OnSuccess() - { - Debug.WriteLine("Success"); - } - - // It is called when StartCapturing is failed - public void OnFailure(int errorCode, string errorMessage) - { - Debug.WriteLine(errorMessage); - } -} -``` +### Add a CameraPage for Capturing the Document + +1. Create a new ContentPage(XAML) and name it CameraPage. + +2. Add the following code to the **CameraPage.xaml**: + + ```xml + + + + +