Skip to content

Commit 9af58da

Browse files
authored
Update Program.cs
1 parent abf65e6 commit 9af58da

File tree

1 file changed

+65
-1
lines changed

1 file changed

+65
-1
lines changed

samples/Performance/SpeedFirstSettings/Program.cs

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,67 @@ class Program
88
{
99
static public void configSpeedFirst(ref BarcodeReader dbr)
1010
{
11+
// Obtain current runtime settings of instance.
1112
PublicRuntimeSettings settings = dbr.GetRuntimeSettings();
13+
14+
// Parameter 1. Set expected barcode formats
15+
// The simpler barcode format, the faster decoding speed.
16+
// Here we use OneD barcode format to demonstrate.
1217
settings.BarcodeFormatIds = (int)EnumBarcodeFormat.BF_EAN_13;
18+
19+
// Parameter 2. Set expected barcode count
20+
// The less barcode count, the faster decoding speed.
1321
settings.ExpectedBarcodesCount = 1;
22+
23+
// Parameter 3. Set the threshold for the image shrinking for localization.
24+
// The smaller the threshold, the smaller the image shrinks. The default value is 2300.
1425
settings.ScaleDownThreshold = 1200;
1526

27+
// Parameter 4. Set the binarization mode for convert grayscale image to binary image.
28+
// Mostly, the less binarization modes set, the faster decoding speed.
1629
settings.BinarizationModes[0] = EnumBinarizationMode.BM_LOCAL_BLOCK;
1730

31+
// Parameter 5. Set localization mode.
32+
// LM_SCAN_DIRECTLY: Localizes barcodes quickly. It is both for OneD and TweD barcodes. This mode is recommended in interactive scenario.
1833
settings.LocalizationModes[0] = EnumLocalizationMode.LM_SCAN_DIRECTLY;
1934
settings.LocalizationModes[1] = EnumLocalizationMode.LM_SKIP;
2035
settings.LocalizationModes[2] = EnumLocalizationMode.LM_SKIP;
2136
settings.LocalizationModes[3] = EnumLocalizationMode.LM_SKIP;
2237

38+
// LM_ONED_FAST_SCAN: Localizing barcodes quickly. However, it is only for OneD barcodes. It is also recommended in interactive scenario.
39+
// sts.localizationModes = new int[]{EnumLocalizationMode.LM_ONED_FAST_SCAN, 0,0,0,0,0,0,0};
40+
41+
// Parameter 6. Reduce deblurModes setting
42+
// DeblurModes will improve the readability and accuracy but decrease the reading speed.
43+
// Please update your settings here if you want to enable different Deblurmodes.
2344
settings.DeblurModes[0] = EnumDeblurMode.DM_BASED_ON_LOC_BIN;
2445
settings.DeblurModes[1] = EnumDeblurMode.DM_THRESHOLD_BINARIZATION;
2546

47+
// Parameter 7. Set timeout(ms) if the application is very time sensitive.
48+
// If timeout, the decoding thread will exit at the next check point.
2649
settings.Timeout = 100;
50+
2751
dbr.UpdateRuntimeSettings(settings);
2852

53+
// Other potentially accelerated arguments of various modes.
54+
55+
// Argument 4.a Disable the EnableFillBinaryVacancy argument.
56+
// Local block binarization process might cause vacant area in barcode. The barcode reader will fill the vacant black by default (default value 1). Set the value 0 to disable this process.
2957
string strErrorMessage;
3058
dbr.SetModeArgument("BinarizationModes", 0, "EnableFillBinaryVacancy", "0", out strErrorMessage);
59+
60+
// Argument 5.a Sets the scan direction when searching barcode.
61+
// It is valid only when the type of LocalizationMode is LM_ONED_FAST_SCAN or LM_SCAN_DIRECTLY.
62+
// 0: Both vertical and horizontal direction.
63+
// 1: Vertical direction.
64+
// 2: Horizontal direction.
65+
// Read more about localization mode members: https://www.dynamsoft.com/barcode-reader/parameters/enum/parameter-mode-enums.html?ver=latest#localizationmode
3166
dbr.SetModeArgument("LocalizationModes", 0, "ScanDirection", "0", out strErrorMessage);
3267
}
3368
static public void configSpeedFirstByTemplate(ref BarcodeReader dbr)
3469
{
70+
// Compared with PublicRuntimeSettings, parameter templates have a richer ability to control parameter details.
71+
// Please refer to the parameter explanation in "SpeedFirstTemplate.json" to understand how to control speed first.
3572
string strErrorMessage;
3673
EnumErrorCode ret = dbr.InitRuntimeSettingsWithFile("SpeedFirstTemplate.json", EnumConflictMode.CM_OVERWRITE, out strErrorMessage);
3774
}
@@ -58,6 +95,16 @@ static void Main(string[] args)
5895
{
5996
try
6097
{
98+
// Initialize license
99+
/*
100+
// By setting organizaion ID as "200001", a 7-day trial license will be used for license verification.
101+
// Note that network connection is required for this license to work.
102+
//
103+
// When using your own license, locate the following line and specify your Organization ID.
104+
// organizationID = "200001";
105+
//
106+
// 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
107+
*/
61108
DMDLSConnectionParameters connectionInfo = BarcodeReader.InitDLSConnectionParameters();
62109
connectionInfo.OrganizationID = "200001";
63110
EnumErrorCode errorCode = BarcodeReader.InitLicenseFromDLS(connectionInfo, out string errorMsg);
@@ -66,30 +113,47 @@ static void Main(string[] args)
66113
Console.WriteLine(errorMsg);
67114
}
68115

116+
// Create an instance of Barcode Reader
69117
BarcodeReader dbr = new BarcodeReader();
70118
TextResult[] results = null;
71119
string fileName = "../../../../../images/AllSupportedBarcodeTypes.png";
72120

121+
// There are two ways to configure runtime parameters. One is through PublicRuntimeSettings, the other is through parameters template.
73122
Console.WriteLine("Decode through PublicRuntimeSettings:");
74123
{
124+
// config through PublicRuntimeSettings
75125
configSpeedFirst(ref dbr);
126+
76127
DateTime beforeRead = DateTime.Now;
128+
129+
// Decode barcodes from an image file by current runtime settings. The second parameter value "" means to decode through the current PublicRuntimeSettings.
77130
results = dbr.DecodeFile(fileName, "");
131+
78132
DateTime afterRead = DateTime.Now;
133+
79134
int timeElapsed = (int)(afterRead - beforeRead).TotalMilliseconds;
135+
136+
// Output the barcode format and barcode text.
80137
outputResults(results, timeElapsed);
81138
}
82139

83140
Console.WriteLine("\r\n");
84141

85142
Console.WriteLine("Decode through parameters template:");
86143
{
87-
144+
// config through parameters template
88145
configSpeedFirstByTemplate(ref dbr);
146+
89147
DateTime beforeRead = DateTime.Now;
148+
149+
// Decode barcodes from an image file by template.
90150
results = dbr.DecodeFile(fileName, "");
151+
91152
DateTime afterRead = DateTime.Now;
153+
92154
int timeElapsed = (int)(afterRead - beforeRead).TotalMilliseconds;
155+
156+
// Output the barcode format and barcode text.
93157
outputResults(results, timeElapsed);
94158
}
95159
}

0 commit comments

Comments
 (0)