How to Adjust Reading Speed
Accuracy is essential for scalability and reading large sets of barcodes, but how a barcode reader allocates its resources and how efficiently it is also must be considered. Depending on the input images and the image quality themselves, it is vital that developers decide on how a barcode reader should approach and read the images, such as whether to skip image preprocessing if the images are clear, or going with a more resource intensive option to improve the reading accuracy of the barcode reader.
IronBarCode provides you with the flexibility to choose the speed and accuracy of the barcode processing detail, allowing you to fine-tune and control every aspect of the process. You can make the decision based on the input images you have and the resources you want to allocate.
The article below would be a general guideline on the most optimal situation for deciding which reading speed to use. We'd use a sample set of QR codes to give brief examples of how changing the reading speed affects the results.
Get started with IronBarcode
Start using IronBarcode in your project today with a free trial.
How to Adjust Reading Speed
- Download the C# library to adjust reading speed
- Utilize the BarcodeReaderOptions class to set the reading speed
- Use the
Read
method to extract barcode values from various image formats - Print out the barcode values
- Evaluate the performance trade-off between different reading speeds
Reading Speed
Within IronBarCode, developers can set the ReadingSpeed
to four different options: Faster
,Balanced
, Detailed
, and ExtremeDetail
. We'll go through each of these options, and a sample set as a benchmark on how the ReadingSpeed
value affects the process's output. The sample set contains a mix of degraded barcode images and clearer images, heavily leaning towards severely degraded images to illustrate the functionality of the library.
We'll also use a popular .NET benchmark library to benchmark the times and memory usage, illustrating how each option compares to the others and identifying the ideal scenarios and situations for each reading speed option. We'll display the code for benchmarking with the library, and also a more straightforward way of deducing the amount of degraded barcode IronBarCode could read.
Faster Speed Option
The first value is Faster
. In general, setting the Speed
property to this value enables the fastest barcode reading with minimal resources, but it comes with a trade-off of reduced accuracy. The process would skip image preprocessing and is generally recommended if the image itself is already sharp and clear before being input into the process.
For this example, we set the Speed
property to ReadingSpeed.Faster
, imported the directory containing all the barcodes, and printed out any barcodes found, along with their value and type and the number of barcodes found from each image.
:path=/static-assets/barcode/content-code-examples/how-to/reading-speed-option-faster.cs
using IronBarCode;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
var optionsFaster = new BarcodeReaderOptions
{
Speed = ReadingSpeed.Faster
};
// Directory containing PDF files
string folderPath = @"YOUR_FILE_PATH";
// Get all PDF files in the directory
var pdfFiles = Directory.GetFiles(folderPath, "*.jpg");
int countFaster = 0;
var stopwatch = Stopwatch.StartNew();
foreach (var file in pdfFiles)
{
// Read the barcode
var results = BarcodeReader.Read(file, optionsFaster);
if (results.Any())
{
Console.WriteLine($"Barcode(s) found in: {Path.GetFileName(file)}");
foreach (var result in results)
{
Console.WriteLine($" Value: {result.Value}, Type: {result.BarcodeType}");
countFaster++;
}
}
else
{
Console.WriteLine($"No barcode found in: {Path.GetFileName(file)}");
}
}
stopwatch.Stop();
// Print number of images the barcode reader could decode
Console.WriteLine($"Faster could read = {countFaster} out of {pdfFiles.Length} in {stopwatch.ElapsedMilliseconds}ms");
IRON VB CONVERTER ERROR developers@ironsoftware.com
The Faster
detected 146 barcode results out of 430 in 25 seconds. This option is quick and can decode around 33.95% of the barcode. Although fast, this method is generally only suited for images with pristine conditions.
Balanced Speed Option
The Balanced
value balances accuracy and read performance. When applying this setting, IronBarcode applies light processing to the image to clarify the barcode area, make it stand out for the barcode reader to detect, and make it easier to read. In general, this is the recommended setting for most modern-day images, as the light processing should suffice to produce accurate results.
Let's use the same images and showcase how the Balanced
value affects the output results.
:path=/static-assets/barcode/content-code-examples/how-to/reading-speed-option-balanced.cs
using IronBarCode;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
var optionsFaster = new BarcodeReaderOptions
{
Speed = ReadingSpeed.Balanced
};
// Directory containing PDF files
string folderPath = @"YOUR_FILE_PATH";
// Get all PDF files in the directory
var pdfFiles = Directory.GetFiles(folderPath, "*.jpg");
int countFaster = 0;
var stopwatch = Stopwatch.StartNew();
foreach (var file in pdfFiles)
{
// Read the barcode
var results = BarcodeReader.Read(file, optionsFaster);
if (results.Any())
{
Console.WriteLine($"Barcode(s) found in: {Path.GetFileName(file)}");
foreach (var result in results)
{
Console.WriteLine($" Value: {result.Value}, Type: {result.BarcodeType}");
countFaster++;
}
}
else
{
Console.WriteLine($"No barcode found in: {Path.GetFileName(file)}");
}
}
stopwatch.Stop();
// Print number of images the barcode reader could decode
Console.WriteLine($"Balanced could read = {countFaster} out of {pdfFiles.Length} in {stopwatch.ElapsedMilliseconds}ms");
IRON VB CONVERTER ERROR developers@ironsoftware.com
The Balanced
detected 237 barcode results out of 430 in 43 seconds. It provides a 55.11% accuracy improvement over the Faster
option, with only a slight increase in time. The Balanced
option maintains an efficient balance between memory and speed, making it the ideal choice for most situations, and it's the recommended starting point.
Detailed Speed Option
In scenarios where the images are heavily blurred or distorted and situations where the Balanced
option is unable to clearly detect and produce results, developers may opt to use the Detailed
property to apply medium pre-processing to the images to clarify the barcode area even further and clear up more digital noise for the barcode reader to detect the barcode.
Let's apply the Detailed
setting to the Speed
property this time and see if it affects the overall output of the images.
:path=/static-assets/barcode/content-code-examples/how-to/reading-speed-option-detailed.cs
using IronBarCode;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
var optionsFaster = new BarcodeReaderOptions
{
Speed = ReadingSpeed.Detailed
};
// Directory containing PDF files
string folderPath = @"YOUR_FILE_PATH";
// Get all PDF files in the directory
var pdfFiles = Directory.GetFiles(folderPath, "*.jpg");
int countFaster = 0;
var stopwatch = Stopwatch.StartNew();
foreach (var file in pdfFiles)
{
// Read the barcode
var results = BarcodeReader.Read(file, optionsFaster);
if (results.Any())
{
Console.WriteLine($"Barcode(s) found in: {Path.GetFileName(file)}");
foreach (var result in results)
{
Console.WriteLine($" Value: {result.Value}, Type: {result.BarcodeType}");
countFaster++;
}
}
else
{
Console.WriteLine($"No barcode found in: {Path.GetFileName(file)}");
}
}
stopwatch.Stop();
// Print number of images the barcode reader could decode
Console.WriteLine($"Detailed could read = {countFaster} out of {pdfFiles.Length} in {stopwatch.ElapsedMilliseconds}ms");
IRON VB CONVERTER ERROR developers@ironsoftware.com
The Detailed
detected 237 barcode results out of 430 in 5 minutes and 30 seconds. Its success rate of 55.11% in a severely degraded barcode dataset is a testament to its accuracy. However, the trade-off is significant, as the process time is increased by a large margin. Therefore, it is crucial that this option be used exclusively for degraded barcode images.
ExtremeDetail Speed Option
The final setting of the Speed
property is ExtremeDetail
, which applies heavy processing to the barcode image so that the reader can read it, generally reducing IronBarcode's reading performance. This option is ideal for scanning large amounts of barcodes within one input file that is also unclear or blurry in batches. The operation is CPU-intensive and should be used as a last resort when the other options aren't producing the desired results.
Let's apply the ExtremeDetail
setting to the Speed
property to see if it affects the outcome.
:path=/static-assets/barcode/content-code-examples/how-to/reading-speed-option-extreme-detailed.cs
using IronBarCode;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
var optionsFaster = new BarcodeReaderOptions
{
Speed = ReadingSpeed.ExtremeDetail
};
// Directory containing PDF files
string folderPath = @"YOUR_FILE_PATH";
// Get all PDF files in the directory
var pdfFiles = Directory.GetFiles(folderPath, "*.jpg");
int countFaster = 0;
var stopwatch = Stopwatch.StartNew();
foreach (var file in pdfFiles)
{
// Read the barcode
var results = BarcodeReader.Read(file, optionsFaster);
if (results.Any())
{
Console.WriteLine($"Barcode(s) found in: {Path.GetFileName(file)}");
foreach (var result in results)
{
Console.WriteLine($" Value: {result.Value}, Type: {result.BarcodeType}");
countFaster++;
}
}
else
{
Console.WriteLine($"No barcode found in: {Path.GetFileName(file)}");
}
}
stopwatch.Stop();
// Print number of images the barcode reader could decode
Console.WriteLine($"ExtremeDetail could read = {countFaster} out of {pdfFiles.Length} in {stopwatch.ElapsedMilliseconds}ms");
IRON VB CONVERTER ERROR developers@ironsoftware.com
The ExtremeDetail
option, with its ability to identify 313 out of 430 barcode images, takes an average of 10 minutes per run. It's a powerful tool, suitable only as a last resort for severely degraded options due to its high resource consumption. It can find the most barcodes with an impressive 72.79% accuracy in a dataset of severely degraded barcodes, but it's still recommended to perform pre-processing on them before passing them through the barcode finder.
Summary Table
Mode | Barcodes Found | Mean Time | Time per File | GC Pressure | Accuracy Gain |
---|---|---|---|---|---|
Faster | 147/430 (33.95%) | 25 s | 0.058 s | High (Gen2: 177K) | Baseline |
Balanced | 237/430 (55.11%) | 43 s | 0.1 s | High (Gen2: 151K) | +62.32% vs Faster |
Detailed | 237/430 (55.11%) | 5.50 min | 0.767 s | Very High (Gen2: 297K) | +0% vs Balanced |
ExtremeDetail | 313/430 (72.79%) | 10.14 min | 1.414 s | Extreme (Gen2: 4.74M) | +32.08% vs Detailed |
Choosing the Right Speed
After the brief comparison above, and the different scenarios mentioned above, developers should, in general, try from the lowest setting Faster
and slowly progress through Balanced
, Detailed
, ExtremeDetail
to see if there are any significant discrepancies between the output. Regarding scalability with using IronBarCode, in most scenarios, Balanced
would be more than often to go through everything, and developers should only use the Detailed
, ExtremeDetail
, depending on how heavily distorted the images are. Furthermore, although both of these options applies medium and heavy processing to images when using Detailed
and ExtremeDetail
, there are scenarios where it's more worthwhile to split the process into two and apply image filters manually before placing it into the barcode reader rather than using a single process. For more information on processing images for the barcode reader, please refer to this here. As a general recap, here's a brief table and summary of the situations where each varying speed is appropriate.
Decision Chart
