|
2 | 2 | from dynamsoft_barcode_reader_bundle import *
|
3 | 3 | if __name__ == "__main__":
|
4 | 4 | try:
|
5 |
| - # 1.Initialize license. |
| 5 | + # 1. Initialize license. |
6 | 6 | # The string "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" here is a free public trial license. Note that network connection is required for this license to work.
|
7 | 7 | # 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
|
8 | 8 | err_code, err_str = LicenseManager.init_license("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9")
|
|
17 | 17 | err_code, err_str, settings = cvr_instance.get_simplified_settings(EnumPresetTemplate.PT_READ_BARCODES)
|
18 | 18 |
|
19 | 19 | # 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 |
21 | 21 |
|
22 |
| - # 3.3 Set the expected barcode count you want to read. |
| 22 | + # 3.3 Set the expected barcode count you want to read. |
23 | 23 | settings.barcode_settings.expected_barcodes_count = 10
|
24 | 24 |
|
25 | 25 | # 3.4 Set the grayscale transformation modes.
|
26 | 26 | settings.barcode_settings.grayscale_transformation_modes[0] = EnumGrayscaleTransformationMode.GTM_AUTO
|
27 | 27 |
|
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. |
29 | 29 | # Note: DBR supports setting coordinates by pixels or percentages. The origin of the coordinate system is the upper left corner point.
|
30 | 30 | settings.roi_measured_in_percentage = 1
|
31 | 31 | points = settings.roi.points
|
|
43 | 43 | if err_code != EnumErrorCode.EC_OK:
|
44 | 44 | print("Update settings failed: ErrorCode:", err_code, ", ErrorString:", err_str)
|
45 | 45 | # 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" |
47 | 47 |
|
48 | 48 | # 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) |
50 | 50 |
|
51 | 51 | # 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: |
56 | 54 | print("No barcode detected.")
|
57 | 55 | 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()) |
61 | 73 | print()
|
62 |
| - print("Barcode", index) |
63 |
| - print("Barcode Format:", item.get_format_string()) |
64 |
| - print("Barcode Text:", item.get_text()) |
65 | 74 | except Exception as e:
|
66 | 75 | print(e)
|
0 commit comments