forked from Dynamsoft/barcode-reader-python-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_DecodeFileInMemory.py
More file actions
56 lines (46 loc) · 2.12 KB
/
test_DecodeFileInMemory.py
File metadata and controls
56 lines (46 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import sys
from typing import List
from dbr import *
# you can change the following variables' value to your own value.
license_key = "Input your own license"
json_file = r"Please input your own template path"
image = r"Please input your own image path"
reader = BarcodeReader()
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=github
reader.init_license(license_key)
## The code snippet below shows how to use the full license in DBR 8.x:
# connection_paras = BarcodeReader.init_lts_connection_parameters()
## If DBR service is already built on your server, you can fill in the address of your server, or leave this property's default value.
# connection_paras.main_server_url = "Input your own server url"
# connection_paras.handshake_code = "Input your own handshake"
# connection_paras.deployment_type = EnumDMDeploymentType.DM_DT_DESKTOP
# connection_paras.uuid_generation_method = EnumDMUUIDGenerationMethod.DM_UUIDGM_RANDOM
# try:
# error = BarcodeReader.init_license_from_lts(connection_paras)
# if error[0] != EnumErrorCode.DBR_OK:
# print(error[1])
# except BarcodeReaderError as bre:
# print(bre)
error = reader.init_runtime_settings_with_file(json_file)
if error[0] != EnumErrorCode.DBR_OK:
print(error[1])
with open(image, "rb") as fread:
total = fread.read()
try:
text_results = reader.decode_file_stream(bytearray(total))
# if your python version is equal to or higher than python3.6, you can use the following code to replace the above code
# text_results:List[TextResult] = reader.decode_file_stream(bytearray(total))
if text_results != None:
for text_result in text_results:
print("Barcode Format : ")
print(text_result.barcode_format_string)
print("Barcode Text : ")
print(text_result.barcode_text)
print("Localization Points : ")
print(text_result.localization_result.localization_points)
print("Exception : ")
print(text_result.exception)
print("-------------")
except BarcodeReaderError as bre:
print(bre)