Skip to content

Commit 2494e4b

Browse files
update to 11.0.2000
1 parent a643bf7 commit 2494e4b

10 files changed

+1165
-98
lines changed

LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ License Notice
22

33
This folder contains code samples ("Sample Code") for use with Dynamsoft Barcode Reader, a commercial software development kit licensed by Dynamsoft. The Sample Code may be modified and included in your end user software under the terms of the Dynamsoft Software License Agreement https://www.dynamsoft.com/company/license-agreement/ ("Commercial License"). Except as expressly stated in the Commercial License, no other rights are granted in the Sample Code. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
44

5-
Copyright © 2003–2024 Dynamsoft. All rights reserved.
5+
Copyright © 2003–2025 Dynamsoft. All rights reserved.

Legal.txt

+916-1
Large diffs are not rendered by default.

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pip3 install dynamsoft_barcode_reader_bundle
4747
| [`GeneralSettings`](Samples/general_settings.py) | Shows how to adjust general scan settings, e.g., barcode format, barcode count, scan region. |
4848
| [`ReadDPMBarcode`](Samples/read_dpm_barcode.py) | Shows how to read DPM (Direct Part Mark) barcodes. |
4949
| [`VideoDecoding`](Samples/video_decoding.py) | Shows how to decode barcodes from live video or video file. |
50+
| [`MultiFormatImageProcessing`](Samples/multi_format_image_processing.py) | Shows how to decode barcodes from various image format. |
5051

5152
## Documentation
5253

Samples/ReadDPM.json

+62-24
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,83 @@
11
{
2-
"CaptureVisionTemplates" :
3-
[
2+
"CaptureVisionTemplates": [
43
{
5-
"Name" : "ReadDPM",
6-
"ImageROIProcessingNameArray" :
7-
[
4+
"Name": "ReadDPM",
5+
"ImageROIProcessingNameArray": [
86
"roi_read_dpm"
97
],
10-
"MaxParallelTasks" : 0,
11-
"Timeout" : 3000
8+
"MaxParallelTasks": 0,
9+
"Timeout": 3000
1210
}
1311
],
14-
"TargetROIDefOptions" :
15-
[
12+
"TargetROIDefOptions": [
1613
{
17-
"Name" : "roi_read_dpm",
18-
"TaskSettingNameArray" :
19-
[
14+
"Name": "roi_read_dpm",
15+
"TaskSettingNameArray": [
2016
"task_read_dpm"
2117
]
2218
}
2319
],
2420
"BarcodeReaderTaskSettingOptions": [
2521
{
26-
"Name" : "task_read_dpm",
27-
"ExpectedBarcodesCount" : 1,
28-
"BarcodeFormatIds" : [ "BF_DATAMATRIX" ],
29-
"LocalizationModes" : [
22+
"Name": "task_read_dpm",
23+
"ExpectedBarcodesCount": 1,
24+
"BarcodeFormatIds": [
25+
"BF_DATAMATRIX"
26+
],
27+
"DPMCodeReadingModes": [
3028
{
31-
"Mode": "LM_STATISTICS_MARKS"
32-
},
33-
{
34-
"Mode": "LM_CONNECTED_BLOCKS"
29+
"Mode": "DPMCRM_GENERAL"
3530
}
3631
],
37-
"DPMCodeReadingModes":
38-
[
32+
"SectionArray": [
33+
{
34+
"Section": "ST_REGION_PREDETECTION",
35+
"ImageParameterName": "ip_default",
36+
"StageArray": [
37+
{
38+
"Stage": "SST_PREDETECT_REGIONS"
39+
}
40+
]
41+
},
42+
{
43+
"Section": "ST_BARCODE_LOCALIZATION",
44+
"ImageParameterName": "ip_default",
45+
"StageArray": [
46+
{
47+
"Stage": "SST_LOCALIZE_CANDIDATE_BARCODES",
48+
"LocalizationModes": [
49+
{
50+
"Mode": "LM_STATISTICS_MARKS"
51+
},
52+
{
53+
"Mode": "LM_CONNECTED_BLOCKS"
54+
}
55+
]
56+
},
57+
{
58+
"Stage": "SST_LOCALIZE_BARCODES"
59+
}
60+
]
61+
},
3962
{
40-
"Mode": "DPMCRM_GENERAL"
63+
"Section": "ST_BARCODE_DECODING",
64+
"ImageParameterName": "ip_default",
65+
"StageArray": [
66+
{
67+
"Stage": "SST_RESIST_DEFORMATION"
68+
},
69+
{
70+
"Stage": "SST_COMPLEMENT_BARCODE"
71+
},
72+
{
73+
"Stage": "SST_SCALE_BARCODE_IMAGE"
74+
},
75+
{
76+
"Stage": "SST_DECODE_BARCODES"
77+
}
78+
]
4179
}
4280
]
4381
}
4482
]
45-
}
83+
}

Samples/general_settings.py

+25-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from dynamsoft_barcode_reader_bundle import *
33
if __name__ == "__main__":
44
try:
5-
# 1.Initialize license.
5+
# 1. Initialize license.
66
# The string "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" here is a free public trial license. Note that network connection is required for this license to work.
77
# You can also request a 30-day trial license in the customer portal: https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=samples&package=python
88
err_code, err_str = LicenseManager.init_license("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9")
@@ -17,15 +17,15 @@
1717
err_code, err_str, settings = cvr_instance.get_simplified_settings(EnumPresetTemplate.PT_READ_BARCODES)
1818

1919
# 3.2 Set the expected barcode format you want to read.
20-
settings.barcode_settings.barcode_format_ids = EnumBarcodeFormat.BF_POSTALCODE | EnumBarcodeFormat.BF_DOTCODE
20+
settings.barcode_settings.barcode_format_ids = EnumBarcodeFormat.BF_PDF417 | EnumBarcodeFormat.BF_QR_CODE
2121

22-
# 3.3 Set the expected barcode count you want to read.
22+
# 3.3 Set the expected barcode count you want to read.
2323
settings.barcode_settings.expected_barcodes_count = 10
2424

2525
# 3.4 Set the grayscale transformation modes.
2626
settings.barcode_settings.grayscale_transformation_modes[0] = EnumGrayscaleTransformationMode.GTM_AUTO
2727

28-
# 3.5 Set the ROI(region of interest) to speed up the barcode reading process.
28+
# 3.5 Set the ROI(region of interest) to speed up the barcode reading process.
2929
# Note: DBR supports setting coordinates by pixels or percentages. The origin of the coordinate system is the upper left corner point.
3030
settings.roi_measured_in_percentage = 1
3131
points = settings.roi.points
@@ -43,24 +43,33 @@
4343
if err_code != EnumErrorCode.EC_OK:
4444
print("Update settings failed: ErrorCode:", err_code, ", ErrorString:", err_str)
4545
# 4.Replace by your own image path
46-
image_path = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + "../images/AllSupportedBarcodeTypes.png"
46+
image_path = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + "../images/GeneralBarcodes.png"
4747

4848
# 5.Decode barcodes from an image file.
49-
result = cvr_instance.capture(image_path, EnumPresetTemplate.PT_READ_BARCODES)
49+
result_array = cvr_instance.capture_multi_pages(image_path, EnumPresetTemplate.PT_READ_BARCODES)
5050

5151
# 6.Output the barcode text.
52-
if result.get_error_code() != EnumErrorCode.EC_OK:
53-
print("Error:", result.get_error_code(), result.get_error_string())
54-
barcode_result = result.get_decoded_barcodes_result()
55-
if barcode_result is None or barcode_result.get_items() == 0:
52+
results = result_array.get_results()
53+
if results is None or len(results) == 0:
5654
print("No barcode detected.")
5755
else:
58-
items = barcode_result.get_items()
59-
print("Decoded", len(items), "barcodes.")
60-
for index,item in enumerate(items):
56+
for result in results:
57+
if result.get_error_code() == EnumErrorCode.EC_UNSUPPORTED_JSON_KEY_WARNING:
58+
print("Warning:", result.get_error_code(), result.get_error_string())
59+
elif result.get_error_code() != EnumErrorCode.EC_OK:
60+
print("Error:", result.get_error_code(), result.get_error_string())
61+
62+
barcode_result = result.get_decoded_barcodes_result()
63+
if barcode_result is None or barcode_result.get_items() == 0:
64+
print("No barcode detected.")
65+
else:
66+
items = barcode_result.get_items()
67+
print("Decoded", len(items), "barcodes.")
68+
for index,item in enumerate(items):
69+
print()
70+
print("Barcode", index)
71+
print("Barcode Format:", item.get_format_string())
72+
print("Barcode Text:", item.get_text())
6173
print()
62-
print("Barcode", index)
63-
print("Barcode Format:", item.get_format_string())
64-
print("Barcode Text:", item.get_text())
6574
except Exception as e:
6675
print(e)
+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
from dynamsoft_barcode_reader_bundle import *
2+
import cv2
3+
from PIL import Image
4+
import numpy as np
5+
if __name__ == "__main__":
6+
try:
7+
# 1.Initialize license.
8+
# The string "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" here is a free public trial license. Note that network connection is required for this license to work.
9+
# You can also request a 30-day trial license in the customer portal: https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=samples&package=python
10+
err_code, err_str = LicenseManager.init_license("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9")
11+
if err_code != EnumErrorCode.EC_OK and err_code != EnumErrorCode.EC_LICENSE_CACHE_USED:
12+
print("License initialization failed: ErrorCode:", err_code, ", ErrorString:", err_str)
13+
else:
14+
# 2. Create an instance of CaptureVisionRouter.
15+
cvr_instance = CaptureVisionRouter()
16+
options = [
17+
"exit program",
18+
"decode with file",
19+
"decode with buffer",
20+
"decode with bytes",
21+
"decode with opencv",
22+
"decode with PIL",
23+
]
24+
file_path = "../images/GeneralBarcodes.png"
25+
while True:
26+
# 3. Choose decode mode.
27+
for i, option in enumerate(options):
28+
print(f"{i}. {option}")
29+
choice = input("Enter your choice: ")
30+
if not choice.isdigit() or int(choice) >= len(options) or int(choice) < 0:
31+
print("Unsupported options.")
32+
continue
33+
if int(choice) == 0:
34+
break
35+
elif int(choice) == 1:
36+
#decode image with file path.
37+
image_data = file_path
38+
elif int(choice) == 2:
39+
#decode image with dynamsoft_barcode_reader_bundle.core.ImageData
40+
image_io = ImageIO()
41+
err, image_data = image_io.read_from_file(file_path)
42+
elif int(choice) == 3:
43+
#decode image with bytes
44+
image_data = open(file_path, "rb").read()
45+
elif int(choice) == 4:
46+
#decode image with opencv
47+
image_data = cv2.imread(file_path)
48+
elif int(choice) == 5:
49+
#decode image with PIL
50+
image = Image.open(file_path)
51+
image_data = np.array(image)
52+
else:
53+
raise ValueError("An unexpected value.")
54+
55+
# 4. Decode barcodes from the image.
56+
captured_result = cvr_instance.capture(image_data,EnumPresetTemplate.PT_READ_BARCODES)
57+
58+
# 5. Output the barcode result.
59+
if captured_result.get_error_code() == EnumErrorCode.EC_UNSUPPORTED_JSON_KEY_WARNING:
60+
print("Warning:", captured_result.get_error_code(), captured_result.get_error_string())
61+
elif captured_result.get_error_code() != EnumErrorCode.EC_OK:
62+
print("Error:", captured_result.get_error_code(), captured_result.get_error_string())
63+
64+
barcode_result = captured_result.get_decoded_barcodes_result()
65+
if barcode_result is None or barcode_result.get_items() == 0:
66+
print("No barcode detected.")
67+
else:
68+
items = barcode_result.get_items()
69+
print("Decoded", len(items), "barcodes.")
70+
for index,item in enumerate(items):
71+
print("Result", index+1)
72+
print("Barcode Format:", item.get_format_string())
73+
print("Barcode Text:", item.get_text())
74+
75+
print()
76+
except Exception as e:
77+
print(e)
78+
input("Press Enter to quit...")
79+

Samples/read_an_image.py

+29-14
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,41 @@
11
from dynamsoft_barcode_reader_bundle import *
22
import os
3-
43
if __name__ == '__main__':
5-
# Initialize license.
4+
# 1. Initialize license.
65
# You can request and extend a trial license from https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=samples&package=python
76
# The string 'DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9' here is a free public trial license. Note that network connection is required for this license to work.
87
errorCode, errorMsg = LicenseManager.init_license("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9")
98
if errorCode != EnumErrorCode.EC_OK and errorCode != EnumErrorCode.EC_LICENSE_CACHE_USED:
109
print("License initialization failed: ErrorCode:", errorCode, ", ErrorString:", errorMsg)
1110
else:
12-
cvr = CaptureVisionRouter()
13-
result = cvr.capture("../images/GeneralBarcodes.png", EnumPresetTemplate.PT_READ_BARCODES)
14-
if result.get_error_code() != EnumErrorCode.EC_OK:
15-
print("Error:", result.get_error_code(), result.get_error_string())
16-
barcode_result = result.get_decoded_barcodes_result()
17-
if barcode_result is None or barcode_result.get_items() == 0:
11+
# 2. Create an instance of CaptureVisionRouter.
12+
cvr_instance = CaptureVisionRouter()
13+
14+
# 3. Replace by your own image path.
15+
image_path = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + "../images/GeneralBarcodes.png"
16+
17+
# 4. Decode barcodes from an image file.
18+
result_array = cvr_instance.capture_multi_pages(image_path, EnumPresetTemplate.PT_READ_BARCODES)
19+
20+
# 5. Output the barcode text.
21+
results = result_array.get_results()
22+
if results is None or len(results) == 0:
1823
print("No barcode detected.")
1924
else:
20-
items = barcode_result.get_items()
21-
print("Decoded", len(items), "barcodes.")
22-
for index,item in enumerate(items):
23-
print("Result", index+1)
24-
print("Barcode Format:", item.get_format_string())
25-
print("Barcode Text:", item.get_text())
25+
for i, result in enumerate(results):
26+
if result.get_error_code() == EnumErrorCode.EC_UNSUPPORTED_JSON_KEY_WARNING:
27+
print("Warning:", result.get_error_code(), result.get_error_string())
28+
elif result.get_error_code() != EnumErrorCode.EC_OK:
29+
print("Error:", result.get_error_code(), result.get_error_string())
30+
barcode_result = result.get_decoded_barcodes_result()
31+
if barcode_result is None or barcode_result.get_items() == 0:
32+
print("Page-"+str(i+1), "No barcode detected.")
33+
else:
34+
items = barcode_result.get_items()
35+
print("Page-"+str(i+1), "Decoded", len(items), "barcodes.")
36+
for index,item in enumerate(items):
37+
print("Result", index+1)
38+
print("Barcode Format:", item.get_format_string())
39+
print("Barcode Text:", item.get_text())
40+
print()
2641
input("Press Enter to quit...")

Samples/read_dpm_barcode.py

+23-15
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,35 @@
1515
errorCode, errorMsg = cvr_instance.init_settings_from_file(template_path)
1616
if errorCode != EnumErrorCode.EC_OK:
1717
raise Exception("Init template failed: " + errorMsg)
18-
18+
1919
# 2 Replace with your own dpm barcode image path
20-
image_path = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + "../images/dpm.jpg"
20+
image_path = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + "../images/DPM.png"
2121

2222
# 3 Decode barcodes from the image file.
23-
result = cvr_instance.capture(image_path,"")
24-
23+
result_array = cvr_instance.capture_multi_pages(image_path,"")
24+
2525
# 4 Output the barcode format and barcode text.
26-
if result.get_error_code() != EnumErrorCode.EC_OK:
27-
print("Error:", result.get_error_code(), result.get_error_string())
28-
barcode_result = result.get_decoded_barcodes_result()
29-
if barcode_result is None or barcode_result.get_items() == 0:
26+
results = result_array.get_results()
27+
if results is None or len(results) == 0:
3028
print("No barcode detected.")
3129
else:
32-
items = barcode_result.get_items()
33-
print("Decoded", len(items), "barcodes.")
34-
for index,item in enumerate(items):
30+
for i, result in enumerate(results):
31+
if result.get_error_code() == EnumErrorCode.EC_UNSUPPORTED_JSON_KEY_WARNING:
32+
print("Warning:", result.get_error_code(), result.get_error_string())
33+
elif result.get_error_code() != EnumErrorCode.EC_OK:
34+
print("Error:", result.get_error_code(), result.get_error_string())
35+
36+
barcode_result = result.get_decoded_barcodes_result()
37+
if barcode_result is None or barcode_result.get_items() == 0:
38+
print("Page-"+str(i+1), "No barcode detected.")
39+
else:
40+
items = barcode_result.get_items()
41+
print("Page-"+str(i+1), "Decoded", len(items), "barcodes.")
42+
for index,item in enumerate(items):
43+
print()
44+
print("Barcode", index)
45+
print("Barcode Format:", item.get_format_string())
46+
print("Barcode Text:", item.get_text())
3547
print()
36-
print("Barcode", index)
37-
print("Barcode Format:", item.get_format_string())
38-
print("Barcode Text:", item.get_text())
39-
4048
except Exception as e:
4149
print(e)

0 commit comments

Comments
 (0)