|
| 1 | +import os |
| 2 | +import sys |
| 3 | +import json |
| 4 | +from typing import List |
| 5 | +from dbr import * |
| 6 | + |
| 7 | +# you can change the following variables' value to your own value. |
| 8 | +license_key = "Input your own license" |
| 9 | +#license_server = "Input the name/IP of the license server" |
| 10 | +json_file = r"Please input your own template path" |
| 11 | +image = r"Please input your own image path" |
| 12 | + |
| 13 | +reader = BarcodeReader() |
| 14 | + |
| 15 | +# Apply for a trial license: https://www.dynamsoft.com/CustomerPortal/Portal/Triallicense.aspx |
| 16 | +reader.init_license(license_key) |
| 17 | + |
| 18 | +#reader.init_license_from_server(license_server, license_key) |
| 19 | +#license_content = reader.output_license_to_string() |
| 20 | +#reader.init_license_from_license_content(license_key, license_content) |
| 21 | + |
| 22 | +settings = reader.get_runtime_settings() |
| 23 | +settings.intermediate_result_types = EnumIntermediateResultType.IRT_ORIGINAL_IMAGE | EnumIntermediateResultType.IRT_CONTOUR | EnumIntermediateResultType.IRT_BINARIZED_IMAGE |
| 24 | +settings.intermediate_result_saving_mode = EnumIntermediateResultSavingMode.IRSM_MEMORY |
| 25 | +error = reader.update_runtime_settings(settings) |
| 26 | +if error[0] != EnumErrorCode.DBR_OK: |
| 27 | + print(error[1]) |
| 28 | + |
| 29 | +try: |
| 30 | + text_results = reader.decode_file(image) |
| 31 | + |
| 32 | + # if your python version is equal to or higher than python3.6, you can use the following code to replace the above code |
| 33 | + # text_results:List[TextResult] = reader.decode_file(image) |
| 34 | + |
| 35 | + if text_results != None: |
| 36 | + for text_result in text_results: |
| 37 | + print("Barcode Format :") |
| 38 | + print(text_result.barcode_format_string) |
| 39 | + print("Barcode Text :") |
| 40 | + print(text_result.barcode_text) |
| 41 | + print("Localization Points : ") |
| 42 | + print(text_result.localization_result.localization_points) |
| 43 | + print("-------------") |
| 44 | + |
| 45 | + intermediate_results = reader.get_all_intermediate_results() |
| 46 | + |
| 47 | + text_results_2 = reader.decode_intermediate_results(intermediate_results) |
| 48 | + if text_results_2 != None: |
| 49 | + for text_result_2 in text_results_2: |
| 50 | + print("Barcode Format :") |
| 51 | + print(text_result_2.barcode_format_string) |
| 52 | + print("Barcode Text :") |
| 53 | + print(text_result_2.barcode_text) |
| 54 | + print("Localization Points : ") |
| 55 | + print(text_result_2.localization_result.localization_points) |
| 56 | + print("-------------") |
| 57 | + |
| 58 | +except BarcodeReaderError as bre: |
| 59 | + print(bre) |
| 60 | + |
| 61 | + |
0 commit comments