不完美条形码和图像校正
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");
NuGet下载
PM > Install-Package BarCode
不完美条形码和图像校正

不完美条形码和图像校正

IronBarcode 提供了多种图像预处理滤镜可供选择,并可在 BarcodeReaderOptions 中轻松应用。 选择可能改善图像读取的滤镜,如 Sharpen、二值化阈值和 Contrast。 请记住,您选择它们的顺序就是应用的顺序。

可以选择保存应用每个过滤器的中间图像的数据。 这可以通过 ImageFilterCollection 的 CacheAtEachIteration 属性进行切换。

特色代码示例中的关键点:

  • 我们创建一个BarcodeReaderOptions实例,并使用各种图像过滤器进行配置:Sharpen, Binary Threshold, 和Contrast。
  • 过滤器按特定顺序添加,表示它们应该应用的顺序。
  • 通过将 cacheAtEachIteration 设置为 true,库在应用每个滤镜后保存中间图像,这对于调试和分析非常有用。
  • 最后,我们从图像中读取条形码,并将条形码类型和值打印到控制台。
了解更多关于IronBarcode图像校正的信息
在GitHub上查看

准备开始了吗?

NuGet 下载量 2,564,559版本:2026.11刚刚发布