DocumentScannerSDK 2.0.1
dotnet add package DocumentScannerSDK --version 2.0.1
NuGet\Install-Package DocumentScannerSDK -Version 2.0.1
<PackageReference Include="DocumentScannerSDK" Version="2.0.1" />
paket add DocumentScannerSDK --version 2.0.1
#r "nuget: DocumentScannerSDK, 2.0.1"
// Install DocumentScannerSDK as a Cake Addin
#addin nuget:?package=DocumentScannerSDK&version=2.0.1
// Install DocumentScannerSDK as a Cake Tool
#tool nuget:?package=DocumentScannerSDK&version=2.0.1
.NET Document Scanner SDK
The .NET Document Scanner SDK is a C# wrapper for Dynamsoft 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)
- Android
- iOS
API
public static void InitLicense(string license)
: Initialize the license key. It must be called before creating the document scanner object.public static DocumentScanner Create()
: Create the document scanner object.public Result[]? DetectFile(string filename)
: Detect documents from an image file.public Result[]? DetectBuffer(byte[] buffer, int width, int height, int stride, ImagePixelFormat format)
: Detect documents from a buffer.public NormalizedImage NormalizeFile(string filename, int[] points)
: Normalize the detected documents from an image file.public NormalizedImage NormalizeBuffer(byte[] buffer, int width, int height, int stride, ImagePixelFormat format, int[] points)
: Normalize the detected documents from a buffer.public static string? GetVersionInfo()
: Get SDK version number.public void SetParameters(string parameters)
: Customize the parameters. Refer to Parameter Organization for more details.
Usage
Set the license key:
DocumentScanner.InitLicense("LICENSE-KEY");
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:
Result[]? resultArray = scanner.DetectBuffer(bytes, width, height, stride, 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("LICENSE-KEY"); // 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
Command-line Document Scanner (Windows & Linux)
dotnet run
Command-line Document Scanner with OpenCVSharp Windows runtime. To make it work on Linux, you need to install OpenCVSharp4.runtime.ubuntu.18.04-x64 package.
dotnet run
WinForms Desktop Document Scanner (Windows Only)
dotnet run
Building NuGet Package from Source Code
# build dll for desktop
cd desktop
dotnet build --configuration Release
# build dll for android
cd android
dotnet build --configuration Release
# build dll for iOS
cd ios
dotnet build --configuration Release
# build nuget package
nuget pack .\DocumentScannerSDK.nuspec
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-android33.0 is compatible. net7.0-ios was computed. net7.0-ios16.1 is compatible. 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. |
This package has 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.
Updated color template for Android.