不完美的条形码和图像校正
IronBarcode 提供许多图像预处理过滤器供您选择,这些过滤器可在 BarcodeReaderOptions
中轻松应用。 选择可提高图像阅读效果的滤镜,如锐化、二进制阈值和对比度。 请记住,您选择的顺序就是它们的应用顺序。
可以选择保存应用了每个过滤器的中间图像的图像数据。 这可以通过 ImageFilterCollection
的 SaveAtEachIteration
属性进行切换。
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
IronBarcode 提供许多图像预处理过滤器供您选择,这些过滤器可在 BarcodeReaderOptions
中轻松应用。 选择可提高图像阅读效果的滤镜,如锐化、二进制阈值和对比度。 请记住,您选择的顺序就是它们的应用顺序。
可以选择保存应用了每个过滤器的中间图像的图像数据。 这可以通过 ImageFilterCollection
的 SaveAtEachIteration
属性进行切换。