VintaSoft Barcode .NET SDK v10.0
In This Topic
    How SDK reads barcodes from color image
    In This Topic

    Color, palette or gray image (the color image) is converted to black-white image before barcode reading.

    Here is a list of steps performed by the image converting algorithm:

    1. The sum of color components (T) is calculated for each pixel by the following formula: T = R + G + B
    2. Pixel color is changed to black color if T is less than Threshold value
    3. Pixel color is changed to white color if T is more than or equal Threshold value

    Automatic Recognition Mode

    This mode allows to make barcode recognition process as simple as possible. You can set only Expected barcodes and Scan Interval values up.

    Automatic recognition mode is preferable in case you read barcodes from images which threshold is hard to locate and when barcodes are damaged as the original image is of poor quality (contain noise, dimensional distortion etc). In certain cases this mode decrease the barcode recognition speed as the additional image manipulation, which is included in Automatic recognition algorithm, takes some extra time.

    Threshold Fine-Tuning Modes

    Threshold can be:

    You should use ThresholdMode.Automatic mode if you read barcodes from many different images, e.g. images are acquired from different devices and in different light conditions.
    You should use ThresholdMode.Manual mode if you read barcodes from similar images, e.g. you use the best threshold which gives you the best recognition result for your barcode collection.
    You should use ThresholdMode.Iterations mode if you read barcodes from images where the appropriate threshold value is difficult-to-locate. By setting up the Max and Min threshold values and count of iteration steps you can get the barcode read from a rather large collection of different images.


    Example: Here is an example that shows how to detect barcodes in a color image with difficult-to-locate threshold.
    Public Shared Function ReadBarcode(filename As String) As String
            ' create a BarcodeReader object
            Using barcodeReader As New BarcodeReader()
                    ' specify that only Code 39, EAN, PDF417 and Micro PDF417 barcodes must be searched
                    barcodeReader.Settings.ScanBarcodeTypes = BarcodeType.Code39 Or BarcodeType.EAN8 Or BarcodeType.EAN13 Or BarcodeType.PDF417 Or BarcodeType.MicroPDF417
                    ' specify that only horizontal barcodes must be searched
                    barcodeReader.Settings.ScanDirection = ScanDirection.LeftToRight Or ScanDirection.RightToLeft
                    ' specify that only image pixels of every 5 row and column must analyzed for barcode searching
                    barcodeReader.Settings.ScanInterval = 5
                    ' specify that barcode searching must be stopped when 10 barcodes are searched
                    barcodeReader.Settings.ExpectedBarcodes = 10
    
                    ' specify that iterations mode must be used for barcode searching
                    barcodeReader.Settings.ThresholdMode = ThresholdMode.Iterations
                    ' specify minimum threshold value used for barcode searching
                    barcodeReader.Settings.ThresholdIterations = 15
                    ' specify maximum threshold value used for barcode searching
                    barcodeReader.Settings.ThresholdMin = 400
                    ' specify the number of iterations between minimum and maximum threshold values
                    barcodeReader.Settings.ThresholdMax = 600
    
                    ' extract barcodes
                    Dim infos As IBarcodeInfo() = barcodeReader.ReadBarcodes(filename)
    
                    ' if barcodes are not detected
                    If infos Is Nothing OrElse infos.Length = 0 Then
                            Return "Codes are not detected."
                    End If
    
                    ' get information about extracted barcodes
                    Dim resultString As New StringBuilder()
                    resultString.AppendLine(String.Format("Codes detected [{0}]:", infos.Length))
                    For i As Integer = 0 To infos.Length - 1
                            resultString.AppendLine(infos(i).ToString())
                    Next
                    Return resultString.ToString()
            End Using
    End Function
                  
    
    public static string ReadBarcode(string filename)
    {
        // create a BarcodeReader object
        using (BarcodeReader barcodeReader = new BarcodeReader())
        {
            // specify that only Code 39, EAN, PDF417 and Micro PDF417 barcodes must be searched
            barcodeReader.Settings.ScanBarcodeTypes =
                BarcodeType.Code39 |
                BarcodeType.EAN8 |
                BarcodeType.EAN13 |
                BarcodeType.PDF417 |
                BarcodeType.MicroPDF417;
            // specify that only horizontal barcodes must be searched
            barcodeReader.Settings.ScanDirection =
                ScanDirection.LeftToRight |
                ScanDirection.RightToLeft;
            // specify that only image pixels of every 5 row and column must analyzed for barcode searching
            barcodeReader.Settings.ScanInterval = 5;
            // specify that barcode searching must be stopped when 10 barcodes are searched
            barcodeReader.Settings.ExpectedBarcodes = 10;
    
            // specify that iterations mode must be used for barcode searching
            barcodeReader.Settings.ThresholdMode = ThresholdMode.Iterations;
            // specify minimum threshold value used for barcode searching
            barcodeReader.Settings.ThresholdIterations = 15;
            // specify maximum threshold value used for barcode searching
            barcodeReader.Settings.ThresholdMin = 400;
            // specify the number of iterations between minimum and maximum threshold values
            barcodeReader.Settings.ThresholdMax = 600;
    
            // extract barcodes
            IBarcodeInfo[] infos = barcodeReader.ReadBarcodes(filename);
    
            // if barcodes are not detected
            if (infos == null || infos.Length == 0)
                return "Codes are not detected.";
    
            // get information about extracted barcodes
            StringBuilder resultString = new StringBuilder();
            resultString.AppendLine(string.Format("Codes detected [{0}]:", infos.Length));
            for (int i = 0; i < infos.Length; i++)
                resultString.AppendLine(infos[i].ToString());
            return resultString.ToString();
        }
    }