Skip to content

Commit f1c4d4a

Browse files
authored
Merge pull request #29 from ZoroWang/master
Update to 8.1
2 parents 31067eb + 5d919cb commit f1c4d4a

11 files changed

+476
-107
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
- [Contact Us](#contact-us)
3030

3131
### Version
32-
- **8.0.1**
32+
33+
- **8.1**
3334

3435
### Supported Platforms
3536
- **Windows x64**
@@ -142,12 +143,14 @@ if sys.version_info.major == 3 and sys.version_info.minor >= 6:
142143
143144
if text_results != None:
144145
for text_result in text_results:
145-
print("Barcode Format :")
146+
print("Barcode Format : ")
146147
print(text_result.barcode_format_string)
147-
print("Barcode Text :")
148+
print("Barcode Text : ")
148149
print(text_result.barcode_text)
149150
print("Localization Points : ")
150151
print(text_result.localization_result.localization_points)
152+
print("Exception : ")
153+
print(text_result.exception)
151154
print("-------------")
152155
except BarcodeReaderError as bre:
153156
print(bre)
@@ -158,12 +161,14 @@ else:
158161
159162
if text_results != None:
160163
for text_result in text_results:
161-
print("Barcode Format :")
164+
print("Barcode Format : ")
162165
print(text_result.barcode_format_string)
163166
print("Barcode Text :")
164167
print(text_result.barcode_text)
165168
print("Localization Points : ")
166169
print(text_result.localization_result.localization_points)
170+
print("Exception : ")
171+
print(text_result.exception)
167172
print("-------------")
168173
except BarcodeReaderError as bre:
169174
print(bre)

demo/BarcodeReaderDemo.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,16 @@ def decode_file(path):
153153
for text_result in text_results:
154154
print("-------------")
155155
print('Barcode {0}'.format(i))
156-
print("Barcode Format :")
156+
print("Barcode Format : ")
157157
print(text_result.barcode_format_string)
158-
print("Barcode Text :")
158+
print("Barcode Text : ")
159159
print(text_result.barcode_text)
160-
print("Barcode Bytes :")
160+
print("Barcode Bytes : ")
161161
print(text_result.barcode_bytes)
162162
print("Localization Points : ")
163163
print(text_result.localization_result.localization_points)
164+
print("Exception : ")
165+
print(text_result.exception)
164166
print("-------------")
165167
i = i + 1
166168
else:

demo/DecodeVideoDemo.py

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
import os
2+
import sys
3+
import time
4+
from dbr import *
5+
import cv2
6+
7+
8+
reader = BarcodeReader()
9+
10+
results = None
11+
12+
13+
Template_Settings = {
14+
'1': '{"ImageParameter":{'
15+
'"Name":"BestCoverage",'
16+
'"DeblurLevel":9,'
17+
'"ExpectedBarcodesCount":512,'
18+
'"ScaleDownThreshold":100000,'
19+
'"LocalizationModes":['
20+
'{"Mode":"LM_CONNECTED_BLOCKS"},'
21+
'{"Mode":"LM_SCAN_DIRECTLY"},'
22+
'{"Mode":"LM_STATISTICS"},'
23+
'{"Mode":"LM_LINES"},'
24+
'{"Mode":"LM_STATISTICS_MARKS"}],'
25+
'"GrayscaleTransformationModes":['
26+
'{"Mode":"GTM_ORIGINAL"},'
27+
'{"Mode":"GTM_INVERTED"}]'
28+
'}'
29+
'}',
30+
'2': '{"ImageParameter":{'
31+
'"Name":"BestSpeed",'
32+
'"DeblurLevel":3,'
33+
'"ExpectedBarcodesCount":512,'
34+
'"LocalizationModes":['
35+
'{"Mode":"LM_SCAN_DIRECTLY"}],'
36+
'"TextFilterModes":['
37+
'{"MinImageDimension":262144,"Mode":"TFM_GENERAL_CONTOUR"}]'
38+
'}'
39+
'}',
40+
'3': '{"ImageParameter":{'
41+
'"Name":"Balance",'
42+
'"DeblurLevel":5,'
43+
'"ExpectedBarcodesCount":512,'
44+
'"LocalizationModes":['
45+
'{"Mode":"LM_CONNECTED_BLOCKS"},'
46+
'{"Mode":"LM_STATISTICS"}]'
47+
'}'
48+
'}'
49+
}
50+
51+
52+
class SubTextResultResultCallBack(TextResultResultCallBack):
53+
@staticmethod
54+
def text_results_callback_func(frame_id, t_results, user_data):
55+
print(frame_id)
56+
global results
57+
results = t_results
58+
59+
60+
def init_runtime_settings():
61+
while True:
62+
print()
63+
print("Step 1: Choose a template settings : ")
64+
print("\t 1: Best Coverage Settings")
65+
print("\t 2: Best Speed Settings")
66+
print("\t 3: Balance Settings")
67+
item = input()
68+
69+
if str(item) == 'q' or str(item) == 'Q':
70+
print('Bye, looking forward to your next use.')
71+
exit()
72+
73+
if str(item) not in Template_Settings.keys():
74+
print('Please choose a valid number.')
75+
continue
76+
else:
77+
reader.init_runtime_settings_with_string(Template_Settings[item])
78+
break
79+
80+
81+
def get_video_path():
82+
while True:
83+
print()
84+
print("Step 2: Choose the way to get video : ")
85+
print("\t 1: Camera")
86+
print("\t 2: Video file")
87+
print()
88+
item = input()
89+
90+
if str(item) is 'q' or str(item) is 'Q':
91+
print('Bye, looking forward to your next use.')
92+
exit()
93+
elif str(item) is not '1' and str(item) is not '2':
94+
print('Please choose a valid number.')
95+
continue
96+
else:
97+
if str(item) is '1':
98+
video_file = 0
99+
return video_file
100+
else:
101+
while True:
102+
print()
103+
print("Step 3: Input the path to the video file : ")
104+
print()
105+
video_file = input()
106+
if video_file == 'q' or video_file == 'Q':
107+
print('Bye, looking forward to your next use.')
108+
exit()
109+
if not os.path.exists(video_file):
110+
print("The video file doesn't exist , please input a valid path.")
111+
continue
112+
else:
113+
return video_file
114+
115+
116+
def read_barcode():
117+
global results
118+
video_width = 0
119+
video_height = 0
120+
121+
video_file = get_video_path()
122+
123+
vc = cv2.VideoCapture(video_file)
124+
video_width = vc.get(cv2.CAP_PROP_FRAME_WIDTH)
125+
video_height = vc.get(cv2.CAP_PROP_FRAME_HEIGHT)
126+
vc.set(3, video_width) #set width
127+
vc.set(4, video_height) #set height
128+
129+
stride = 0
130+
if vc.isOpened():
131+
rval, frame = vc.read()
132+
stride = frame.strides[0]
133+
else:
134+
return
135+
136+
windowName = "Barcode Reader"
137+
138+
parameters = reader.init_frame_decoding_parameters()
139+
# you can modify these following parameters.
140+
parameters.max_queue_length = 30
141+
parameters.max_result_queue_length = 30
142+
parameters.width = video_width
143+
parameters.height = video_height
144+
parameters.stride = stride
145+
parameters.image_pixel_format = EnumImagePixelFormat.IPF_RGB_888
146+
parameters.region_top = 0
147+
parameters.region_bottom = 100
148+
parameters.region_left = 0
149+
parameters.region_right = 100
150+
parameters.region_measured_by_percentage = 1
151+
parameters.threshold = 0.01
152+
parameters.fps = 0
153+
parameters.auto_filter = 1
154+
155+
reader.start_video_mode(parameters, SubTextResultResultCallBack.text_results_callback_func)
156+
157+
while True:
158+
if results != None:
159+
thickness = 2
160+
color = (0,255,0)
161+
for result in results:
162+
text_result = TextResult(result)
163+
print("Barcode Format : ")
164+
print(text_result.barcode_format_string)
165+
print("Barcode Text : ")
166+
print(text_result.barcode_text)
167+
print("Localization Points : ")
168+
print(text_result.localization_result.localization_points)
169+
print("Exception : ")
170+
print(text_result.exception)
171+
print("-------------")
172+
173+
points = text_result.localization_result.localization_points
174+
175+
cv2.line(frame, points[0], points[1], color, thickness)
176+
cv2.line(frame, points[1], points[2], color, thickness)
177+
cv2.line(frame, points[2], points[3], color, thickness)
178+
cv2.line(frame, points[3], points[0], color, thickness)
179+
cv2.putText(frame, text_result.barcode_text, points[0], cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0,0,255))
180+
results = None
181+
182+
cv2.imshow(windowName, frame)
183+
rval, frame = vc.read()
184+
if rval == False:
185+
break
186+
187+
try:
188+
ret = reader.append_video_frame(frame)
189+
except:
190+
pass
191+
192+
# 'ESC' for quit
193+
key = cv2.waitKey(1)
194+
if key == 27:
195+
break
196+
197+
reader.stop_video_mode()
198+
cv2.destroyWindow(windowName)
199+
200+
201+
if __name__ == '__main__':
202+
203+
# you can change the following variables' value to your own value.
204+
license_key = "Input your own license"
205+
206+
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense
207+
reader.init_license(license_key)
208+
209+
## The code snippet below shows how to use the full license in DBR 8.x:
210+
# connection_paras = BarcodeReader.init_lts_connection_parameters()
211+
## 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.
212+
# connection_paras.main_server_url = "Input your own server url"
213+
# connection_paras.handshake_code = "Input your own handshake"
214+
# connection_paras.deployment_type = EnumDMDeploymentType.DM_DT_DESKTOP
215+
# connection_paras.uuid_generation_method = EnumDMUUIDGenerationMethod.DM_UUIDGM_RANDOM
216+
# try:
217+
# error = BarcodeReader.init_license_from_lts(connection_paras)
218+
# if error[0] != EnumErrorCode.DBR_OK:
219+
# print(error[1])
220+
# except BarcodeReaderError as bre:
221+
# print(bre)
222+
223+
print("*************************************************")
224+
print("Welcome to Dynamsoft Barcode Reader DecodeVideoDemo")
225+
print("*************************************************")
226+
print("Hints: Please input 'Q'or 'q' to quit the application.")
227+
print()
228+
229+
init_runtime_settings()
230+
231+
read_barcode()
232+
print("-------------------over------------------------")

samples/test_DecodeFile.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@
4040

4141
if text_results != None:
4242
for text_result in text_results:
43-
print("Barcode Format :")
43+
print("Barcode Format : ")
4444
print(text_result.barcode_format_string)
45-
print("Barcode Text :")
45+
print("Barcode Text : ")
4646
print(text_result.barcode_text)
4747
print("Localization Points : ")
4848
print(text_result.localization_result.localization_points)
49+
print("Exception : ")
50+
print(text_result.exception)
4951
print("-------------")
5052
except BarcodeReaderError as bre:
5153
print(bre)

samples/test_DecodeFileInMemory.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@
4242

4343
if text_results != None:
4444
for text_result in text_results:
45-
print("Barcode Format :")
45+
print("Barcode Format : ")
4646
print(text_result.barcode_format_string)
47-
print("Barcode Text :")
47+
print("Barcode Text : ")
4848
print(text_result.barcode_text)
4949
print("Localization Points : ")
5050
print(text_result.localization_result.localization_points)
51+
print("Exception : ")
52+
print(text_result.exception)
5153
print("-------------")
5254
except BarcodeReaderError as bre:
5355
print(bre)

samples/test_DecodeImageBufferByOpencv.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,24 @@
3838

3939
try:
4040
text_results = reader.decode_buffer(image)
41+
# buffer = image.tobytes()
42+
# height = image.shape[0]
43+
# width = image.shape[1]
44+
# stride = image.strides[0]
45+
# text_results = reader.decode_buffer_manually(buffer, width, height, stride, EnumImagePixelFormat.IPF_RGB_888, "")
4146
# if your python version is equal to or higher than python3.6, you can use the following code to replace the above code
4247
# text_results:List[TextResult] = reader.decode_buffer(image)
4348

4449
if text_results != None:
4550
for text_result in text_results:
46-
print("Barcode Format :")
51+
print("Barcode Format : ")
4752
print(text_result.barcode_format_string)
48-
print("Barcode Text :")
53+
print("Barcode Text : ")
4954
print(text_result.barcode_text)
5055
print("Localization Points : ")
5156
print(text_result.localization_result.localization_points)
57+
print("Exception : ")
58+
print(text_result.exception)
5259
print("-------------")
5360
except BarcodeReaderError as bre:
5461
print(bre)

samples/test_DecodeImagesInFolder.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@
4747

4848
if text_results != None:
4949
for text_result in text_results:
50-
print("Barcode Format :")
50+
print("Barcode Format : ")
5151
print(text_result.barcode_format_string)
52-
print("Barcode Text :")
52+
print("Barcode Text : ")
5353
print(text_result.barcode_text)
5454
print("Localization Points : ")
5555
print(text_result.localization_result.localization_points)
56+
print("Exception : ")
57+
print(text_result.exception)
5658
print("-------------")
5759
except BarcodeReaderError as bre:
5860
print(bre)

0 commit comments

Comments
 (0)