VintaSoft Barcode .NET SDK v10.0
In This Topic
    How to read barcodes from color image with poor quality?
    In This Topic

    There are 2 ways possible:


    Example: Here is an example that shows how to detect barcodes in a color image with difficult-to-locate threshold.
    Public Shared Sub TestScanWithIterationsCode128orDataMatrix(fileName As String)
            ' recognize one Code 128 or DataMatrix barcode from 400 to 600 threshold (10 iterations).
            ScanWithIterations(fileName, BarcodeType.Code128 Or BarcodeType.DataMatrix, 1, 10, 400, 600)
    End Sub
    
    Public Shared Sub ScanWithIterations(fileName As String, barcodes As BarcodeType, expectedBarcodes As Integer, iterationCount As Integer, minThreshold As Integer, maxThreshold As Integer)
            Using barcodeImage As Image = Image.FromFile(fileName)
                    ' create a BarcodeReader object
                    Using reader As New BarcodeReader()
                            ' set barcode reader settings
                            reader.Settings.ScanBarcodeTypes = barcodes
                            reader.Settings.ExpectedBarcodes = expectedBarcodes
                            reader.Settings.ThresholdMode = ThresholdMode.Iterations
                            reader.Settings.ThresholdIterations = iterationCount
                            reader.Settings.ThresholdMin = minThreshold
                            reader.Settings.ThresholdMax = maxThreshold
    
                            ' read barcodes
                            Dim barcodesInfo As IBarcodeInfo() = reader.ReadBarcodes(barcodeImage)
    
                            ' if barcodes are not detected
                            If barcodesInfo.Length = 0 Then
                                    Console.WriteLine("No barcodes found.")
                            Else
                                    ' if barcodes are detected
                                    ' get information about extracted barcodes
    
                                    For i As Integer = 0 To barcodesInfo.Length - 1
                                            Dim inf As IBarcodeInfo = barcodesInfo(i)
                                            Console.WriteLine(String.Format("[{0}] {1} (Threshold: {2})", inf.BarcodeType, inf.Value, inf.Threshold))
                                    Next
                            End If
                    End Using
            End Using
    End Sub
                  
    
    public static void TestScanWithIterationsCode128orDataMatrix(string fileName)
    {
        // recognize one Code 128 or DataMatrix barcode from 400 to 600 threshold (10 iterations).
        ScanWithIterations(fileName, BarcodeType.Code128 | BarcodeType.DataMatrix, 1, 10, 400, 600);
    }
    
    public static void ScanWithIterations(
        string fileName,
        BarcodeType barcodes,
        int expectedBarcodes,
        int iterationCount,
        int minThreshold,
        int maxThreshold)
    {
        using (Image barcodeImage = Image.FromFile(fileName))
        {
            // create a BarcodeReader object
            using (BarcodeReader reader = new BarcodeReader())
            {
                // set barcode reader settings
                reader.Settings.ScanBarcodeTypes = barcodes;
                reader.Settings.ExpectedBarcodes = expectedBarcodes;
                reader.Settings.ThresholdMode = ThresholdMode.Iterations;
                reader.Settings.ThresholdIterations = iterationCount;
                reader.Settings.ThresholdMin = minThreshold;
                reader.Settings.ThresholdMax = maxThreshold;
    
                // read barcodes
                IBarcodeInfo[] barcodesInfo = reader.ReadBarcodes(barcodeImage);
    
                // if barcodes are not detected
                if (barcodesInfo.Length == 0)
                {
                    Console.WriteLine("No barcodes found.");
                }
                // if barcodes are detected
                else
                {
                    // get information about extracted barcodes
    
                    for (int i = 0; i < barcodesInfo.Length; i++)
                    {
                        IBarcodeInfo inf = barcodesInfo[i];
                        Console.WriteLine(string.Format("[{0}] {1} (Threshold: {2})", inf.BarcodeType,
                                                        inf.Value, inf.Threshold));
                    }
                }
            }
        }
    }