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.
-
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 -
Set the height range that the returned result needs to meet, the value range is [0,0x7ffffffff] (in pixels);
-
Set the width range that the returned result needs to meet, the value range is [0,0x7ffffffff] (in pixels);
-
Set the length range that Bytes needs to meet in the returned result, the value range is [0,0x7ffffffff] (in bytes);
-
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)
}
}