Skip to content

Commit 2832455

Browse files
update ddn guide
1 parent 36dfbc9 commit 2832455

File tree

1 file changed

+36
-23
lines changed

1 file changed

+36
-23
lines changed

programming/dotnet/user-guide/document-scanner.md

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ Search for and install the `Dynamsoft.DotNet.CaptureVision.Bundle` nuget package
4747
Open the `Program.cs` file and add the following namespaces.
4848

4949
```csharp
50-
using Dynamsoft.Core;
5150
using Dynamsoft.CVR;
5251
using Dynamsoft.License;
53-
using Dynamsoft.DCP;
52+
using Dynamsoft.Core;
53+
using Dynamsoft.Utility;
54+
using Dynamsoft.DDN;
5455
```
5556

5657
### Initialize the License Key
@@ -84,10 +85,8 @@ using (CaptureVisionRouter cvRouter = new CaptureVisionRouter())
8485
using (CaptureVisionRouter cvRouter = new CaptureVisionRouter())
8586
{
8687
string imageFile = "[PATH-TO-THE-IMAGE-FILE]";
87-
using (CapturedResult? result = cvRouter.Capture(imageFile, PresetTemplate.PT_DETECT_AND_NORMALIZE_DOCUMENT))
88-
{
89-
//code for saving the normalized result as an image file
90-
}
88+
CapturedResult[] results = cvRouter.CaptureMultiPages(imageFile, PresetTemplate.PT_DETECT_AND_NORMALIZE_DOCUMENT)
89+
//code for saving the normalized result as an image file
9190
}
9291
```
9392

@@ -96,32 +95,46 @@ using (CaptureVisionRouter cvRouter = new CaptureVisionRouter())
9695
2. Save the normalized result as an image file
9796

9897
```csharp
99-
if (result == null)
98+
if (results == null || results.Length == 0)
10099
{
101100
Console.WriteLine("No document detected.");
102101
}
103102
else
104103
{
105-
if (result.GetErrorCode() != 0)
106-
{
107-
Console.WriteLine("Error: " + result.GetErrorCode() + ", " + result.GetErrorString());
108-
}
109-
NormalizedImagesResult? normalizedImagesResult = result.GetNormalizedImagesResult();
110-
if (normalizedImagesResult != null)
104+
for (int index = 0; index < results.Length; index++)
111105
{
112-
NormalizedImageResultItem[] items = normalizedImagesResult.GetItems();
113-
Console.WriteLine("Normalized " + items.Length + " documents");
114-
foreach (NormalizedImageResultItem normalizedItem in items)
106+
CapturedResult result = results[index];
107+
if (result.GetErrorCode() == (int)EnumErrorCode.EC_UNSUPPORTED_JSON_KEY_WARNING)
108+
{
109+
Console.WriteLine("Warning: " + result.GetErrorCode() + ", " + result.GetErrorString());
110+
}
111+
else if (result.GetErrorCode() != (int)EnumErrorCode.EC_OK)
112+
{
113+
Console.WriteLine("Error: " + result.GetErrorCode() + ", " + result.GetErrorString());
114+
}
115+
FileImageTag tag = result.GetOriginalImageTag() as FileImageTag;
116+
int pageNumber = tag != null ? tag.GetPageNumber() : index;
117+
ProcessedDocumentResult processedDocumentResult = result.GetProcessedDocumentResult();
118+
if (processedDocumentResult == null || processedDocumentResult.GetEnhancedImageResultItems().Length == 0)
119+
{
120+
Console.WriteLine("Page-" + (pageNumber + 1) + " No document found.");
121+
}
122+
else
115123
{
116-
string outPath = "normalizedResult_" + Array.IndexOf(items, normalizedItem) + ".png";
117-
ImageManager imageManager = new ImageManager();
118-
var image = normalizedItem.GetImageData();
119-
if (image != null)
124+
EnhancedImageResultItem[] items = processedDocumentResult.GetEnhancedImageResultItems();
125+
for (int i = 0; i < items.Length; i++)
120126
{
121-
errorCode = imageManager.SaveToFile(image, outPath);
122-
if (errorCode == 0)
127+
EnhancedImageResultItem enhancedResult = items[i];
128+
string outPath = "Page_" + (pageNumber + 1) + "enhancedResult_" + i + ".png";
129+
ImageIO imageIo = new ImageIO();
130+
var image = enhancedResult.GetImageData();
131+
if (image != null)
123132
{
124-
Console.WriteLine("Document " + Array.IndexOf(items, normalizedItem) + " file: " + outPath);
133+
errorCode = imageIo.SaveToFile(image, outPath);
134+
if (errorCode == 0)
135+
{
136+
Console.WriteLine("Document " + i + " file: " + outPath);
137+
}
125138
}
126139
}
127140
}

0 commit comments

Comments
 (0)