Códigos de barras imperfectos y corrección de imágenes
using IronBarCode;
using IronSoftware.Drawing;
using System.Linq;
// Choose which filters are to be applied (in order)
// Set SaveAtEachIteration = true to save the intermediate image data after each filter is applied
var filtersToApply = new ImageFilterCollection(SaveAtEachIteration: true) {
new SharpenFilter(),
new InvertFilter(),
new ContrastFilter(),
new BrightnessFilter(),
new AdaptiveThresholdFilter(),
new BinaryThresholdFilter(),
new GaussianBlurFilter(),
new MedianBlurFilter(),
new BilateralFilter()
};
BarcodeReaderOptions myOptionsExample = new BarcodeReaderOptions()
{
// Set chosen filters in BarcodeReaderOptions
ImageFilters = filtersToApply,
Speed = ReadingSpeed.Balanced,
ExpectMultipleBarcodes = true,
};
// Read with the options applied
BarcodeResults results = BarcodeReader.Read("screenshot.png", myOptionsExample);
AnyBitmap[] filteredImages = results.FilterImages();
// Export intermediate image files to disk
for (int i = 0 ; i < filteredImages.Length ; i++)
filteredImages[i].SaveAs($"{i}_barcode.png");
// Or
results.ExportFilterImagesToDisk("filter-result.jpg");
Imports IronBarCode
Imports IronSoftware.Drawing
Imports System.Linq
' Choose which filters are to be applied (in order)
' Set SaveAtEachIteration = true to save the intermediate image data after each filter is applied
Private filtersToApply = New ImageFilterCollection(SaveAtEachIteration:= True) From {
New SharpenFilter(),
New InvertFilter(),
New ContrastFilter(),
New BrightnessFilter(),
New AdaptiveThresholdFilter(),
New BinaryThresholdFilter(),
New GaussianBlurFilter(),
New MedianBlurFilter(),
New BilateralFilter()
}
Private myOptionsExample As New BarcodeReaderOptions() With {
.ImageFilters = filtersToApply,
.Speed = ReadingSpeed.Balanced,
.ExpectMultipleBarcodes = True
}
' Read with the options applied
Private results As BarcodeResults = BarcodeReader.Read("screenshot.png", myOptionsExample)
Private filteredImages() As AnyBitmap = results.FilterImages()
' Export intermediate image files to disk
For i As Integer = 0 To filteredImages.Length - 1
filteredImages(i).SaveAs($"{i}_barcode.png")
Next i
' Or
results.ExportFilterImagesToDisk("filter-result.jpg")
Install-Package BarCode
Códigos de barras imperfectos y corrección de imágenes
IronBarcode ofrece muchos filtros de preprocesamiento de imágenes para elegir, que se aplican fácilmente dentro de BarcodeReaderOptions. Seleccione los filtros que pueden mejorar la lectura de su imagen, como Sharpen, Binary Threshold y Contrast. Por favor, tenga en cuenta que el orden en el que los elija es el orden en el que se aplican.
Existe la opción de guardar los datos de imagen de las imágenes intermedias con cada filtro aplicado. Esto se puede alternar con la propiedad SaveAtEachIteration de ImageFilterCollection.