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, useSimplifiedCaptureVisionSettings
.However, bear in mind that
SimplifiedCaptureVisionSettings
doesn’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
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
SimplifiedCaptureVisionSettings
object - Change one or more settings
- 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
SimplifiedCaptureVisionSettings:
C++ / JavaScriptSimplifiedBarcodeReaderSettings:
C++ / JavaScript
JSON Template
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
InitSettingsFromFile
orInitSettings
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
orInitSettings
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.