How to set DBR parameters
DBR provides flexible parameter configuration to meet user’s decoding requirements under different scenarios and different needs. Users can modify the configuration through RuntimeSetting and the Json template.
- RuntimeSetting
RuntimeSetting is an object that manages various parameters during runtime. If you need to dynamically change the DBR configuration when the program is running, modifying RuntimeSetting will be a good choice. RuntimeSetting only provides some common parameters for setting, the complete parameter setting can be achieved through the Json template. - Json template The Json template provided by DBR allows you to manage various parameters in the form of configuration files. If your application scenario is relatively fixed and you do not need to change the DBR configuration frequently, the Json template will be a suitable choice. The Json template can be used along side with RuntimeSetting: first use the Json template to read the complete and stable settings, and then use RuntimeSetting for common and variable settings.
Next, we will introduce two methods in detail:
RuntimeSetting object
RuntimeSetting
object manages various parameters of the DBR runtime. The user can change the DBR configuration by modifying the field values in RuntimeSetting
. This method is suitable for scenarios that require dynamic configuration changes.
First, you need to get the current RuntimeSetting
object through GetRuntimeSetting
, modify the corresponding field configuration, and then use UpdateRuntimeSetting
to make the configuration effective. Specific modifiable field values will be introduced in detail in subsequent documents.
The following example shows changing the barcodeFormatIds
field in RuntimeSetting
to set the barcode format that needs to be processed.
CBarcodeReader* reader = new CBarcodeReader();
reader->InitLicense("type your license");
PublicRuntimeSettings* runtimeSettings = new PublicRuntimeSettings();
reader->GetRuntimeSettings(runtimeSettings); //get runtime settings
runtimeSettings->barcodeFormatIds = BF_ALL ; //update the parameter. BF_ALL means all barcode formats
char sError[512];
reader->UpdateRuntimeSettings(runtimeSettings, sError, 512); //update runtime settings
reader->DecodeFile("type your image path", ""); //decode
TextResultArray* paryResult = NULL;
reader->GetAllTextResults(&paryResult); //get the decode result
CBarcodeReader::FreeTextResults(&paryResult);
delete runtimeSettings;
delete reader;
Json template
DBR allows users to manage parameters in the form of configuration files that follow Json syntax. This method is suitable for the case where the parameter configuration is relatively fixed . The Json template mainly involves ImageParameter
, FormatSpecification
and RegionDefinition
.
ImageParameter
: Define the global configuration used for the entire image.
FormatSpecification
: Define the configuration used for a particular pattern.
RegionDefinition
: Define the configuration within a specific area of the image.
Let’s go into more detail.
- ImageParameter
ImageParameter
defines the global configuration used for the entire image. One or multiple may be defined. We will introduce the specific configurable fields in the subsequent documents.
When defining anImageParameter
, it can be specified by theImageParameter
in Json. When defining multipleImageParameter
, use theImageParameterContentArray
, eachImageParameter
object needs to specify a differentName
. To use theImageParameter
configuration defined in the Json template, first we need to useInitRuntimeSettingsWithFile
to load a Json file, or useInitRuntimeSettingsWithString
to load a Json string, and then when calling the DBR decoding function, specify the configuration throughName
ofImageParameter
. If not specified, the defaultImageParameter
configuration object will be used. TheemSettingPriority
parameters in theInitRuntimeSettingsWithFile
andInitRuntimeSettingsWithString
interfaces are used to specify how to operate the default configuration of the DBR when loading the Json configuration. IfCM_IGNORE
is set, the default configuration will not be changed. If set toCM_OVERWRITE
, theImageParameter
configuration you just loaded will be used and the default template will be merged.
The following is a sample Json template. In this example, we use the parameter pTemplateName
of DecodeFile
to specify the ImageParameter
whose Name
is “IP1”.
// One ImageParameter example {
{
"Version": "3.0",
"ImageParameter": {
"Name": "IP1",
"Description": "This is an imageParameter",
"BarcodeFormatIds": ["BF_ALL"]
}
}
//Multiple ImageParameter example{
{
"Version": "3.0",
"ImageParameterContentArray": [
{
"Name": "IP1",
"BarcodeFormatIds": ["BF_ALL"]
},
{
"Name": "IP2",
"BarcodeFormatIds": ["BF_CODE_39"]
},
{
"Name": "IP3",
"BarcodeFormatIds": ["BF_CODE_128"]
}
]
}
CBarcodeReader* reader = new CBarcodeReader();
reader->InitLicense("type your license");
int ret;
char sError[512];
ret = reader->InitRuntimeSettingsWithFile("JsonTemplate.json",CM_OVERWRITE,
sError,512); ///Load a template configuration
reader->DecodeFile("type your file path", "ImageParameter1"); //Use the configuration with the Name "IP1"
TextResultArray* paryResult = NULL;
reader->GetAllTextResults(&paryResult); //get decode result
CBarcodeReader::FreeTextResults(&paryResult);
delete runtimeSettings;
delete reader;
- FormatSpecification
If you only want to configure certain parameters for a specific pattern, thenFormatSpecification
should be used. This object defines the configuration used for a specific barcode format. If the configuration is inconsistent with the global ImageParameter configuration, thenFormatSpecification
has a higher priority. For specific configurable parameters and applicable scenarios, please refer to our documentation for specific barcode format configuration parameters. In Json, use theFormatSpecificationArray
to define one or multipleFormatSpecification
objects, which are distinguished by defining differentName
. UseFormatSpecificationNameArray
to specify theName
that eachFormatSpecification
needs to use.
In the following example, we defined a FormatSpecification
named “FS_1”.
{
"ImageParameter": {
"Name": "ImageParameter1",
"FormatSpecificationNameArray": ["FS_1"]
},
"FormatSpecificationArray": [
{
"Name": "FS_1",
"AllmoduleDeviation": 10,
"BarcodeFormatIds": ["BF_CODE_39"]
}
],
"Version": "3.0"
}
- RegionDefinition
If you only care about a specific area on the image instead of the entire image or you want to make additional configurations for a specific area of the image, you should use
RegionDefinition
. Setting the area can help DBR to narrow the range of the image to be processed, which helps to increase the speed. TheRegionDefinition
object defines the configuration in the specified area of the image. If the configuration is inconsistent with the globalImageParameter
configuration, then the RegionDefinition has a higher priority. For specific configurable parameters, please refer to our detailed documentation onRegionDefinition
. In Json, one or moreRegionDefinitionArray
are defined byRegionDefinitionArray
, and distinguished by differentName
.
In the following example, we have defined two RegionDefinition
, “RP_1” and “RP_2”
{
"ImageParameter": {
"Name": "ImageParameter1",
"Description": "This is a region template",
"RegionDefinitionNameArray": ["RP_1", "RP_2"]
},
"RegionDefinitionArray": [
{
"Name": "RP_1",
"BarcodeFormatIds": ["BF_CODE_39"],
"Top": 20,
"Bottom": 80,
"Left": 20,
"Right": 80,
"MeasuredByPercentage": 1
},
{
"Name": "RP_2",
"BarcodeFormatIds": ["BF_CODE_93"]
}
],
"Version": "3.0"
}