Dev Center
Table of contents

Use SimplifiedCaptureVisionSettings or JSON Template

Dynamsoft Barcode Reader (DBR) provides two ways for configuring the parameters: via SimplifiedCaptureVisionSettings or via a JSON Template.

  • SimplifiedCaptureVisionSettings

    SimplifiedCaptureVisionSettings is an object that manages various parameters during runtime. If you need to dynamically configure the reading process, use SimplifiedCaptureVisionSettings.

    However, bear in mind that SimplifiedCaptureVisionSettings doesn’t provide all the available configuration options of the SDK.

  • JSON Template

    With a JSON template, you can make use of all the configuration options that DBR offers.

    However, compared with SimplifiedCaptureVisionSettings, a template is static and can’t be changed. If you need to use different settings for different scenarios, you can define a few templates and specify the proper one to use at runtime.

SimplifiedCaptureVisionSettings

SimplifiedCaptureVisionSettings is an object that manages various runtime settings of the DBR SDK which dictate the performance of the barcode reader.

Basic steps:

  1. Get the current value of the SimplifiedCaptureVisionSettings object
  2. Change one or more settings
  3. Update the SimplifiedCaptureVisionSettings object with the changed copy for the changes to take effect

The following code snippet demonstrates how to specify barcode formats via SimplifiedCaptureVisionSettings.

  • JavaScript
  • C++
  • Android
  • Objective-C
  • Swift
// Obtain current runtime settings of `router` instance. Here we use `ReadSingleBarcode` as an example. You can change it to your own template name or the name of other preset template.
let settings = await router.getSimplifiedSettings("ReadSingleBarcode");
// Specify the barcode formats by enumeration values.
// Use "|" to enable multiple barcode formats at one time.
settings.barcodeSettings.barcodeFormatIds = Dynamsoft.DBR.EnumBarcodeFormat.BF_QR_CODE | Dynamsoft.DBR.EnumBarcodeFormat.BF_QR_CODE;
// Update the settings to a specific template.
await router.updateSettings("ReadSingleBarcode", settings);
char szErrorMsg[256] = {0};
// Obtain current runtime settings of `CCaptureVisionRouter` instance.
CCaptureVisionRouter* cvr = new CCaptureVisionRouter;
SimplifiedCaptureVisionSettings settings;
cvr->GetSimplifiedSettings(CPresetTemplate::PT_READ_BARCODES, &settings);
// Specify the barcode formats by enumeration values.
// Use "|" to enable multiple barcode formats at one time.
settings.barcodeSettings.barcodeFormatIds = BF_QR_CODE | BF_ONED;
// Update the settings.
cvr->UpdateSettings(CPresetTemplate::PT_READ_BARCODES, &settings, szErrorMsg, 256);
try {
   // `cvr` is an instance of `CaptureVisionRouter`.
   SimplifiedCaptureVisionSettings captureVisionSettings = cvr.getSimplifiedSettings(EnumPresetTemplate.PT_READ_BARCODES);
   captureVisionSettings.barcodeSettings.barcodeFormatIds = EnumBarcodeFormat.BF_QR_CODE | EnumBarcodeFormat.BF_ONED;
   cvr.updateSettings(EnumPresetTemplate.PT_READ_BARCODES, captureVisionSettings);
} catch (CaptureVisionRouterException e) {
   e.printStackTrace();
}
NSError *error;
// `cvr` is an instance of `DSCaptureVisionRouter`.
DSSimplifiedCaptureVisionSettings *cvrRuntimeSettings = [cvr getSimplifiedSettings:DSPresetTemplateReadBarcodes error:&error];
cvrRuntimeSettings.barcodeSettings.barcodeFormatIds = DSBarcodeFormatQRCode | DSBarcodeFormatOned;
[cvr updateSettings:DSPresetTemplate.PT_READ_BARCODES settings:cvrRuntimeSettings error:&error];
guard let cvrRuntimeSettings = try? cvr.getSimplifiedSettings(template.rawValue) else {
    return
}
cvrRuntimeSettings.barcodeSettings?.barcodeFormatIds = .qrCode | .oneD
do {
    try cvr.updateSettings(template.rawValue, settings:cvrRuntimeSettings)
} catch {
    print("update runtimeSettings error:\(error.localizedDescription)")
}

See Also

JSON Template

With a JSON template, you can make use of all the configuration options that DBR offers.

Basic steps:

  1. Build a JSON template and configure the required parameters
  2. Save the template to a file or convert it to string
  3. Call method InitSettingsFromFile or InitSettings to apply the settings

Read Parameter Template Structure to learn more about the structure of templates.

JavaScript edition only supports importing a JSON string and not a file.

The following steps demonstrates how to specify barcode formats via JSON Template.

  • Build a most basic JSON template and configure parameter BarcodeFormatIds
    {
        "CaptureVisionTemplates": [
            {
                "Name" : "CV_0",
                "ImageROIProcessingNameArray": ["TA_0" ]
            }
        ],
        "TargetROIDefOptions" : [
            {
                "Name" : "TA_0",
                "TaskSettingNameArray": [ "BR_0" ]
            }
        ],
        "BarcodeReaderTaskSettingOptions": [
            {
                "Name" : "BR_0",
                "BarcodeFormatIds" : ["BF_ONED", "BF_QR_CODE"]
            }
        ]
    }
    
  • Save the above template to file setting.json or Convert the above content into a string format for the respective programming language.

  • Call method InitSettingsFromFile or InitSettings to apply the settings

    • 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-SETTING-FILE", szErrorMsg, 256);
    //cvr->InitSettings("{\"CaptureVisionTemplates\":[{\"Name\":\"CV_0\",\"ImageROIProcessingNameArray\":[\"TA_0\"]}],\"TargetROIDefOptions\":[{\"Name\":\"TA_0\",\"TaskSettingNameArray\":[\"BR_0\"]}],\"BarcodeReaderTaskSettingOptions\":[{\"Name\":\"BR_0\",\"BarcodeFormatIds\":[\"BF_ONED\",\"BF_QR_CODE\"]}]}", 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.
    }
    

Mixed Usage

It’s also possible to use a JSON Template along with SimplifiedCaptureVisionSettings. Typically, you initialize the SDK with a JSON Template, the settings in which will be reflected in SimplifiedCaptureVisionSettings, then you can further fine-tune SimplifiedCaptureVisionSettings to apply to the actual reading process.

This page is compatible for:

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.42
    • 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
  • Documentation Homepage
Change +