Skip to content

Commit 783ea2c

Browse files
committed
modify samples
1 parent 412f235 commit 783ea2c

File tree

3 files changed

+74
-51
lines changed

3 files changed

+74
-51
lines changed

examples/camera/camera-decodevideo.py

Lines changed: 55 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,53 @@ def get_time():
2121

2222
def read_barcode():
2323
global results
24-
video_width = 640
25-
video_height = 480
26-
24+
video_width = 0
25+
video_height = 0
26+
testVideo = r"D:\Work\TestVideoOrImage\QQ视频20191202145135.mp4"
27+
28+
# vc = cv2.VideoCapture(testVideo)
2729
vc = cv2.VideoCapture(0)
30+
video_width = vc.get(cv2.CAP_PROP_FRAME_WIDTH)
31+
video_height = vc.get(cv2.CAP_PROP_FRAME_HEIGHT)
2832
vc.set(3, video_width) #set width
2933
vc.set(4, video_height) #set height
3034

35+
stride = 0
3136
if vc.isOpened():
32-
dbr.InitLicense('LICENSE-KEY')
37+
dbr.InitLicense('Input your license')
3338
rval, frame = vc.read()
39+
stride = frame.strides[0]
3440
else:
3541
return
3642

3743
windowName = "Barcode Reader"
38-
39-
max_buffer = 2
40-
max_results = 10
41-
image_format = 1 # 0: gray; 1: rgb888
42-
43-
dbr.StartVideoMode(max_buffer, max_results, video_width, video_height, image_format, onBarcodeResult)
44-
44+
parameters = dbr.InitFrameDecodingParameters()
45+
parameters["MaxQueueLength"] = 30
46+
parameters["MaxResultQueueLength"] = 30
47+
parameters["Width"] = video_width
48+
parameters["Height"] = video_height
49+
parameters["Stride"] = stride
50+
parameters["ImagePixelFormat"] = dbr.IPF_RGB_888
51+
parameters["RegionTop"] = 0
52+
parameters["RegionLeft"] = 0
53+
parameters["RegionRight"] = 100
54+
parameters["RegionBottom"] = 100
55+
parameters["RegionMeasuredByPercentage"] = 1
56+
parameters["Threshold"] = 0.01
57+
parameters["FPS"] = 0
58+
59+
60+
dbr.StartVideoMode(parameters, onBarcodeResult)
61+
62+
count = 0
4563
while True:
4664
if results != None:
47-
thickness = 2
48-
color = (0,255,0)
65+
# thickness = 2
66+
# color = (0,255,0)
4967
for result in results:
68+
# print("barcode format: " + result[0])
69+
# print("barcode text: " + result[1])
70+
print("barcode format: " + str(result["BarcodeFormat"]))
5071
print("barcode format: " + result["BarcodeFormatString"])
5172
print("barcode text: " + result["BarcodeText"])
5273
localizationResult = result["LocalizationResult"]
@@ -58,35 +79,44 @@ def read_barcode():
5879
y3 = localizationResult["Y3"]
5980
x4 = localizationResult["X4"]
6081
y4 = localizationResult["Y4"]
82+
localizationPoints = [(x1,y1),(x2,y2),(x3,y3),(x4,y4)]
83+
print(localizationPoints)
6184

62-
cv2.line(frame, (x1, y1), (x2, y2), color, thickness)
63-
cv2.line(frame, (x2, y2), (x3, y3), color, thickness)
64-
cv2.line(frame, (x3, y3), (x4, y4), color, thickness)
65-
cv2.line(frame, (x4, y4), (x1, y1), color, thickness)
66-
85+
# cv2.line(frame, (x1, y1), (x2, y2), color, thickness)
86+
# cv2.line(frame, (x2, y2), (x3, y3), color, thickness)
87+
# cv2.line(frame, (x3, y3), (x4, y4), color, thickness)
88+
# cv2.line(frame, (x4, y4), (x1, y1), color, thickness)
6789
results = None
6890

69-
cv2.imshow(windowName, frame)
7091
rval, frame = vc.read()
71-
92+
if rval == False:
93+
break
94+
# cv2.imshow(windowName, frame)
95+
96+
# if count == 1000:
97+
# break
98+
# else:
99+
# count = count + 1
100+
# print(count)
72101
# start = time.time()
73102
try:
74103
ret = dbr.AppendVideoFrame(frame)
75104
except:
76105
pass
106+
77107

78108
# cost = (time.time() - start) * 1000
79109
# print('time cost: ' + str(cost) + ' ms')
80-
81110
# 'ESC' for quit
82-
key = cv2.waitKey(1)
83-
if key == 27:
84-
break
111+
# key = cv2.waitKey(1)
112+
# if key == 27:
113+
# break
85114

86115
dbr.StopVideoMode()
87-
cv2.destroyWindow(windowName)
116+
# cv2.destroyWindow(windowName)
88117

89118

90119
if __name__ == "__main__":
91120
print("OpenCV version: " + cv2.__version__)
92121
read_barcode()
122+
print("over")

examples/camera/camera_multiprocessing.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,16 @@ def dbr_run(frame_queue, finish_queue):
2525
while finish_queue.qsize() == 0:
2626
try:
2727
inputframe = frame_queue.get_nowait()
28-
results = dbr.DecodeBuffer(inputframe)
28+
29+
results = dbr.DecodeBuffer(inputframe, inputframe.shape[0], inputframe.shape[1], inputframe.strides[0])
2930
# textResults is a list object, the following program will output each whole text result.
3031
# if you just want some individual results in textResult, you can get all keys in text result and get the value by the key.
3132
textResults = results["TextResults"]
3233
intermediateResults = results["IntermediateResults"]
3334
for textResult in textResults:
34-
print(textResult)
35-
print(textResult.keys())
3635
# print(textResult["BarcodeFormat"])
37-
# print(textResult["BarcodeFormatString"])
38-
# print(textResult["BarcodeText"])
36+
print(textResult["BarcodeFormatString"])
37+
print(textResult["BarcodeText"])
3938
# print(textResult["BarcodeBytes"])
4039
# # LocalizationResult is a dictionary object, you can use the same method as textResult to get the key-value.
4140
# print(textResult["LocalizationResult"])
@@ -47,9 +46,9 @@ def dbr_run(frame_queue, finish_queue):
4746
# print(extendedResult)
4847
# intermediateResults is a list object, the following program will output each whole intermediate result.
4948
# if you just want some individual results in intermediateResult, you can get all keys in intermediateResult and get the value by the key.
50-
for intermediateResult in intermediateResults:
51-
print(intermediateResult)
52-
print(intermediateResult.keys())
49+
# for intermediateResult in intermediateResults:
50+
# print(intermediateResult)
51+
# print(intermediateResult.keys())
5352
except:
5453
pass
5554

examples/command-line/test.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ def DecodeFile(fileName, templateName = ""):
2323
textResults = results["TextResults"]
2424
intermediateResults = results["IntermediateResults"]
2525
for textResult in textResults:
26-
print(textResult)
27-
print(textResult.keys())
2826
# print(textResult["BarcodeFormat"])
29-
# print(textResult["BarcodeFormatString"])
30-
# print(textResult["BarcodeText"])
27+
print(textResult["BarcodeFormatString"])
28+
print(textResult["BarcodeText"])
3129
# print(textResult["BarcodeBytes"])
3230
# # LocalizationResult is a dictionary object, you can use the same method as textResult to get the key-value.
3331
# print(textResult["LocalizationResult"])
@@ -39,17 +37,16 @@ def DecodeFile(fileName, templateName = ""):
3937
# print(extendedResult)
4038
# intermediateResults is a list object, the following program will output each whole intermediate result.
4139
# if you just want some individual results in intermediateResult, you can get all keys in intermediateResult and get the value by the key.
42-
for intermediateResult in intermediateResults:
43-
print(intermediateResult)
44-
print(intermediateResult.keys())
40+
# for intermediateResult in intermediateResults:
41+
# print(intermediateResult)
42+
# print(intermediateResult.keys())
4543
except Exception as err:
4644
print(err)
4745

4846
def DecodeBuffer(image, templateName = ""):
49-
results = dbr.DecodeBuffer(image, templateName)
47+
results = dbr.DecodeBuffer(image, image.shape[0], image.shape[1], image.strides[0], dbr.IPF_RGB_888, templateName)
5048
textResults = results["TextResults"]
51-
thickness = 2
52-
color = (0,255,0)
49+
5350
for textResult in textResults:
5451
print("barcode format: " + textResult["BarcodeFormatString"])
5552
print("barcode text: " + textResult["BarcodeText"])
@@ -62,14 +59,10 @@ def DecodeBuffer(image, templateName = ""):
6259
y3 = localizationResult["Y3"]
6360
x4 = localizationResult["X4"]
6461
y4 = localizationResult["Y4"]
62+
localizationPoints = [(x1,y1),(x2,y2),(x3,y3),(x4,y4)]
63+
print(localizationPoints)
6564

66-
cv2.line(image, (x1, y1), (x2, y2), color, thickness)
67-
cv2.line(image, (x2, y2), (x3, y3), color, thickness)
68-
cv2.line(image, (x3, y3), (x4, y4), color, thickness)
69-
cv2.line(image, (x4, y4), (x1, y1), color, thickness)
70-
71-
cv2.imshow("Localization", image)
72-
cv2.waitKey(0)
65+
# cv2.waitKey(0)
7366

7467
def DecodeFileStream(imagePath, templateName = ""):
7568
with open(imagePath, "rb") as fread:
@@ -100,5 +93,6 @@ def DecodeFileStream(imagePath, templateName = ""):
10093
ret = dbr.UpdataRuntimeSettings(params)
10194

10295
DecodeFile(barcode_image)
103-
image = cv2.imread(barcode_image, 1)
96+
image = cv2.imread(barcode_image)
10497
DecodeBuffer(image)
98+
print("Over")

0 commit comments

Comments
 (0)