How to Filter and Sort 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 text string. The SDK provides the following parameters to help you filter the barcode results by barcode format, confidence, etc and order the results by confidence, position or format. These parameters can work both individually and in combination.
- BarcodeFormatIds
- BarcodeAngleRangeArray
- BarcodeWidthRangeArray
- BarcodeHeightRangeArray
- MinRatioOfBarcodeZoneWidthToHeight
- BarcodeTextLengthRangeArray
- BarcodeTextRegExPattern
- MinResultConfidence
- ModuleSizeRangeArray
- TextResultOrderModes
Sample Code
Below is an example illustrating how to filter out QR Code results with confidence higher than 50 and then order the results by position.
-
update parameters in your JSON template
{ "CaptureVisionTemplates": [ { "Name" : "CV_0", "ImageROIProcessingNameArray": ["TA_0" ] } ], "TargetROIDefOptions" : [ { "Name" : "TA_0", "TaskSettingNameArray": [ "BR_0" ] } ], "BarcodeReaderTaskSettingOptions": [ { "Name" : "BR_0", "BarcodeFormatIds" : ["BF_QR_CODE"], "TextResultOrderModes" : [ { "Mode" : "TROM_POSITION" } ], "BarcodeFormatSpecificationNameArray": "FS_0" } ], "BarcodeFormatSpecificationOptions": [ { "Name" : "FS_0", "MinResultConfidence" : 50 } ] }
-
apply settings by calling method
InitSettingsFromFile
- JavaScript
- C++
- Android
- Objective-C
- Swift
// `router` is an instance of `CaptureVisionRouter`. // In the JS edition, the method name we use for initialization is different. router.initSettings("PATH-TO-YOUR-SETTING")
char szErrorMsg[256] = {0}; CCaptureVisionRouter* cvr = new CCaptureVisionRouter; cvr->InitSettingsFromFile("PATH-TO-YOUR-SETTING-FILE", szErrorMsg, 256); // more process here
try { // `cvr` is an instance of `CaptureVisionRouter`. cvr.initSettingsFromFile("PATH-TO-YOUR-SETTING-FILE"); } catch (CaptureVisionRouterException e) { e.printStackTrace(); }
NSError *error; // `cvr` is an instance of `DSCaptureVisionRouter`. [self.cvr initSettingsFromFile:@"PATH-TO-YOUR-SETTING-FILE" error:&error];
do{ //`cvr` is an instance of `CaptureVisionRouter`. try cvr.initSettingsFromFile("PATH-TO-YOUR-SETTING-FILE") }catch{ // Add code to do when error occurs. }