| layout | default-layout |
|---|---|
| description | This article introduces two ways to configure DBR parameters, SimplifiedCaptureVisionSettings and JSON Template, and their syntax rules. |
| title | Use SimplifiedCaptureVisionSettings or JSON Template |
| keywords | DBR SimplifiedCaptureVisionSettings Json Template ImageParameter FormatSpecification |
| needAutoGenerateSidebar | true |
| needGenerateH3Content | true |
| noTitleIndex | true |
Dynamsoft Barcode Reader (DBR) provides two ways for configuring the parameters: via SimplifiedCaptureVisionSettings or via a JSON Template.
-
SimplifiedCaptureVisionSettings
SimplifiedCaptureVisionSettingsis an object that manages various parameters during runtime. If you need to dynamically configure the reading process, useSimplifiedCaptureVisionSettings.However, bear in mind that
SimplifiedCaptureVisionSettingsdoesn't provide all the available configuration options of the SDK. -
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 is an object that manages various runtime settings of the DBR SDK which dictate the performance of the barcode reader.
Basic steps:
- Get the current value of the
SimplifiedCaptureVisionSettingsobject - Change one or more settings
- Update the
SimplifiedCaptureVisionSettingsobject with the changed copy for the changes to take effect
The following code snippet demonstrates how to specify barcode formats via SimplifiedCaptureVisionSettings.
See Also
SimplifiedCaptureVisionSettings:[C++]({{ site.dcvb_cpp_api }}capture-vision-router/structs/simplified-capture-vision-settings.html) / JavaScript / [Python]({{ site.dcvb_python_api }}capture-vision-router/auxiliary-classes/simplified-capture-vision-settings.html) / [.NET]({{ site.dcvb_dotnet_api }}capture-vision-router/auxiliary-classes/simplified-capture-vision-settings.html)SimplifiedBarcodeReaderSettings:[C++]({{ site.cpp_api }}simplified-barcode-reader-settings.html) / JavaScript / [Python]({{ site.python_api }}simplified-barcode-reader-settings.html) / [.NET]({{ site.dotnet_api }}simplified-barcode-reader-settings.html)
With a JSON template, you can make use of all the configuration options that DBR offers.
Basic steps:
- Build a JSON template and configure the required parameters
- Save the template to a file or convert it to string
- Call method
InitSettingsFromFileorInitSettingsto apply the settings
Read [Parameter Template Structure]({{ site.dcvb_parameters }}file/index.html) 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.jsonor Convert the above content into a string format for the respective programming language. -
Call method
>- JavaScript >- C++ >- Android >- Objective-C >- Swift >- Python >- C# >- Java > > ```javascript // `router` is an instance of `CaptureVisionRouter`. // Specify the path to the settings file or provide a JSON object. router.initSettings("PATH-TO-YOUR-SETTINGS-FILE-OR-OBJECT"); // Later in the code, specify the name of the template to use (e.g., "CV_0" in the sample template). router.startCapturing("NAME-OF-TEMPLATE-TO-USE"); ``` > ```c++ char szErrorMsg[256] = {0}; CCaptureVisionRouter* cvRouter = new CCaptureVisionRouter; cvRouter->InitSettingsFromFile("PATH-TO-SETTING-FILE", szErrorMsg, 256); //cvRouter->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 ``` > ```java try { // `cvr` is an instance of `CaptureVisionRouter`. cvr.initSettingsFromFile("PATH-TO-YOUR-SETTING-FILE"); } catch (CaptureVisionRouterException e) { e.printStackTrace(); } ``` > ```objc NSError *error; // `cvr` is an instance of `DSCaptureVisionRouter`. [self.cvr initSettingsFromFile:@"PATH-TO-YOUR-SETTING-FILE" error:&error]; ``` > ```swift do{ //`cvr` is an instance of `CaptureVisionRouter`. try cvr.initSettingsFromFile("PATH-TO-YOUR-SETTING-FILE") }catch{ // Add code to do when error occurs. } ``` > ```python cvr_instance = CaptureVisionRouter() template_file = 'PATH-TO-YOUR-SETTING-FILE' errorCode, errorMsg = cvr_instance.init_settings_from_file(template_file) # template_string = 'TEMPLATE-JSON-STRING' # errorCode, errorMsg = cvr_instance.init_settings(template_string) if errorCode != EnumErrorCode.EC_OK: raise Exception("Init template failed: " + errorMsg) # more process here ``` > ```csharp int errorCode = 1; string errorMsg; using (CaptureVisionRouter cvRouter = new CaptureVisionRouter()) { string templateFile = "PATH-TO-YOUR-SETTING-FILE"; errorCode = cvRouter.InitSettingsFromFile(templateFile, out errorMsg); //string templateString = ""; //errorCode = cvRouter.InitSettings(templateString, out errorMsg); if (errorCode != (int)EnumErrorCode.EC_OK) { Console.WriteLine("Init template failed: " + errorMsg); } // more process here } ``` > ```java CaptureVisionRouter cvRouter = new CaptureVisionRouter(); try { String templateFile = "PATH-TO-YOUR-SETTING-FILE"; cvRouter.initSettingsFromFile(templateFile); // String templateString = ""; // cvRouter.initSettings(templateString); } catch (CaptureVisionRouterException e) { System.out.println("Init template failed: ErrorCode: " + e.getErrorCode() + ", ErrorString: " + e.getErrorString()); return; } // more process here ```InitSettingsFromFileorInitSettingsto apply the settings
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.
NOTE: If your JSON template contains complex configurations that cannot be represented in
SimplifiedCaptureVisionSettings, you may encounter an error message like "complex template can't be converted to simplified settings" when callinggetSimplifiedSettings(). In such cases, you should either:
- Simplify your JSON template so that it can be converted to
SimplifiedCaptureVisionSettings, or- Continue using the JSON template exclusively without attempting to retrieve or update simplified settings.