Skip to content

Commit 864ba87

Browse files
committed
add some samples
1 parent a7f2d1b commit 864ba87

13 files changed

+719
-6
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import os
2+
import json
3+
from dbr import DynamsoftBarcodeReader
4+
dbr = DynamsoftBarcodeReader()
5+
6+
import cv2
7+
import sys
8+
sys.path.append('../')
9+
10+
def InitLicense(license):
11+
dbr.InitLicense(license)
12+
13+
def InitRuntimeSettingsByJsonFile(inputFileName):
14+
errorCode = dbr.InitRuntimeSettingsByJsonFile(inputFileName)
15+
if errorCode != 0:
16+
print("Failed!")
17+
else:
18+
print("Successful")
19+
20+
def AppendTemplate(appendFileName, conflictMode):
21+
errorCode = dbr.AppendTplFileToRuntimeSettings(appendFileName, conflictMode)
22+
if errorCode != 0:
23+
print("Failed!")
24+
else:
25+
print("Successful")
26+
27+
def OutputAllTemplateName():
28+
allTemplateName = dbr.GetAllTemplateNames()
29+
print(allTemplateName)
30+
31+
def OutputRuntimeSettingsToFile(outputFileName):
32+
dbr.OutputSettingsToJsonFile(outputFileName)
33+
34+
if __name__ == "__main__":
35+
36+
#you can change the following five variables' value to your own value.
37+
licenseKey = "Input your own license"
38+
inputFileName = r"D:\Work\InputFile\Input20191206-1.json"
39+
appendFileName = r"D:\Work\InputFile\Input20191206-2.json"
40+
outputFileName = r"D:\Work\OutputFile\Output20191206-2.json"
41+
#conflictMode has two optional values : dbr.CM_OVERWRITE and dbr.CM_IGNORE
42+
conflictMode = dbr.CM_OVERWRITE
43+
44+
InitLicense(licenseKey)
45+
InitRuntimeSettingsByJsonFile(inputFileName)
46+
AppendTemplate(appendFileName, dbr.CM_OVERWRITE)
47+
OutputAllTemplateName()
48+
OutputRuntimeSettingsToFile(outputFileName)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import os
2+
import json
3+
from dbr import DynamsoftBarcodeReader
4+
dbr = DynamsoftBarcodeReader()
5+
6+
import cv2
7+
import sys
8+
sys.path.append('../')
9+
10+
def InitLicense(license):
11+
dbr.InitLicense(license)
12+
13+
def InitRuntimeSettingsByJsonString(inputString):
14+
errorCode = dbr.InitRuntimeSettingsByJsonString(inputString)
15+
if errorCode != 0:
16+
print("Failed!")
17+
else:
18+
print("Successful")
19+
20+
def AppendTemplateString(appendString, conflictMode):
21+
errorCode = dbr.AppendTplStringToRuntimeSettings(appendString, conflictMode)
22+
if errorCode != 0:
23+
print("Failed!")
24+
else:
25+
print("Successful")
26+
27+
def OutputAllTemplateName():
28+
allTemplateName = dbr.GetAllTemplateNames()
29+
print(allTemplateName)
30+
31+
def OutputRuntimeSettingsToString():
32+
settings = dbr.OutputSettingsToJsonString()
33+
print(settings)
34+
35+
if __name__ == "__main__":
36+
37+
#you can change the following four variables' value to your own value.
38+
licenseKey = "Input your own license"
39+
inputString = '{"ImageParameter" : { "BarcodeFormatIds" : [ "BF_ALL" ], "DeblurLevel" : 9, "Description" : "", "ExpectedBarcodesCount" : 0, "MaxAlgorithmThreadCount" : 4, "Name" : "IP_1", "Timeout" : 10000}, "Version" : "3.0"}'
40+
appendString = '{"ImageParameter" : { "BarcodeFormatIds" : [ "BF_ALL" ], "DeblurLevel" : 9, "Description" : "", "ExpectedBarcodesCount" : 15, "MaxAlgorithmThreadCount" : 2, "Name" : "IP_2", "Timeout" : 20000}, "Version" : "3.0"}'
41+
#conflictMode has two optional values : dbr.CM_OVERWRITE and dbr.CM_IGNORE
42+
conflictMode = dbr.CM_OVERWRITE
43+
44+
InitLicense(licenseKey)
45+
InitRuntimeSettingsByJsonString(inputString)
46+
AppendTemplateString(appendString, conflictMode)
47+
OutputAllTemplateName()
48+
OutputRuntimeSettingsToString()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import os
2+
import cv2
3+
import sys
4+
sys.path.append('../')
5+
from dbr import DynamsoftBarcodeReader
6+
dbr = DynamsoftBarcodeReader()
7+
8+
def InitLicense(license):
9+
dbr.InitLicense(license)
10+
11+
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)
30+
31+
32+
if __name__ == "__main__":
33+
34+
#you can change the following two variables' value to your own value.
35+
licenseKey = "Input your own license"
36+
fileName = r"D:\Work\Python\python-barcode\images\test.jpg"
37+
38+
InitLicense(licenseKey)
39+
DecodeFile(fileName)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import os
2+
import cv2
3+
import sys
4+
sys.path.append('../')
5+
from dbr import DynamsoftBarcodeReader
6+
dbr = DynamsoftBarcodeReader()
7+
8+
def InitLicense(license):
9+
dbr.InitLicense(license)
10+
11+
def DecodeFileStream(imagePath):
12+
with open(imagePath, "rb") as fread:
13+
total = fread.read()
14+
results = dbr.DecodeFileStream(bytearray(total), len(total))
15+
textResults = results["TextResults"]
16+
# intermediateResults = results["IntermediateResults"]
17+
print(len(textResults))
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+
33+
34+
if __name__ == "__main__":
35+
36+
#you can change the following two variables' value to your own value.
37+
licenseKey = "Input your own license"
38+
fileName = r"D:\Work\Python\python-barcode\images\test.jpg"
39+
40+
InitLicense(licenseKey)
41+
DecodeFileStream(fileName)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import os
2+
import cv2
3+
import sys
4+
sys.path.append('../')
5+
from dbr import DynamsoftBarcodeReader
6+
dbr = DynamsoftBarcodeReader()
7+
8+
def InitLicense(license):
9+
dbr.InitLicense(license)
10+
11+
def DecodeBuffer(imageByOpencv):
12+
results = dbr.DecodeBuffer(image, image.shape[0], image.shape[1], image.strides[0])
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)
30+
31+
32+
if __name__ == "__main__":
33+
34+
#you can change the following two variables' value to your own value.
35+
licenseKey = "Input your own license"
36+
fileName = r"D:\Work\Python\python-barcode\images\test.jpg"
37+
38+
InitLicense(licenseKey)
39+
image = cv2.imread(fileName)
40+
DecodeBuffer(fileName)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import os
2+
import random
3+
import glob
4+
import time
5+
import cv2
6+
import numpy as np
7+
8+
from dbr import DynamsoftBarcodeReader
9+
10+
11+
LICENSE_KEY = "Input your own license"
12+
PATH_TO_IMAGEs = r'D:\DBR\DBR7.2.2\DLL\Images'
13+
14+
def dynamsoftReader (fileName, key):
15+
16+
dbr = DynamsoftBarcodeReader()
17+
dbr.InitLicense(key)
18+
19+
20+
# image = cv2.imread(fileName)
21+
# 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.')
43+
44+
45+
for idx, img in enumerate(glob.glob(os.path.join(PATH_TO_IMAGEs, "*.*"))):
46+
print('Test', idx+1)
47+
print(40*'#')
48+
print('Dynamsoft Barcode Reader 7.2.0.09242:')
49+
dynamsoftReader(img, LICENSE_KEY)
50+
print(40*'#')

examples/command-line/DecodeImagesInFolder.py renamed to examples/command-line/test_DecodeImagesInFolderForSiemens.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
# %matplotlib inline
1414

15-
KEY = "t0068MgAAAE/JLbpY2i8Xz7pGt6NhN1wRL9QxaFE2kQRYi/5sq8P0uddejL4moxsvWxBAt3PmH+bxNQxnLt9AaBY+JTZOwy0="
15+
KEY = "Input your own license"
1616
PATH_TO_PARAM = r'D:\Work\test\template.txt'
1717
PATH_TO_IMAGEs = r'D:\DBR\DBR7.2.2\DLL\Images'
1818

@@ -50,7 +50,7 @@
5050
def dynamsoftReader (fileName,key, path_to_param):
5151

5252
dbr = DynamsoftBarcodeReader()
53-
dbr.initLicense(key)
53+
dbr.InitLicense(key)
5454

5555
# with open(path_to_param, 'r') as file:
5656
# params = file.read().replace('\n', '')
@@ -59,15 +59,14 @@ def dynamsoftReader (fileName,key, path_to_param):
5959
try:
6060
image = cv2.imread(fileName)
6161

62-
# results = dbr.decodeFile(fileName, dbr.BF_ALL)
62+
# results = dbr.DecodeFile(fileName)
6363
results = dbr.DecodeBuffer(image, image.shape[0], image.shape[1], image.strides[0])
6464

6565
if results:
6666
textResults = results["TextResults"]
6767
for textResult in textResults:
68-
print("BarcodeFormat: {0}".format(textResult["BarcodeFormatString"]))
69-
print("BarcodeText: {0}".format(textResult["BarcodeText"]))
70-
68+
print("BarcodeFormat : " + format(textResult["BarcodeFormatString"]))
69+
print("BarcodeText : " + format(textResult["BarcodeText"]))
7170
else:
7271
print('No Barcode Found.')
7372
except Exception as err:

0 commit comments

Comments
 (0)