Skip to content

Commit cef7627

Browse files
authored
Merge pull request #32 from ZoroWang/master
Update to 8.2
2 parents b303d0c + 5eb2642 commit cef7627

17 files changed

+211
-23
lines changed

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
![Dynamsoft](https://dynamsoft.github.io/styleguide/assets/img-icon/logo-dynamsoft-whiteBg-190x47.png "Dynamsoft") | ![dbr](https://dynamsoft.github.io/styleguide/assets/img-icon/logo-dbr-88x88.png "dbr")
77

88

9-
**[Dynamsoft's Barcode Reader SDK](https://www.dynamsoft.com/Products/Dynamic-Barcode-Reader.aspx) enables you to efficiently embed barcode reading functionality in your web, desktop or mobile application using just a few lines of code. Saving you months of added development time and resources, our SDK can create high-speed and reliable barcode scanner software applications to meet your business needs.**
9+
**[Dynamsoft's Barcode Reader SDK](https://www.dynamsoft.com/barcode-reader/overview/?utm_source=github) enables you to efficiently embed barcode reading functionality in your web, desktop or mobile application using just a few lines of code. Saving you months of added development time and resources, our SDK can create high-speed and reliable barcode scanner software applications to meet your business needs.**
1010

1111
## Dynamsoft Barcode Reader - Python Edition
1212

13-
*Dynamsoft Barcode Reader's Python Edition comes with all the general features of Dynamsoft Barcode Reader, bringing convenience for customers who develop in Python. In addition, you could refer to the Python samples available in our [Github](https://github.com/dynamsoft-dbr/python-barcode) when building your own application. If you have any inquiries about our product, please contact us at [email protected]. If you need more information, please check out our [documentation site](https://www.dynamsoft.com/barcode-reader/programming/python/).*
13+
*Dynamsoft Barcode Reader's Python Edition comes with all the general features of Dynamsoft Barcode Reader, bringing convenience for customers who develop in Python. In addition, you could refer to the Python samples available in our [Github](https://github.com/dynamsoft-dbr/python-barcode) when building your own application. If you have any inquiries about our product, please contact us at [email protected]. If you need more information, please check out our [documentation site](https://www.dynamsoft.com/barcode-reader/programming/python/?utm_source=github).*
1414

1515
## Table Of Contents
1616
- [Version](#version)
@@ -30,7 +30,7 @@
3030

3131
### Version
3232

33-
- **8.1.2**
33+
- **8.2**
3434

3535
### Supported Platforms
3636
- **Windows x64**
@@ -55,7 +55,7 @@
5555
5656
### License
5757

58-
Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense
58+
Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=github
5959

6060
### Supported Symbologies
6161
*We support all major barcodes symbologies across a variety of industries such as government, finance, retail, warehouse inventory, and healthcare.*
@@ -97,18 +97,18 @@ Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicen
9797

9898
### Release Notes
9999

100-
https://www.dynamsoft.com/barcode-reader/programming/python/?ver=latest#release-notes
100+
https://www.dynamsoft.com/barcode-reader/programming/python/?ver=latest&utm_source=github#release-notes
101101

102102
### Interfaces
103103

104104
#### Enumerations
105-
https://www.dynamsoft.com/barcode-reader/programming/python/api-reference/?ver=latest#enumerations
105+
https://www.dynamsoft.com/barcode-reader/programming/python/api-reference/?ver=latest&utm_source=github#enumerations
106106

107107
#### Classes
108-
https://www.dynamsoft.com/barcode-reader/programming/python/api-reference/?ver=latest#classes
108+
https://www.dynamsoft.com/barcode-reader/programming/python/api-reference/?ver=latest&utm_source=github#classes
109109

110110
#### Main Class Interface
111-
https://www.dynamsoft.com/barcode-reader/programming/python/api-reference/?ver=latest#barcodereader-methods
111+
https://www.dynamsoft.com/barcode-reader/programming/python/api-reference/?ver=latest&utm_source=github#barcodereader-methods
112112

113113
### Appendix
114114

demo/BarcodeReaderDemo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def decode_files(path):
186186

187187
license_key = "Input your own license"
188188

189-
# Apply for a trial license: https://www.dynamsoft.com/CustomerPortal/Portal/Triallicense.aspx
189+
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=github
190190
reader.init_license(license_key)
191191

192192
## The code snippet below shows how to use the full license in DBR 8.x:

demo/DecodeVideoDemo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def read_barcode():
203203
# you can change the following variables' value to your own value.
204204
license_key = "Input your own license"
205205

206-
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense
206+
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=github
207207
reader.init_license(license_key)
208208

209209
## The code snippet below shows how to use the full license in DBR 8.x:

samples/test_AppendTemplateFile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
reader = BarcodeReader()
1717

18-
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense
18+
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=github
1919
reader.init_license(license_key)
2020

2121
## The code snippet below shows how to use the full license in DBR 8.x:

samples/test_AppendTemplateString.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
reader = BarcodeReader()
1414

15-
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense
15+
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=github
1616
reader.init_license(license_key)
1717

1818
## The code snippet below shows how to use the full license in DBR 8.x:

samples/test_DecodeFile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
reader = BarcodeReader()
1313

14-
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense
14+
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=github
1515
reader.init_license(license_key)
1616

1717
## The code snippet below shows how to use the full license in DBR 8.x:

samples/test_DecodeFileInMemory.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
reader = BarcodeReader()
1212

13-
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense
13+
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=github
1414
reader.init_license(license_key)
1515

1616
## The code snippet below shows how to use the full license in DBR 8.x:

samples/test_DecodeImageBufferByOpencv.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
reader = BarcodeReader()
1616

17-
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense
17+
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=github
1818
reader.init_license(license_key)
1919

2020
## The code snippet below shows how to use the full license in DBR 8.x:

samples/test_DecodeImagesInFolder.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
reader = BarcodeReader()
1616

17-
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense
17+
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=github
1818
reader.init_license(license_key)
1919

2020
## The code snippet below shows how to use the full license in DBR 8.x:

samples/test_DecodeIntermediateResults.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
reader = BarcodeReader()
1313

14-
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense
14+
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=github
1515
reader.init_license(license_key)
1616

1717
## The code snippet below shows how to use the full license in DBR 8.x:

samples/test_DecodeLocalVideo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def read_barcode():
138138

139139
print("-------------------start------------------------")
140140

141-
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense
141+
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=github
142142
reader.init_license(license_key)
143143

144144
## The code snippet below shows how to use the full license in DBR 8.x:

samples/test_DecodeLocalVideos.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def read_barcode(video_path):
147147

148148
print("-------------------start------------------------")
149149

150-
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense
150+
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=github
151151
reader.init_license(license_key)
152152

153153
## The code snippet below shows how to use the full license in DBR 8.x:

samples/test_DecodeVideoByCamera.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def read_barcode():
142142

143143
print("-------------------start------------------------")
144144

145-
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense
145+
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=github
146146
reader.init_license(license_key)
147147

148148
## The code snippet below shows how to use the full license in DBR 8.x:

samples/test_DecodeVideoByPiCamera.py

+188
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
import os
2+
import sys
3+
import time
4+
import io
5+
import numpy as np
6+
from picamera import PiCamera
7+
from picamera.array import PiRGBArray
8+
from dbr import *
9+
import cv2
10+
11+
# you can change the following variables' value to your own value.
12+
license_key = "Input your own license"
13+
json_file = r"Please input your own template path"
14+
15+
reader = BarcodeReader()
16+
17+
def intermediate_results_callback_func(frame_id, i_results, user_data):
18+
print(frame_id)
19+
for result in i_results:
20+
intermediate_result = IntermediateResult(result)
21+
print('Intermediate Result data type : {0}'.format(intermediate_result.result_type))
22+
print('Intermediate Result data : {0}'.format(intermediate_result.results))
23+
print("-------------")
24+
## Or you can inherit the abstract class IntermediateResultCallBack to implement the abstract method intermediate_results_callback_func.
25+
# class SubIntermediateResultCallBack(IntermediateResultCallBack):
26+
# @staticmethod
27+
# def intermediate_results_callback_func(frame_id, i_results, user_data):
28+
# print(frame_id)
29+
# for result in i_results:
30+
# intermediate_result = IntermediateResult(result)
31+
# print('Intermediate Result data type : {0}'.format(intermediate_result.result_type))
32+
# print('Intermediate Result data : {0}'.format(intermediate_result.results))
33+
# print("-------------")
34+
35+
36+
def text_results_callback_func(frame_id, t_results, user_data):
37+
print(frame_id)
38+
for result in t_results:
39+
text_result = TextResult(result)
40+
print("Barcode Format : ")
41+
print(text_result.barcode_format_string)
42+
print("Barcode Text : ")
43+
print(text_result.barcode_text)
44+
print("Localization Points : ")
45+
print(text_result.localization_result.localization_points)
46+
print("Exception : ")
47+
print(text_result.exception)
48+
print("-------------")
49+
## Or you can inherit the abstract class TextResultResultCallBack to implement the abstract method text_results_callback_func.
50+
# class SubTextResultResultCallBack(TextResultResultCallBack):
51+
# @staticmethod
52+
# def text_results_callback_func(frame_id, t_results, user_data):
53+
# print(frame_id)
54+
# for result in t_results:
55+
# text_result = TextResult(result)
56+
# print("Barcode Format : ")
57+
# print(text_result.barcode_format_string)
58+
# print("Barcode Text : ")
59+
# print(text_result.barcode_text)
60+
# print("Localization Points : ")
61+
# print(text_result.localization_result.localization_points)
62+
# print("Exception : ")
63+
# print(text_result.exception)
64+
# print("-------------")
65+
66+
67+
def error_callback_func(frame_id, error_code, user_data):
68+
print(frame_id)
69+
error_msg = user_data.get_error_string(error_code)
70+
print('Error : {0} ; {1}'.format(error_code, error_msg))
71+
## Or you can inherit the abstract class ErrorCallBack to implement the abstract method error_callback_func.
72+
# class SubErrorCallBack(ErrorCallBack):
73+
# @staticmethod
74+
# def error_callback_func(frame_id, error_code, user_data):
75+
# print(frame_id)
76+
# error_msg = user_data.get_error_string(error_code)
77+
# print('Error : {0} ; {1}'.format(error_code, error_msg))
78+
79+
80+
def get_time():
81+
localtime = time.localtime()
82+
capturetime = time.strftime("%Y%m%d%H%M%S", localtime)
83+
return capturetime
84+
85+
def read_barcode():
86+
video_width = 0
87+
video_height = 0
88+
89+
# vc = cv2.VideoCapture(0)
90+
camera = PiCamera()
91+
camera.resolution = (1024, 1024) # Set image's width and height
92+
93+
# SetPiCameraParameters(camera):
94+
# camera.saturation = 80 # Video or Image saturation
95+
# camera.brightness = 50 # Video or Image brightness
96+
# camera.shutter_speed = 6000000 # The shutter speed
97+
# camera.iso = 800 # ISO
98+
# camera.sharpness = 0 # Image Sharpness
99+
# camera.hflip = True # Whether to flip horizontally
100+
# camera.vflip = True # Whether to flip vertically
101+
# camera.rotation = 0 # Whether to rotate image
102+
# camera.resolution = (280, 160) # Set image's width and height
103+
104+
105+
video_width = camera.resolution[0]
106+
video_height = camera.resolution[1]
107+
print(camera.resolution)
108+
109+
stride = 0
110+
stream = io.BytesIO()
111+
camera.capture(stream, format='jpeg')
112+
# create numpy by stream
113+
data = np.frombuffer(stream.getvalue(), dtype=np.uint8)
114+
# decode numpy by opencv
115+
image = cv2.imdecode(data, 1)
116+
stride = image.strides[0]
117+
print(stride)
118+
rawCapture = PiRGBArray(camera, size=(video_width, video_height))
119+
120+
windowName = "Barcode Reader"
121+
122+
parameters = reader.init_frame_decoding_parameters()
123+
# you can modify these following parameters.
124+
parameters.max_queue_length = 30
125+
parameters.max_result_queue_length = 30
126+
parameters.width = video_width
127+
parameters.height = video_height
128+
parameters.stride = stride
129+
parameters.image_pixel_format = EnumImagePixelFormat.IPF_RGB_888
130+
parameters.region_top = 0
131+
parameters.region_bottom = 100
132+
parameters.region_left = 0
133+
parameters.region_right = 100
134+
parameters.region_measured_by_percentage = 1
135+
parameters.threshold = 0.01
136+
parameters.fps = 0
137+
parameters.auto_filter = 1
138+
139+
reader.start_video_mode(parameters, text_results_callback_func)
140+
# reader.start_video_mode(parameters, SubTextResultResultCallBack.text_results_callback_func)
141+
## You can use three callbacks at the same time.
142+
# reader.start_video_mode(parameters, text_results_callback_func, "", intermediate_results_callback_func, error_callback_func, reader)
143+
# reader.start_video_mode(parameters, SubTextResultResultCallBack.text_results_callback_func, "", SubIntermediateResultCallBack.intermediate_results_callback_func, SubErrorCallBack.error_callback_func, reader)
144+
145+
for frame in camera.capture_continuous(rawCapture, format='bgr', use_video_port=True):
146+
image = frame.array
147+
148+
try:
149+
ret = reader.append_video_frame(image)
150+
except:
151+
pass
152+
153+
# 'ESC' for quit
154+
key = cv2.waitKey(1)
155+
# reset
156+
rawCapture.truncate(0)
157+
if key == 27:
158+
break
159+
160+
reader.stop_video_mode()
161+
cv2.destroyWindow(windowName)
162+
163+
164+
print("-------------------start------------------------")
165+
166+
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=github
167+
reader.init_license(license_key)
168+
169+
## The code snippet below shows how to use the full license in DBR 8.x:
170+
# connection_paras = BarcodeReader.init_lts_connection_parameters()
171+
## 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.
172+
# connection_paras.main_server_url = "Input your own server url"
173+
# connection_paras.handshake_code = "Input your own handshake"
174+
# connection_paras.deployment_type = EnumDMDeploymentType.DM_DT_DESKTOP
175+
# connection_paras.uuid_generation_method = EnumDMUUIDGenerationMethod.DM_UUIDGM_RANDOM
176+
# try:
177+
# error = BarcodeReader.init_license_from_lts(connection_paras)
178+
# if error[0] != EnumErrorCode.DBR_OK:
179+
# print(error[1])
180+
# except BarcodeReaderError as bre:
181+
# print(bre)
182+
183+
error = reader.init_runtime_settings_with_file(json_file)
184+
if error[0] != EnumErrorCode.DBR_OK:
185+
print(error[1])
186+
187+
read_barcode()
188+
print("-------------------over------------------------")

samples/test_InitRuntimeSettingsByFile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
reader = BarcodeReader()
1616

17-
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense
17+
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=github
1818
reader.init_license(license_key)
1919

2020
## The code snippet below shows how to use the full license in DBR 8.x:

samples/test_InitRuntimeSettingsByString.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
reader = BarcodeReader()
1313

14-
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense
14+
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=github
1515
reader.init_license(license_key)
1616

1717
## The code snippet below shows how to use the full license in DBR 8.x:

samples/test_UpdateRuntimeSettings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
reader = BarcodeReader()
1010

11-
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense
11+
# Apply for a trial license: https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=github
1212
reader.init_license(license_key)
1313

1414
## The code snippet below shows how to use the full license in DBR 8.x:

0 commit comments

Comments
 (0)