Skip to content

Commit 770867b

Browse files
committed
repair a bug( memory leak )
1 parent 9f3f59e commit 770867b

4 files changed

Lines changed: 545 additions & 107 deletions

File tree

examples/command-line/test_DecodeFile.py

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,37 @@ def InitLicense(license):
99
dbr.InitLicense(license)
1010

1111
def DecodeFile(fileName):
12-
results = dbr.DecodeFile(fileName)
13-
textResults = results["TextResults"]
14-
# intermediateResults = results["IntermediateResults"]
15-
print(len(textResults))
16-
for textResult in textResults:
17-
print(textResult["BarcodeFormatString"])
18-
print(textResult["BarcodeText"])
19-
localizationResult = textResult["LocalizationResult"]
20-
x1 = localizationResult["X1"]
21-
y1 = localizationResult["Y1"]
22-
x2 = localizationResult["X2"]
23-
y2 = localizationResult["Y2"]
24-
x3 = localizationResult["X3"]
25-
y3 = localizationResult["Y3"]
26-
x4 = localizationResult["X4"]
27-
y4 = localizationResult["Y4"]
28-
localizationPoints = [(x1,y1),(x2,y2),(x3,y3),(x4,y4)]
29-
print(localizationPoints)
12+
try:
13+
results = dbr.DecodeFile(fileName)
14+
textResults = results["TextResults"]
15+
resultsLength = len(textResults)
16+
print("count: " + str(resultsLength))
17+
if resultsLength != 0:
18+
for textResult in textResults:
19+
print(textResult["BarcodeFormatString"])
20+
print(textResult["BarcodeText"])
21+
localizationResult = textResult["LocalizationResult"]
22+
x1 = localizationResult["X1"]
23+
y1 = localizationResult["Y1"]
24+
x2 = localizationResult["X2"]
25+
y2 = localizationResult["Y2"]
26+
x3 = localizationResult["X3"]
27+
y3 = localizationResult["Y3"]
28+
x4 = localizationResult["X4"]
29+
y4 = localizationResult["Y4"]
30+
localizationPoints = [(x1,y1),(x2,y2),(x3,y3),(x4,y4)]
31+
print(localizationPoints)
32+
else :
33+
print("No barcode detected")
34+
except Exception as err:
35+
print(err)
3036

3137

3238
if __name__ == "__main__":
3339

3440
#you can change the following two variables' value to your own value.
3541
licenseKey = "Input your own license"
36-
fileName = r"D:\Work\Python\python-barcode\images\test.jpg"
42+
fileName = r"F:\Work\TestVideoOrImage\IN1910101311400312803-01.jpg"
3743

3844
InitLicense(licenseKey)
3945
DecodeFile(fileName)

examples/command-line/test_DecodeImagesInFolder.py

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
LICENSE_KEY = "Input your own license"
12-
PATH_TO_IMAGEs = r'D:\DBR\DBR7.2.2\DLL\Images'
12+
PATH_TO_IMAGEs = r'F:\Work\TestVideoOrImage\code128\code128'
1313

1414
def dynamsoftReader (fileName, key):
1515

@@ -19,30 +19,37 @@ def dynamsoftReader (fileName, key):
1919

2020
# image = cv2.imread(fileName)
2121
# results = dbr.DecodeBuffer(image, image.shape[0], image.shape[1], image.strides[0])
22-
23-
results = dbr.DecodeFile(fileName)
24-
25-
if results:
26-
textResults = results["TextResults"]
27-
for textResult in textResults:
28-
print("BarcodeFormat : " + textResult["BarcodeFormatString"])
29-
print("BarcodeText : " + textResult["BarcodeText"])
30-
localizationResult = textResult["LocalizationResult"]
31-
x1 = localizationResult["X1"]
32-
y1 = localizationResult["Y1"]
33-
x2 = localizationResult["X2"]
34-
y2 = localizationResult["Y2"]
35-
x3 = localizationResult["X3"]
36-
y3 = localizationResult["Y3"]
37-
x4 = localizationResult["X4"]
38-
y4 = localizationResult["Y4"]
39-
localizationPoints = [(x1,y1),(x2,y2),(x3,y3),(x4,y4)]
40-
print("LocalizationPoints : " + str(localizationPoints))
41-
else:
42-
print('No Barcode Found.')
22+
try:
23+
results = dbr.DecodeFile(fileName)
24+
25+
if results:
26+
textResults = results["TextResults"]
27+
textResultsLength = len(textResults)
28+
if textResultsLength != 0:
29+
for textResult in textResults:
30+
print("BarcodeFormat : " + textResult["BarcodeFormatString"])
31+
print("BarcodeText : " + textResult["BarcodeText"])
32+
localizationResult = textResult["LocalizationResult"]
33+
x1 = localizationResult["X1"]
34+
y1 = localizationResult["Y1"]
35+
x2 = localizationResult["X2"]
36+
y2 = localizationResult["Y2"]
37+
x3 = localizationResult["X3"]
38+
y3 = localizationResult["Y3"]
39+
x4 = localizationResult["X4"]
40+
y4 = localizationResult["Y4"]
41+
localizationPoints = [(x1,y1),(x2,y2),(x3,y3),(x4,y4)]
42+
print("LocalizationPoints : " + str(localizationPoints))
43+
else:
44+
print('No Barcode Found.')
45+
else:
46+
print('No Barcode Found.')
47+
except Exception as err:
48+
print(err)
4349

4450

4551
for idx, img in enumerate(glob.glob(os.path.join(PATH_TO_IMAGEs, "*.*"))):
52+
print(img)
4653
print('Test', idx+1)
4754
print(40*'#')
4855
print('Dynamsoft Barcode Reader 7.2.0.09242:')

examples/command-line/test_DecodeLocalVideo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def read_barcode():
2323
global results
2424
video_width = 0
2525
video_height = 0
26-
testVideo = r"D:\Work\TestVideoOrImage\20191202145135.mp4"
26+
testVideo = r"F:\Work\TestVideoOrImage\(QRCODE)JavaScript Barcode Reader Demo.mp4"
2727

2828
vc = cv2.VideoCapture(testVideo)
2929
video_width = vc.get(cv2.CAP_PROP_FRAME_WIDTH)

0 commit comments

Comments
 (0)