不完善的條碼和圖像修正
IronBarcode 提供多種圖像預處理濾鏡可以選擇,這些可以輕鬆地在 BarcodeReaderOptions 中應用。 選擇可能增強圖像閱讀的過濾器,例如銳化、二元閾值和對比度。 請記住,您選擇它們的順序就是它們被應用的順序。
可以选择保存每个滤镜应用后的中间图像的数据。 這可以通過 ImageFilterCollection 的 SaveAtEachIteration 屬性來切換。
using IronBarCode;
using IronSoftware.Drawing;
// Choose which filters are to be applied (in order)
// Set cacheAtEachIteration = true to save the intermediate image data after each filter is applied
var filtersToApply = new ImageFilterCollection(cacheAtEachIteration: 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
' Choose which filters are to be applied (in order)
' Set cacheAtEachIteration = true to save the intermediate image data after each filter is applied
Private filtersToApply = New ImageFilterCollection(cacheAtEachIteration:= 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 屬性來切換。