Skip to content

Commit abf65e6

Browse files
authored
Update Program.cs
1 parent ea243d0 commit abf65e6

File tree

1 file changed

+62
-45
lines changed
  • samples/Performance/ReadRateFirstSettings

1 file changed

+62
-45
lines changed

samples/Performance/ReadRateFirstSettings/Program.cs

Lines changed: 62 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using System;
2-
using Dynamsoft;
1+
using System;
2+
using Dynamsoft;
33
using Dynamsoft.DBR;
44

55
namespace ReadRateFirstSettings
@@ -8,75 +8,70 @@ class Program
88
{
99
static void configReadRateFirst(BarcodeReader dbr)
1010
{
11+
// Obtain current runtime settings of instance.
1112
PublicRuntimeSettings sts = dbr.GetRuntimeSettings();
1213

14+
// Parameter 1. Set expected barcode formats
15+
// Here the barcode scanner will try to find the maximal barcode formats.
1316
sts.BarcodeFormatIds = (int)EnumBarcodeFormat.BF_ALL;
1417
sts.BarcodeFormatIds_2 = (int)EnumBarcodeFormat_2.BF2_DOTCODE | (int)EnumBarcodeFormat_2.BF2_POSTALCODE;
1518

19+
// Parameter 2. Set expected barcode count.
20+
// Here the barcode scanner will try to find 64 barcodes.
21+
// If the result count does not reach the expected amount, the barcode scanner will try other algorithms in the setting list to find enough barcodes.
1622
sts.ExpectedBarcodesCount = 64;
1723

24+
// Parameter 3. Set more binarization modes.
1825
sts.BinarizationModes[0] = EnumBinarizationMode.BM_LOCAL_BLOCK;
1926
sts.BinarizationModes[1] = EnumBinarizationMode.BM_THRESHOLD;
20-
sts.BinarizationModes[2] = EnumBinarizationMode.BM_SKIP;
21-
sts.BinarizationModes[3] = EnumBinarizationMode.BM_SKIP;
22-
sts.BinarizationModes[4] = EnumBinarizationMode.BM_SKIP;
23-
sts.BinarizationModes[5] = EnumBinarizationMode.BM_SKIP;
24-
sts.BinarizationModes[6] = EnumBinarizationMode.BM_SKIP;
25-
sts.BinarizationModes[7] = EnumBinarizationMode.BM_SKIP;
2627

28+
// Parameter 4. Set more localization modes.
29+
// LocalizationModes are all enabled as default. Barcode reader will automatically switch between the modes and try decoding continuously until timeout or the expected barcode count is reached.
30+
// Please manually update the enabled modes list or change the expected barcode count to promote the barcode scanning speed.
31+
// Read more about localization mode members: https://www.dynamsoft.com/barcode-reader/parameters/enum/parameter-mode-enums.html?ver=latest#localizationmode
2732
sts.LocalizationModes[0] = EnumLocalizationMode.LM_CONNECTED_BLOCKS;
2833
sts.LocalizationModes[1] = EnumLocalizationMode.LM_SCAN_DIRECTLY;
2934
sts.LocalizationModes[2] = EnumLocalizationMode.LM_STATISTICS;
3035
sts.LocalizationModes[3] = EnumLocalizationMode.LM_LINES;
3136
sts.LocalizationModes[4] = EnumLocalizationMode.LM_STATISTICS_MARKS;
3237
sts.LocalizationModes[5] = EnumLocalizationMode.LM_STATISTICS_POSTAL_CODE;
33-
sts.LocalizationModes[6] = EnumLocalizationMode.LM_SKIP;
34-
sts.LocalizationModes[7] = EnumLocalizationMode.LM_SKIP;
3538

39+
// Parameter 5. Set more deblur modes.
40+
// DeblurModes are all enabled as default. Barcode reader will automatically switch between the modes and try decoding continuously until timeout or the expected barcode count is reached.
41+
// Please manually update the enabled modes list or change the expected barcode count to promote the barcode scanning speed.
42+
//Read more about deblur mode members: https://www.dynamsoft.com/barcode-reader/parameters/enum/parameter-mode-enums.html#deblurmode
3643
sts.DeblurModes[0] = EnumDeblurMode.DM_DIRECT_BINARIZATION;
3744
sts.DeblurModes[1] = EnumDeblurMode.DM_THRESHOLD_BINARIZATION;
3845
sts.DeblurModes[2] = EnumDeblurMode.DM_GRAY_EQUALIZATION;
3946
sts.DeblurModes[3] = EnumDeblurMode.DM_SMOOTHING;
4047
sts.DeblurModes[4] = EnumDeblurMode.DM_MORPHING;
4148
sts.DeblurModes[5] = EnumDeblurMode.DM_DEEP_ANALYSIS;
4249
sts.DeblurModes[6] = EnumDeblurMode.DM_SHARPENING;
43-
sts.DeblurModes[7] = EnumDeblurMode.DM_SKIP;
44-
sts.DeblurModes[8] = EnumDeblurMode.DM_SKIP;
45-
sts.DeblurModes[9] = EnumDeblurMode.DM_SKIP;
4650

51+
// Parameter 6. Set scale up modes.
52+
// It is a parameter to control the process for scaling up an image used for detecting barcodes with small module size
4753
sts.ScaleUpModes[0] = EnumScaleUpMode.SUM_AUTO;
48-
sts.ScaleUpModes[1] = EnumScaleUpMode.SUM_SKIP;
49-
sts.ScaleUpModes[2] = EnumScaleUpMode.SUM_SKIP;
50-
sts.ScaleUpModes[3] = EnumScaleUpMode.SUM_SKIP;
51-
sts.ScaleUpModes[4] = EnumScaleUpMode.SUM_SKIP;
52-
sts.ScaleUpModes[5] = EnumScaleUpMode.SUM_SKIP;
53-
sts.ScaleUpModes[6] = EnumScaleUpMode.SUM_SKIP;
54-
sts.ScaleUpModes[7] = EnumScaleUpMode.SUM_SKIP;
55-
54+
55+
// Parameter 7. Set grayscale transformation modes.
56+
// By default, the library can only locate the dark barcodes that stand on a light background. "GTM_INVERTED":The image will be transformed into inverted grayscale.
5657
sts.FurtherModes.GrayscaleTransformationModes[0] = EnumGrayscaleTransformationMode.GTM_ORIGINAL;
5758
sts.FurtherModes.GrayscaleTransformationModes[1] = EnumGrayscaleTransformationMode.GTM_INVERTED;
58-
sts.FurtherModes.GrayscaleTransformationModes[2] = EnumGrayscaleTransformationMode.GTM_SKIP;
59-
sts.FurtherModes.GrayscaleTransformationModes[3] = EnumGrayscaleTransformationMode.GTM_SKIP;
60-
sts.FurtherModes.GrayscaleTransformationModes[4] = EnumGrayscaleTransformationMode.GTM_SKIP;
61-
sts.FurtherModes.GrayscaleTransformationModes[5] = EnumGrayscaleTransformationMode.GTM_SKIP;
62-
sts.FurtherModes.GrayscaleTransformationModes[6] = EnumGrayscaleTransformationMode.GTM_SKIP;
63-
sts.FurtherModes.GrayscaleTransformationModes[7] = EnumGrayscaleTransformationMode.GTM_SKIP;
6459

60+
// Parameter 8. Enable dpm modes.
61+
// It is a parameter to control how to read direct part mark (DPM) barcodes.
6562
sts.FurtherModes.DPMCodeReadingModes[0] = EnumDPMCodeReadingMode.DPMCRM_GENERAL;
66-
sts.FurtherModes.DPMCodeReadingModes[1] = EnumDPMCodeReadingMode.DPMCRM_SKIP;
67-
sts.FurtherModes.DPMCodeReadingModes[2] = EnumDPMCodeReadingMode.DPMCRM_SKIP;
68-
sts.FurtherModes.DPMCodeReadingModes[3] = EnumDPMCodeReadingMode.DPMCRM_SKIP;
69-
sts.FurtherModes.DPMCodeReadingModes[4] = EnumDPMCodeReadingMode.DPMCRM_SKIP;
70-
sts.FurtherModes.DPMCodeReadingModes[5] = EnumDPMCodeReadingMode.DPMCRM_SKIP;
71-
sts.FurtherModes.DPMCodeReadingModes[6] = EnumDPMCodeReadingMode.DPMCRM_SKIP;
72-
sts.FurtherModes.DPMCodeReadingModes[7] = EnumDPMCodeReadingMode.DPMCRM_SKIP;
7363

64+
// Parameter 9. Increase timeout(ms). The barcode scanner will have more chances to find the expected barcode until it times out
7465
sts.Timeout = 30000;
66+
67+
// Apply the new settings to the instance
7568
dbr.UpdateRuntimeSettings(sts);
7669

7770
}
7871

7972
static void configReadRateFirstByTemplate(BarcodeReader dbr) {
73+
// Compared with PublicRuntimeSettings, parameter templates have a richer ability to control parameter details.
74+
// Please refer to the parameter explanation in "ReadRateFirstTemplate.json" to understand how to control read rate first.
8075
string errorMessage;
8176
EnumErrorCode ret=dbr.InitRuntimeSettingsWithFile("ReadRateFirstTemplate.json", EnumConflictMode.CM_OVERWRITE,out errorMessage);
8277
}
@@ -102,39 +97,61 @@ static void Main(string[] args)
10297
{
10398
try
10499
{
105-
DMDLSConnectionParameters connectionInfo = BarcodeReader.InitDLSConnectionParameters();
106-
connectionInfo.OrganizationID = "200001";
107-
EnumErrorCode errorCode = BarcodeReader.InitLicenseFromDLS(connectionInfo, out string errorMsg);
108-
if (errorCode != EnumErrorCode.DBR_SUCCESS)
109-
{
110-
Console.WriteLine(errorMsg);
100+
// Initialize license
101+
/*
102+
// By setting organizaion ID as "200001", a 7-day trial license will be used for license verification.
103+
// Note that network connection is required for this license to work.
104+
//
105+
// When using your own license, locate the following line and specify your Organization ID.
106+
// organizationID = "200001";
107+
//
108+
// If you don't have a license yet, you can request a trial from https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=samples&package=dotnet
109+
*/
110+
DMDLSConnectionParameters connectionInfo = BarcodeReader.InitDLSConnectionParameters();
111+
connectionInfo.OrganizationID = "200001";
112+
EnumErrorCode errorCode = BarcodeReader.InitLicenseFromDLS(connectionInfo, out string errorMsg);
113+
if (errorCode != EnumErrorCode.DBR_SUCCESS)
114+
{
115+
Console.WriteLine(errorMsg);
111116
}
112-
117+
118+
// Create an instance of Barcode Reader
113119
BarcodeReader dbr = new BarcodeReader();
114120
TextResult[] results = null;
115121
string fileName = "../../../../../images/AllSupportedBarcodeTypes.png";
116122

123+
// There are two ways to configure runtime parameters. One is through PublicRuntimeSettings, the other is through parameters template.
117124
Console.WriteLine("Decode through PublicRuntimeSettings:");
118125
{
126+
// config through PublicRuntimeSettings
119127
configReadRateFirst(dbr);
128+
129+
// Decode barcodes from an image file by current runtime settings. The second parameter value "" means to decode through the current PublicRuntimeSettings.
120130
results = dbr.DecodeFile(fileName, "");
131+
132+
// Output the barcode format and barcode text.
121133
outputResults(results);
122134
}
123135

124136
Console.WriteLine("\r\n");
125137

126138
Console.WriteLine("Decode through parameters template:");
127139
{
140+
// config through parameters template
128141
configReadRateFirstByTemplate(dbr);
142+
143+
// Decode barcodes from an image file by template.
129144
results = dbr.DecodeFile(fileName, "");
145+
146+
// Output the barcode format and barcode text.
130147
outputResults(results);
131148
}
132149
}
133-
catch (Exception exp)
134-
{
135-
Console.WriteLine(exp.Message);
150+
catch (Exception exp)
151+
{
152+
Console.WriteLine(exp.Message);
136153
}
137-
Console.WriteLine("Press any key to quit...");
154+
Console.WriteLine("Press any key to quit...");
138155
Console.ReadKey();
139156
}
140157
}

0 commit comments

Comments
 (0)