|
1 | | -from dbr import * |
| 1 | +from dynamsoft_capture_vision_bundle import * |
2 | 2 | import flet as ft |
3 | 3 | import pathlib |
4 | 4 | import google.generativeai as genai |
5 | 5 | import google.ai.generativelanguage as glm |
6 | 6 |
|
7 | | -license_key = "LICENSE-KEY" |
8 | | -BarcodeReader.init_license(license_key) |
9 | | -reader = BarcodeReader() |
| 7 | +license_key = "DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==" |
| 8 | +cvr_instance = CaptureVisionRouter() |
| 9 | +error_code, error_message = LicenseManager.init_license(license_key) |
| 10 | +if error_code != EnumErrorCode.EC_OK and error_code != EnumErrorCode.EC_LICENSE_CACHE_USED: |
| 11 | + print("License initialization failed: ErrorCode:", |
| 12 | + error_code, ", ErrorString:", error_message) |
10 | 13 |
|
11 | 14 | # https://ai.google.dev/tutorials/python_quickstart |
12 | 15 | genai.configure(api_key='API_KEY') |
@@ -99,26 +102,24 @@ def pick_files_result(e: ft.FilePickerResultEvent): |
99 | 102 | page.pubsub.send_all( |
100 | 103 | Message("Me", image_path, message_type="chat_message", is_image=True)) |
101 | 104 |
|
102 | | - text_results = None |
103 | | - try: |
104 | | - text_results = reader.decode_file(image_path) |
105 | | - |
106 | | - # if text_results != None: |
107 | | - # for text_result in text_results: |
108 | | - # print("Barcode Format : ") |
109 | | - # print(text_result.barcode_format_string) |
110 | | - # print("Barcode Text : ") |
111 | | - # print(text_result.barcode_text) |
112 | | - # print("Localization Points : ") |
113 | | - # print(text_result.localization_result.localization_points) |
114 | | - # print("Exception : ") |
115 | | - # print(text_result.exception) |
116 | | - # print("-------------") |
117 | | - except BarcodeReaderError as bre: |
118 | | - print(bre) |
119 | | - |
120 | | - if text_results != None: |
121 | | - barcode_text = text_results[0].barcode_text |
| 105 | + result = cvr_instance.capture(image_path, EnumPresetTemplate.PT_READ_BARCODES.value) |
| 106 | + |
| 107 | + if result.get_error_code() != EnumErrorCode.EC_OK: |
| 108 | + print("Error:", result.get_error_code(), |
| 109 | + result.get_error_string()) |
| 110 | + else: |
| 111 | + items = result.get_items() |
| 112 | + barcode_text = "" |
| 113 | + for item in items: |
| 114 | + format_type = item.get_format_string() |
| 115 | + text = item.get_text() |
| 116 | + print("Barcode Format:", format_type) |
| 117 | + print("Barcode Text:", text) |
| 118 | + barcode_text += text + " " |
| 119 | + |
| 120 | + if barcode_text == "": |
| 121 | + barcode_text = "No barcode found" |
| 122 | + |
122 | 123 | page.pubsub.send_all( |
123 | 124 | Message("DBR", barcode_text, message_type="chat_message")) |
124 | 125 |
|
|
0 commit comments