-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog-detailed-timing-for-each-processing-stage-loading-preprocessing-detection-and-decoding-to-identify-bottlenecks.cs
More file actions
106 lines (97 loc) · 4.31 KB
/
Copy pathlog-detailed-timing-for-each-processing-stage-loading-preprocessing-detection-and-decoding-to-identify-bottlenecks.cs
File metadata and controls
106 lines (97 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Diagnostics;
using System.IO;
using Aspose.Drawing;
using Aspose.BarCode;
using Aspose.BarCode.Generation;
using Aspose.BarCode.BarCodeRecognition;
/// <summary>
/// Demonstrates barcode generation, loading, preprocessing, detection, and decoding
/// while measuring the time taken for each stage.
/// </summary>
class Program
{
/// <summary>
/// Entry point of the application.
/// Generates a barcode image, reads it back, and outputs detection results.
/// </summary>
static void Main()
{
// --------------------------------------------------------------------
// Prepare temporary file path for the sample barcode image
// --------------------------------------------------------------------
string tempDir = Path.GetTempPath();
string imagePath = Path.Combine(tempDir, "sample_barcode.png");
// --------------------------------------------------------------------
// Stage: Barcode generation (setup)
// --------------------------------------------------------------------
using (var generator = new BarcodeGenerator(EncodeTypes.Code128, "Test123"))
{
// Save the generated barcode to the temporary file
generator.Save(imagePath);
}
// Verify that the image was created successfully
if (!File.Exists(imagePath))
{
Console.WriteLine($"Failed to create barcode image at {imagePath}");
return;
}
// Stopwatch for timing each processing stage
var stopwatch = new Stopwatch();
// --------------------------------------------------------------------
// Stage: Loading the image
// --------------------------------------------------------------------
stopwatch.Start();
using (var bitmap = new Bitmap(imagePath))
{
stopwatch.Stop();
Console.WriteLine($"Loading time: {stopwatch.ElapsedMilliseconds} ms");
stopwatch.Reset();
// ----------------------------------------------------------------
// Stage: Preprocessing (configure reader and quality settings)
// ----------------------------------------------------------------
stopwatch.Start();
using (var reader = new BarCodeReader(bitmap, DecodeType.AllSupportedTypes))
{
// Example preprocessing: set high performance quality preset
reader.QualitySettings = QualitySettings.HighPerformance;
stopwatch.Stop();
Console.WriteLine($"Preprocessing time: {stopwatch.ElapsedMilliseconds} ms");
stopwatch.Reset();
// ----------------------------------------------------------------
// Stage: Detection (read barcodes)
// ----------------------------------------------------------------
stopwatch.Start();
var results = reader.ReadBarCodes();
stopwatch.Stop();
Console.WriteLine($"Detection time: {stopwatch.ElapsedMilliseconds} ms");
stopwatch.Reset();
// ----------------------------------------------------------------
// Stage: Decoding (extract code text and other info)
// ----------------------------------------------------------------
stopwatch.Start();
foreach (var result in results)
{
Console.WriteLine($"Detected Type: {result.CodeTypeName}");
Console.WriteLine($"Code Text: {result.CodeText}");
Console.WriteLine($"Confidence: {result.Confidence}");
Console.WriteLine($"Reading Quality: {result.ReadingQuality}");
}
stopwatch.Stop();
Console.WriteLine($"Decoding time: {stopwatch.ElapsedMilliseconds} ms");
stopwatch.Reset();
}
}
// --------------------------------------------------------------------
// Clean up temporary image file
// --------------------------------------------------------------------
try
{
File.Delete(imagePath);
}
catch
{
// Ignore any errors during cleanup
}
}
}