Dev Center
Table of contents

Thanks for downloading Dynamsoft Barcode Reader Package!

Your download will start shortly. If your download does not begin, click here to retry.

How to Filter and Sort Barcode Results

The DBR decoding result contains a variety of information, and we provide flexible parameters to filter and sort the results you care about. With each heading, we will explore a new parameter that you could use to filter and sort the results.

Angle, width, height and text length of the decoded result

You can set the angle, width, height, and text length requirements that the decoded result should meet through parameters, and the results that do not meet the setting requirements will be filtered out.

  • BarcodeAngleRangeArray

    Set the angle range that the returned result needs to meet, the value range is [0,360] (in degrees).

    The definition of Angle in DBR is: the angle between the vector at the lower left corner of the barcode as the starting point and the end point at the lower right corner of the barcode and the X axis, clockwise is positive. Let us take actual pictures to illustrate the angle

    1D Angle Example

    QR Angle Example

    DataMatrix Angle Example

    Aztec Angle Example

    Maxicode Angle Example

  • BarcodeHeightRangeArray

    Set the height range that the returned result needs to meet, the value range is [0,0x7ffffffff] (in pixels);

  • BarcodeWidthRangeArray

    Set the width range that the returned result needs to meet, the value range is [0,0x7ffffffff] (in pixels);

  • BarcodeBytesLengthRangeArray

    Set the length range that Bytes needs to meet in the returned result, the value range is [0,0x7ffffffff] (in bytes);

  • BarcodeTextLengthRangeArray

    Set the length range of the Text in the returned result, the value range is [0,0x7ffffffff] (in the number of characters).

Regular Expression

You can use BarcodeTextRegExPattern to specify the regular expression requirements that must be met when DBR returns the result text. The default value is empty which means there is no limitation.

For example, if we set BarcodeTextRegExPattern as “[0-9]\d{4,11}”, then the result text should be 5 to 12 digits. If the result is 123456 which matches the expression, it will be returned. If it is 123 which has only 3 digits or a123456 which has a letter in it, they don ‘t match the expression and will not be returned.

For more info, check out About Regular Expression

Confidence Score

The decoding results of DBR will have a confidence score, and the result with too low of a score may be wrong. You can use MinResultConfidence to specify the minimum score that DBR needs to meet to return results. The default value is 30, which is the recommended value for 1D barcodes.

Please refer to the following sample program for how to obtain the confidence of the returned result

CBarcodeReader* reader = new CBarcodeReader();     
reader->InitLicense("LICENSE-KEY");     
reader->DecodeFile("FILE-PATH", "");             
TextResultArray* pResult = NULL;     
reader->GetAllTextResults(&pResult);
int iCount = pResult->resultsCount;  
for(int j = 0; j < iCount; j++)
{  
    TextResult* pBarcode = pResults->results[j];  
    LocalizationResult* pLocRes = pBarcode->localizationResult;  
    printf("confidence:%d\n",pLocRes->confidence);
}  
dynamsoft::dbr::CBarcodeReader::FreeTextResults(&pResult);     
delete reader;  

Coordinate format of result position

For the position coordinates of the decoding result, the parameter ResultCoordinateType can be used to specify whether the coordinates are in pixels or percentage.

Name Notes
RCT_PERCENTAGE The x of the returned coordinate point is the percentage of the image width, and y is the percentage of the image height
RCT_PIXEL The default. The coordinate point of the returned result is the pixel coordinate point

Ordering

TextResultOrderModes is used to sort the decoding results.

Name Notes
TROM_CONFIDENCE Sort in descending order according to the score of the returned result
TROM_POSITION According to the coordinate position of the returned result, sort from top to bottom and from left to right
TROM_FORMAT Sort letters and numbers according to the code type string of the returned result
TROM_SKIP Skip the sorting

Clarity

ReturnBarcodeZoneClarity specifies whether to return the clarity of the barcode region detected on the image. It can be set to 0 or 1. The default value is 0 which means no clarity is returned. To return the clarity, set it to 1.

DBR uses the gray gradient changes of adjacent pixels to measure the clarity of the code area. The value range of BarcodeZoneClarity is 0~100, the larger the number, the clearer it is.

Please refer to the following sample program on how to obtain

CBarcodeReader* reader = new CBarcodeReader();     
reader->InitLicense("LICENSE-KEY");    
PublicRuntimeSettings* runtimeSettings = new PublicRuntimeSettings();     
reader->GetRuntimeSettings(runtimeSettings); 
runtimeSettings->returnBarcodeZoneClarity = 1;
char sError[512];  
reader->UpdateRuntimeSettings(runtimeSettings, sError, 512);
reader->DecodeFile("FILE-PATH", "");
TextResultArray* pResult = NULL;     
reader->GetAllTextResults(&pResult); 
int iCount = pResult->resultsCount;  
for(int j = 0; j < iCount; j++)
{  
    TextResult* pBarcode = pResults->results[j];  
    ExtendResult* pExResult = pBarcode->result[0];  
    printf("clarity:%d\n", pExResult->clarity);
}  
dynamsoft::dbr::CBarcodeReader::FreeTextResults(&pResult);
delete runtimeSettings;
delete reader;

Sample template

{
    "Version": "3.0", 
    "ImageParameter": {
        "FormatSpecificationNameArray": [
            "FP_1"
        ], 
        "TextResultOrderModes": [
            {
                "Mode": "TROM_CONFIDENCE"
            }
        ],  //Order the results by confidence score
        "ResultCoordinateType": "RCT_PIXEL", //Return the coordinates in pixels
        "ReturnBarcodeZoneClarity": 0        //Do not return the clarity
    }, 
    "FormatSpecification": {
        "Name": " FP_1", 
        "BarcodeAngleRangeArray": null,    //Do not limit the angle
        "BarcodeBytesLengthRangeArray": [
            {
                "MaxValue": 20, 
                "MinValue": 0
            }
        ], // Limit the number of the resulting bytes to 0~20
        "BarcodeFormatIds": [
            "BF_CODE_39"
        ], 
        "BarcodeTextRegExPattern": "[0-9]{4}", //Limit the result to be a 4-digit string
        "BarcodeHeightRangeArray": [
            {
                "MaxValue": 500, 
                "MinValue": 0
            }
        ], // Limit the resulting barcode height to 0~500 px
        "BarcodeWidthRangeArray": [
            {
                "MaxValue": 200, 
                "MinValue": 100
            }
        ],//Limit the resulting barcode width to 100~200 px
        "MinResultConfidence": 30 // Limit the results by confidence score (>30)
    }
}

This page is compatible for:

Version 7.5.0

Is this page helpful?

YesYes NoNo

In this article:

latest version

  • Latest version
  • Version 10.x
    • Version 10.2.0
    • Version 10.0.21
    • Version 10.0.20
    • Version 10.0.10
    • Version 10.0.0
  • Version 9.x
    • Version 9.6.40
    • Version 9.6.33
    • Version 9.6.32
    • Version 9.6.31
    • Version 9.6.30
    • Version 9.6.20
    • Version 9.6.10
    • Version 9.6.0
    • Version 9.4.0
    • Version 9.2.0
    • Version 9.0.0
  • Version 8.x
    • Version 8.8.0
    • Version 8.6.0
    • Version 8.4.0
    • Version 8.2.0
    • Version 8.1.2
    • Version 8.1.0
    • Version 8.0.0
  • Version 7.x
    • Version 7.6.0
    • Version 7.5.0
Change +