How to filter out unwanted barcode results

Dynamsoft Barcode Reader SDK is able to read multiple barcodes at once and return results of all the decoded barcodes. However, you may not want all the results. For example, you may need only the results of a specific barcode format, or you may need only the barcodes with a certain length (number of barcode data bytes). The SDK provides settings to help you filter out the barcode results by barcode formats, confidence and text length.

Filtering out the barcode results based on the barcode format is shown in Specify Which Barcode Type to Read.

The following code shows how to filter out the unwanted barcode results based on the barcode confidence and barcode text length.

Filtering using barcode confidence

The barcode confidence means the probablity that the barcode result is reconigzed correctly. You can use minResultConfidence to filter out the results with low confidence.

C
C++
Java
void *hBarcode = NULL;
char sError[512];
TextResultArray* pResult = NULL;
PublicRuntimeSettings runtimeSettings;
hBarcode = DBR_CreateInstance();
// Initialize license prior to any decoding
//Replace "<Put your license key here>" with your own license
DBR_InitLicense(hBarcode, "<Put your license key here>");

// Obtain the barcode results with confidence above 35
DBR_GetRuntimeSettings(hBarcode, &runtimeSettings);
runtimeSettings.minResultConfidence = 35;  //It is recommended to set the confidence above 35
DBR_UpdateRuntimeSettings(hBarcode, &runtimeSettings,sError,512);

// Replace "<Put the path of your file here>" with your own file path
DBR_DecodeFile(hBarcode,"<Put your file path here>","");
DBR_GetAllTextResults(hBarcode, &pResult);
DBR_FreeTextResults(&pResult);
DBR_DestroyInstance(hBarcode);
char sError[512];
TextResultArray* paryResult = NULL;
PublicRuntimeSettings* runtimeSettings = new PublicRuntimeSettings();
CBarcodeReader* reader = new CBarcodeReader();
// Initialize license prior to any decoding
// Replace "<Put your license key here>" with your own license
reader->InitLicense("<Put your license key here>");
    
// Obtain the barcode results with confidence above 35
reader->GetRuntimeSettings(runtimeSettings);
runtimeSettings->minResultConfidence = 35;    //It is recommended to set the confidence above 35
reader->UpdateRuntimeSettings(runtimeSettings, sError, 512);

// Replace "<Put your file path here>" with your own file path
reader->DecodeFile("<Put your file path here>", "");
// If succeeds
reader->GetAllTextResults(&paryResult);
CBarcodeReader::FreeTextResults(&paryResult);
delete runtimeSettings;
delete reader;
BarcodeReader dbr = new BarcodeReader();
PublicRuntimeSettings rts = dbr.getRuntimeSettings();

rts.minResultConfidence = 35;//It is recommended to set the confidence above 35
dbr.updateRuntimeSettings(rts);

// Initialize license prior to any decoding
//Replace "<Put your license key here>" with your own license
dbr.initLicense("<Put your license key here>");

//Replace "<Put the path of your file here>" with your own file path
TextResult[] result = dbr.decodeFile("<Put your file path here>","");

Filtering using barcode result length

The barcode length is calculated in bytes. The length of the barcode text does not necessarily mean the actual length of the barcode bytes. You can use minBarcodeTextLength to filter out some invalid or unwanted results.

C
C++
Java
void *hBarcode = NULL;
char sError[512];
TextResultArray* pResult = NULL;
PublicRuntimeSettings runtimeSettings;
hBarcode = DBR_CreateInstance();
// Initialize license prior to any decoding
// Replace "<Put your license key here>" with your own license
DBR_InitLicense(hBarcode, "<Put your license key here>");

// Decode the barcodes with its length longer than 10 bytes
DBR_GetRuntimeSettings(hBarcode, &runtimeSettings);
runtimeSettings.minBarcodeTextLength = 10; //The length is calculated in bytes
DBR_UpdateRuntimeSettings(hBarcode, &runtimeSettings,sError,512);

// Replace "<Put your file path here>" with your own file path
DBR_DecodeFile(hBarcode,"put your file path here","");
DBR_GetAllTextResults(hBarcode, &pResult);
DBR_FreeTextResults(&pResult);
DBR_DestroyInstance(hBarcode);
char sError[512];
TextResultArray* paryResult = NULL;
PublicRuntimeSettings* runtimeSettings = new PublicRuntimeSettings();
CBarcodeReader* reader = new CBarcodeReader();
// Initialize license prior to any decoding
// Replace "Put your license key here" with your own license
reader->InitLicense("Put your license key here");
    
// Decode the barcodes with its length longer than 10 bytes
reader->GetRuntimeSettings(runtimeSettings);
runtimeSettings->minBarcodeTextLength = 10;
reader->UpdateRuntimeSettings(runtimeSettings, sError, 512);

// Replace "Put the path of your file here" with your own file path
reader->DecodeFile("Put your file path here", "");
// If succeeds
reader->GetAllTextResults(&paryResult);
CBarcodeReader::FreeTextResults(&paryResult);
delete runtimeSettings;
delete reader;
BarcodeReader dbr = new BarcodeReader();
PublicRuntimeSettings rts = dbr.getRuntimeSettings();

rts.minBarcodeTextLength = 10; //The length is calculated in bytes
dbr.updateRuntimeSettings(rts);

// Initialize license prior to any decoding
//Replace "<Put your license key here>" with your own license
dbr.initLicense("<Put your license key here>");

//Replace "<Put the path of your file here>" with your own file path
TextResult[] result = dbr.decodeFile("<Put your file path here>","");

results matching ""

    No results matching ""