Imperfect Barcodes and Image Correction
IronBarcode offers many image pre-processing filters to choose from that are easily applied within BarcodeReaderOptions
. Select the filters that may improve reading of your image such as Sharpen, Binary Threshold, and Contrast. Please keep in mind that the order in which you choose them is the order that they are applied.
There is the option of saving the image data of the intermediate images with each filter applied. This can be toggled with the SaveAtEachIteration
property of ImageFilterCollection
.
using IronBarCode; // Import IronBarcode library
public class BarcodeProcessor
{
public static void Main()
{
// Create a BarcodeReaderOptions instance
BarcodeReaderOptions options = new BarcodeReaderOptions();
// Add filters to the options
options.Filters.Add(new ImageFilter { FilterType = ImageFilterType.Sharpen });
options.Filters.Add(new ImageFilter { FilterType = ImageFilterType.BinaryThreshold });
options.Filters.Add(new ImageFilter { FilterType = ImageFilterType.Contrast });
// Enable saving of intermediate images for each filter applied
options.Filters.SaveAtEachIteration = true;
// Read a barcode from an image file using the options
var result = BarcodeReader.ReadBarcodesFromFile("path/to/your/barcode/image.jpg", options);
// Display the barcode data
foreach (var barcode in result)
{
Console.WriteLine($"Type: {barcode.BarcodeType} - Value: {barcode.Text}");
}
}
}
using IronBarCode; // Import IronBarcode library
public class BarcodeProcessor
{
public static void Main()
{
// Create a BarcodeReaderOptions instance
BarcodeReaderOptions options = new BarcodeReaderOptions();
// Add filters to the options
options.Filters.Add(new ImageFilter { FilterType = ImageFilterType.Sharpen });
options.Filters.Add(new ImageFilter { FilterType = ImageFilterType.BinaryThreshold });
options.Filters.Add(new ImageFilter { FilterType = ImageFilterType.Contrast });
// Enable saving of intermediate images for each filter applied
options.Filters.SaveAtEachIteration = true;
// Read a barcode from an image file using the options
var result = BarcodeReader.ReadBarcodesFromFile("path/to/your/barcode/image.jpg", options);
// Display the barcode data
foreach (var barcode in result)
{
Console.WriteLine($"Type: {barcode.BarcodeType} - Value: {barcode.Text}");
}
}
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
- In this C# example, we use the IronBarcode library to read a barcode from an image file.
- We create an instance of
BarcodeReaderOptions
and configure it with various image filters:Sharpen
,Binary Threshold
, andContrast
. - The filters are added in a specific order, indicating the sequence in which they should be applied.
- By setting
SaveAtEachIteration
totrue
, the library saves intermediate images after each filter application, which is useful for debugging and analysis. - Finally, we read the barcode from the image and print the barcode type and value to the console.