DocumentScannerSDK 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package DocumentScannerSDK --version 1.1.0
NuGet\Install-Package DocumentScannerSDK -Version 1.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DocumentScannerSDK" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DocumentScannerSDK --version 1.1.0
#r "nuget: DocumentScannerSDK, 1.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DocumentScannerSDK as a Cake Addin
#addin nuget:?package=DocumentScannerSDK&version=1.1.0

// Install DocumentScannerSDK as a Cake Tool
#tool nuget:?package=DocumentScannerSDK&version=1.1.0

.NET Document Scanner SDK

The .NET Document Scanner SDK is a C# wrapper for Dynamsoft C++ Document Normalizer SDK. It is used to do document edge detection, image cropping, perspective correction and image enhancement.

License Activation

Click here to get a valid license key.

Supported Platforms

  • Windows (x64)
  • Linux (x64)

Download .NET 6 SDK

Methods

  • public static void InitLicense(string license)
  • public static DocumentScanner Create()
  • public Result[]? DetectFile(string filename)
  • public Result[]? DetectBuffer(byte[] buffer, int width, int height, int stride, ImagePixelFormat format)
  • public NormalizedImage NormalizeFile(string filename, int[] points)
  • public NormalizedImage NormalizeBuffer(byte[] buffer, int width, int height, int stride, ImagePixelFormat format, int[] points)
  • public static string? GetVersionInfo()
  • public void SetParameters(string parameters)

Usage

  • Set the license key:

    DocumentScanner.InitLicense("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ=="); 
    
  • Initialize the document scanner object:

    DocumentScanner scanner = DocumentScanner.Create();
    
  • Detect documents from an image file:

    Result[]? resultArray = scanner.DetectFile(filename);
    
  • Detect documents from a buffer:

    Mat mat = Cv2.ImRead(filename, ImreadModes.Color);
    
    int length = mat.Cols * mat.Rows * mat.ElemSize();
    byte[] bytes = new byte[length];
    Marshal.Copy(mat.Data, bytes, 0, length);
    
    Result[]? resultArray = scanner.DetectBuffer(bytes, mat.Cols, mat.Rows, (int)mat.Step(), DocumentScanner.ImagePixelFormat.IPF_RGB_888);
    
  • Normalize the detected documents from an image file:

    if (resultArray != null)
    {
        foreach (Result result in resultArray)
        {
            if (result.Points != null)
            {
                NormalizedImage image = scanner.NormalizeFile(filename, result.Points);
                if (image != null)
                {
                    image.Save(DateTime.Now.ToFileTimeUtc() + ".png");
                }
            }
    
        }
    }
    
  • Normalize the detected documents from a buffer:

    if (resultArray != null)
    {
        foreach (DocumentScanner.Result result in resultArray)
        {
            if (result.Points != null)
            {
                int length = mat.Cols * mat.Rows * mat.ElemSize();
                byte[] bytes = new byte[length];
                Marshal.Copy(mat.Data, bytes, 0, length);
    
                DocumentScanner.NormalizedImage image = scanner.NormalizeBuffer(bytes, mat.Cols, mat.Rows, (int)mat.Step(), DocumentScanner.ImagePixelFormat.IPF_RGB_888, result.Points);
                if (image != null && image.Data != null)
                {
                    image.Save(DateTime.Now.ToFileTimeUtc() + ".png");
                }
            }
    
        }
    }
    
  • Get SDK version number:

    string? version = DocumentScanner.GetVersionInfo();
    
  • Customize the parameters:

    // Refer to https://www.dynamsoft.com/document-normalizer/docs/parameters/parameter-organization-structure.html?ver=latest
    scanner.SetParameters(DocumentScanner.Templates.color);
    

Quick Start

using System;
using System.Runtime.InteropServices;
using Dynamsoft;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            DocumentScanner.InitLicense("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ=="); // Get a license key from https://www.dynamsoft.com/customer/license/trialLicense?product=ddn
            DocumentScanner? scanner = null;
            try {
                scanner = DocumentScanner.Create();
                scanner.SetParameters(DocumentScanner.Templates.color);
                Console.WriteLine("Please enter an image file: ");
                string? filename = Console.ReadLine();
                if (filename != null) {
                    Result[]? resultArray = scanner.DetectFile(filename);
                    if (resultArray != null)
                    {
                        foreach (DocumentScanner.Result result in resultArray)
                        {
                            Console.WriteLine("Confidence: " + result.Confidence);
                            if (result.Points != null)
                            {
                                foreach (int point in result.Points)
                                {
                                    Console.WriteLine("Point: " + point);
                                }

                                DocumentScanner.NormalizedImage image = scanner.NormalizeFile("1.png", result.Points);
                                if (image != null)
                                {
                                    image.Save(DateTime.Now.ToFileTimeUtc() + ".png");
                                }
                            }

                        }
                    }
                    else {
                        Console.WriteLine("No document detected.");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}

Example

Building NuGet Package from Source Code

dotnet build --configuration Release
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 198 3/5/2024
1.2.0 133 1/24/2024
1.1.0 304 7/27/2023
1.0.1 356 11/21/2022
1.0.0.1 362 9/21/2022
1.0.0 365 9/21/2022

- Changed IntPtr to byte[].