Skip to content

Commit 50e869d

Browse files
Merge pull request #804 from dynamsoft-docs/preview
update to internal commit cb09aa22
2 parents 1a4253e + 2673572 commit 50e869d

File tree

4 files changed

+513
-14
lines changed

4 files changed

+513
-14
lines changed
Lines changed: 274 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
1+
---
2+
layout: default-layout
3+
title: Barcode Formats and Count - Dynamsoft Barcode Reader SDK
4+
description: This page describes how to set barcode formats and count in Dynamsoft Barcode Reader SDK.
5+
keywords: Barcode Formats, Expected Count
6+
needAutoGenerateSidebar: true
7+
needGenerateH3Content: true
8+
noTitleIndex: true
9+
---
10+
11+
# Specify Barcode Formats and Count
12+
13+
## Set Barcode Formats
14+
15+
Specifying the barcode format is always the first step when it comes to the configuration of Dynamsoft Barcode Reader(DBR). Be sure to confirm that the target barcode formats are indeed supported by DBR by checking our [list of supported barcode types](https://www.dynamsoft.com/barcode-types/). Excluding undesired barcode types will improve the processing efficiency.
16+
17+
You can configure the parameter in two different ways, depending on your requirements. You can do it through `SimplifiedCaptureVisionSettings`, or if it suits your needs better, you can opt for `JSON Template`. Below are examples illustrating both of these configuration methods:
18+
19+
* Configure barcode format via `SimplifiedCaptureVisionSettings`.
20+
21+
<div class="sample-code-prefix template2"></div>
22+
>- JavaScript
23+
>- C++
24+
>- Android
25+
>- Objective-C
26+
>- Swift
27+
>- Python
28+
>- C#
29+
>
30+
>
31+
```javascript
32+
// 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.
33+
let settings = await router.getSimplifiedSettings("ReadSingleBarcode");
34+
// Specify the barcode formats by enumeration values.
35+
// Use "|" to enable multiple barcode formats at one time.
36+
settings.barcodeSettings.barcodeFormatIds = Dynamsoft.DBR.EnumBarcodeFormat.BF_QR_CODE | Dynamsoft.DBR.EnumBarcodeFormat.BF_QR_CODE;
37+
// Update the settings to a specific template.
38+
await router.updateSettings("ReadSingleBarcode", settings);
39+
```
40+
>
41+
```c++
42+
char szErrorMsg[256] = {0};
43+
// Obtain current runtime settings of `CCaptureVisionRouter` instance.
44+
CCaptureVisionRouter* cvRouter = new CCaptureVisionRouter;
45+
SimplifiedCaptureVisionSettings settings;
46+
cvRouter->GetSimplifiedSettings(CPresetTemplate::PT_READ_BARCODES, &settings);
47+
// Specify the barcode formats by enumeration values.
48+
// Use "|" to enable multiple barcode formats at one time.
49+
settings.barcodeSettings.barcodeFormatIds = BF_QR_CODE | BF_ONED;
50+
// Update the settings.
51+
cvRouter->UpdateSettings(CPresetTemplate::PT_READ_BARCODES, &settings, szErrorMsg, 256);
52+
```
53+
>
54+
```java
55+
try {
56+
// Obtain current runtime settings. `cvr` is an instance of `CaptureVisionRouter`.
57+
// Here we use `EnumPresetTemplate.PT_READ_BARCODES` as an example. You can change it to your own template name or the name of other preset template.
58+
SimplifiedCaptureVisionSettings captureVisionSettings = cvr.getSimplifiedSettings(EnumPresetTemplate.PT_READ_BARCODES);
59+
captureVisionSettings.barcodeSettings.barcodeFormatIds = EnumBarcodeFormat.BF_QR_CODE | EnumBarcodeFormat.BF_ONED;
60+
// Update the settings. Remember to specify the same template name you used when getting the settings.
61+
cvr.updateSettings(EnumPresetTemplate.PT_READ_BARCODES, captureVisionSettings);
62+
} catch (CaptureVisionRouterException e) {
63+
e.printStackTrace();
64+
}
65+
```
66+
>
67+
```objc
68+
NSError *error;
69+
// Obtain current runtime settings. `cvr` is an instance of `CaptureVisionRouter`.
70+
// Here we use `EnumPresetTemplate.PT_READ_BARCODES` as an example. You can change it to your own template name or the name of other preset template.
71+
DSSimplifiedCaptureVisionSettings *captureVisionSettings = [self.cvr getSimplifiedSettings:DSPresetTemplateReadBarcodes error:&error];
72+
captureVisionSettings.barcodeSettings.barcodeFormatIds = DSBarcodeFormatQRCode | DSBarcodeFormatOneD;
73+
// Update the settings. Remember to specify the same template name you used when getting the settings.
74+
[self.cvr updateSettings:DSPresetTemplateReadBarcodes settings:captureVisionSettings error:&error];
75+
```
76+
>
77+
```swift
78+
do{
79+
// Obtain current runtime settings. `cvr` is an instance of `CaptureVisionRouter`.
80+
// Here we use `EnumPresetTemplate.PT_READ_BARCODES` as an example. You can change it to your own template name or the name of other preset template.
81+
let captureVisionSettings = try cvr.getSimplifiedSettings(PresetTemplate.readBarcodes.rawValue)
82+
captureVisionSettings.barcodeSettings?.barcodeFormatIds = [.qrCode,.oneD]
83+
// Update the settings. Remember to specify the same template name you used when getting the settings.
84+
try cvr.updateSettings(PresetTemplate.readBarcodes.rawValue, settings: captureVisionSettings)
85+
}catch{
86+
// Add code to do when error occurs.
87+
}
88+
```
89+
>
90+
```python
91+
cvr_instance = CaptureVisionRouter()
92+
# Obtain current runtime settings of `CCaptureVisionRouter` instance.
93+
err_code, err_str, settings = cvr_instance.get_simplified_settings(EnumPresetTemplate.PT_READ_BARCODES.value)
94+
# Specify the barcode formats by enumeration values.
95+
# Use "|" to enable multiple barcode formats at one time.
96+
settings.barcode_settings.barcode_format_ids = EnumBarcodeFormat.BF_QR_CODE.value | EnumBarcodeFormat.BF_ONED.value
97+
# Update the settings.
98+
err_code, err_str = cvr_instance.update_settings(EnumPresetTemplate.PT_READ_BARCODES.value, settings)
99+
```
100+
>
101+
```csharp
102+
using (CaptureVisionRouter cvRouter = new CaptureVisionRouter())
103+
{
104+
SimplifiedCaptureVisionSettings settings;
105+
string errorMsg;
106+
// Obtain current runtime settings of `CCaptureVisionRouter` instance.
107+
cvRouter.GetSimplifiedSettings(PresetTemplate.PT_READ_BARCODES, out settings);
108+
// Specify the barcode formats by enumeration values.
109+
// Use "|" to enable multiple barcode formats at one time.
110+
settings.barcodeSettings.barcodeFormatIds = (ulong)(EnumBarcodeFormat.BF_QR_CODE | EnumBarcodeFormat.BF_ONED);
111+
// Update the settings.
112+
cvRouter.UpdateSettings(PresetTemplate.PT_READ_BARCODES, settings, out errorMsg);
113+
}
114+
```
115+
116+
117+
* Configure barcode format via `JSON parameter template file`
118+
* Update parameter `BarcodeFormatIds` in your JSON template
119+
```json
120+
{
121+
"CaptureVisionTemplates": [
122+
{
123+
"Name" : "CV_0",
124+
"ImageROIProcessingNameArray": ["TA_0" ]
125+
}
126+
],
127+
"TargetROIDefOptions" : [
128+
{
129+
"Name" : "TA_0",
130+
"TaskSettingNameArray": [ "BR_0" ]
131+
}
132+
],
133+
"BarcodeReaderTaskSettingOptions": [
134+
{
135+
"Name" : "BR_0",
136+
"BarcodeFormatIds" : ["BF_ONED", "BF_QR_CODE"]
137+
}
138+
]
139+
}
140+
```
141+
142+
* Apply the above settings following the article [Use Templates for Configuring Parameters]({{ site.features }}use-runtimesettings-or-templates.html#json-template).
143+
144+
## Set Barcode Count
145+
146+
The `ExpectedBarcodesCount` parameter controls the number of expected results of the recognized barcodes from a single image. The process will be stopped as soon as the count of successfully decoded barcodes reaches the expected amount.
147+
148+
There are some suggestions on how to set the `ExpectedBarcodesCount`:
149+
150+
- When your project is designed for decoding a **single** barcode per image or frame, the recommended `ExpectedBarcodesCount` is **1**. This will sharply improve the processing speed.
151+
- When there are **n** barcodes in a single image or frame (**n** is a fixed number) and you'd like the barcode reader to decode **all of them**, the recommended `ExpectedBarcodesCount` is **n**.
152+
- When the number of barcodes is unknown and you want to output **as many** barcode results as possible, you can set the `ExpectedBarcodesCount` to the **maximum possible value** of `ExpectedBarcodesCount`.
153+
- When the number of barcodes is unknown and you want to output **at least one** barcode result as **soon** as possible, you can set the `ExpectedBarcodesCount` to **0**. The barcode reader will try to decode at least one barcode from the image.
154+
155+
You can configure the parameter in two different ways, depending on your requirements. You can do it through `SimplifiedBarcodeReaderSettings`, or if it suits your needs better, you can opt for `JSON Template`. Below are examples illustrating both of these configuration methods:
156+
157+
* Configure expected barcode count via `SimplifiedCaptureVisionSettings`.
158+
159+
<div class="sample-code-prefix template2"></div>
160+
>- JavaScript
161+
>- C++
162+
>- Android
163+
>- Objective-C
164+
>- Swift
165+
>- Python
166+
>- C#
167+
>
168+
>
169+
```javascript
170+
// 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.
171+
let settings = await router.getSimplifiedSettings("ReadSingleBarcode");
172+
// Specify the expected barcode count.
173+
settings.barcodeSettings.expectedBarcodesCount = 1;
174+
// Update the settings.
175+
await router.updateSettings("ReadSingleBarcode", settings);
176+
```
177+
>
178+
```c++
179+
char szErrorMsg[256] = {0};
180+
// Obtain current runtime settings of `CCaptureVisionRouter` instance.
181+
CCaptureVisionRouter* cvRouter = new CCaptureVisionRouter;
182+
SimplifiedCaptureVisionSettings settings;
183+
cvRouter->GetSimplifiedSettings(CPresetTemplate::PT_READ_BARCODES, &settings);
184+
// Specify the expected barcode count.
185+
settings.barcodeSettings.expectedBarcodesCount = 1;
186+
// Update the settings.
187+
cvRouter->UpdateSettings(CPresetTemplate::PT_READ_BARCODES, &settings, szErrorMsg, 256);
188+
```
189+
>
190+
```java
191+
try {
192+
// Obtain current runtime settings. `cvr` is an instance of `CaptureVisionRouter`.
193+
// Here we use `EnumPresetTemplate.PT_READ_BARCODES` as an example. You can change it to your own template name or the name of other preset template.
194+
SimplifiedCaptureVisionSettings captureVisionSettings = cvr.getSimplifiedSettings(EnumPresetTemplate.PT_READ_BARCODES);
195+
captureVisionSettings.barcodeSettings.expectedBarcodesCount = 1;
196+
// Update the settings. Remember to specify the same template name you used when getting the settings.
197+
cvr.updateSettings(EnumPresetTemplate.PT_READ_BARCODES, captureVisionSettings);
198+
} catch (CaptureVisionRouterException e) {
199+
e.printStackTrace();
200+
}
201+
```
202+
>
203+
```objc
204+
NSError *error;
205+
// Obtain current runtime settings. `cvr` is an instance of `DSCaptureVisionRouter`.
206+
// Here we use `EnumPresetTemplate.PT_READ_BARCODES` as an example. You can change it to your own template name or the name of other preset template.
207+
DSSimplifiedCaptureVisionSettings *captureVisionSettings = [self.cvr getSimplifiedSettings:DSPresetTemplateReadBarcodes error:&error];
208+
captureVisionSettings.barcodeSettings.expectedBarcodesCount = 1;
209+
// Update the settings. Remember to specify the same template name you used when getting the settings.
210+
[self.cvr updateSettings:DSPresetTemplateReadBarcodes settings:captureVisionSettings error:&error];
211+
```
212+
>
213+
```swift
214+
do{
215+
// Obtain current runtime settings. `cvr` is an instance of `CaptureVisionRouter`.
216+
// Here we use `EnumPresetTemplate.PT_READ_BARCODES` as an example. You can change it to your own template name or the name of other preset template.
217+
let captureVisionSettings = try cvr.getSimplifiedSettings(PresetTemplate.readBarcodes.rawValue)
218+
captureVisionSettings.barcodeSettings?.expectedBarcodesCount = 1
219+
// Update the settings. Remember to specify the same template name you used when getting the settings.
220+
try cvr.updateSettings(PresetTemplate.readBarcodes.rawValue, settings: captureVisionSettings)
221+
}catch{
222+
// Add code to do when error occurs.
223+
}
224+
```
225+
>
226+
```python
227+
cvr_instance = CaptureVisionRouter()
228+
# Obtain current runtime settings of `CCaptureVisionRouter` instance.
229+
err_code, err_str, settings = cvr_instance.get_simplified_settings(EnumPresetTemplate.PT_READ_BARCODES.value)
230+
# Specify the expected barcode count.
231+
settings.barcode_settings.expected_barcodes_count = 1
232+
# Update the settings.
233+
err_code, err_str = cvr_instance.update_settings(EnumPresetTemplate.PT_READ_BARCODES.value, settings)
234+
```
235+
>
236+
```csharp
237+
using (CaptureVisionRouter cvRouter = new CaptureVisionRouter())
238+
{
239+
SimplifiedCaptureVisionSettings settings;
240+
string errorMsg;
241+
// Obtain current runtime settings of `CCaptureVisionRouter` instance.
242+
cvRouter.GetSimplifiedSettings(PresetTemplate.PT_READ_BARCODES, out settings);
243+
// Specify the expected barcode count.
244+
settings.barcodeSettings.expectedBarcodesCount = 1;
245+
// Update the settings.
246+
cvRouter.UpdateSettings(PresetTemplate.PT_READ_BARCODES, settings, out errorMsg);
247+
}
248+
```
249+
250+
* Configure barcode format via `JSON parameter template file`
251+
* update parameter `ExpectedBarcodesCount` in your JSON template
252+
```json
253+
{
254+
"CaptureVisionTemplates": [
255+
{
256+
"Name" : "CV_0",
257+
"ImageROIProcessingNameArray": ["TA_0" ]
258+
}
259+
],
260+
"TargetROIDefOptions" : [
261+
{
262+
"Name" : "TA_0",
263+
"TaskSettingNameArray": [ "BR_0" ]
264+
}
265+
],
266+
"BarcodeReaderTaskSettingOptions": [
267+
{
268+
"Name" : "BR_0",
269+
"ExpectedBarcodesCount" : 1
270+
}
271+
]
272+
}
273+
```
274+
* Apply the above settings following the article [Use Templates for Configuring Parameters]({{ site.features }}use-runtimesettings-or-templates.html#json-template).

programming/features/barcode-formats-and-count.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ You can configure the parameter in two different ways, depending on your require
164164
>- Swift
165165
>- Python
166166
>- C#
167+
>- Java
167168
>
168169
>
169170
```javascript
@@ -246,6 +247,27 @@ using (CaptureVisionRouter cvRouter = new CaptureVisionRouter())
246247
cvRouter.UpdateSettings(PresetTemplate.PT_READ_BARCODES, settings, out errorMsg);
247248
}
248249
```
250+
>
251+
```java
252+
CaptureVisionRouter cvRouter = new CaptureVisionRouter();
253+
SimplifiedCaptureVisionSettings settings = null;
254+
try {
255+
// Obtain current runtime settings of `CaptureVisionRouter` instance
256+
settings = cvRouter.getSimplifiedSettings(EnumPresetTemplate.PT_READ_BARCODES);
257+
} catch (CaptureVisionException e) {
258+
settings = new SimplifiedCaptureVisionSettings();
259+
}
260+
// Specify the expected barcode count.
261+
settings.barcodeSettings.expectedBarcodesCount = 1;
262+
try {
263+
// Update the settings.
264+
cvRouter.updateSettings(EnumPresetTemplate.PT_READ_BARCODES, settings);
265+
} catch (CaptureVisionException e) {
266+
System.out.println("Update settings failed: ErrorCode: " + e.getErrorCode() + ", ErrorString: " + e.getErrorString());
267+
return;
268+
}
269+
//call capture or other tasks
270+
```
249271

250272
* Configure barcode format via `JSON parameter template file`
251273
* update parameter `ExpectedBarcodesCount` in your JSON template

0 commit comments

Comments
 (0)