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+ # from pylibdmtx.pylibdmtx import decode
10+ # import matplotlib.pyplot as plt
11+ # import matplotlib.image as mpimg
12+
13+ # %matplotlib inline
14+
15+ KEY = "t0068MgAAAE/JLbpY2i8Xz7pGt6NhN1wRL9QxaFE2kQRYi/5sq8P0uddejL4moxsvWxBAt3PmH+bxNQxnLt9AaBY+JTZOwy0="
16+ PATH_TO_PARAM = r'D:\Work\test\template.txt'
17+ PATH_TO_IMAGEs = r'D:\DBR\DBR7.2.2\DLL\Images'
18+
19+ # def pylibdmtxReader(fileName, shrink_max):
20+
21+ # '''
22+ # Funtion that takes an image and shrink parameter
23+ # and returns the values decoded from barcodes.
24+
25+ # Input Arguments:
26+ # - image: the image
27+ # - shrink: the shrink parameter
28+ # shrink the image so that cells become one or two pixels large,
29+ # the Data Matrix will stand-out as a highly textured area,
30+ # and the gradient will strongly respond.
31+
32+ # Returns:
33+ # - barcode
34+ # '''
35+
36+
37+ # image = cv2.imread(fileName, cv2.IMREAD_UNCHANGED)
38+ # shrink = np.arange(1, shrink_max)
39+
40+ # for i in shrink:
41+ # # time.sleep(1)
42+ # barcode = decode(image, shrink = i)
43+ # while barcode!=[]:
44+ # if barcode[0].data.decode("utf-8").startswith("BF"):
45+ # return print("Barcode: {0}".format(barcode[0].data.decode("utf-8")))
46+ # break
47+ # else:
48+ # print('No Barcode Found.')
49+
50+ def dynamsoftReader (fileName ,key , path_to_param ):
51+
52+ dbr = DynamsoftBarcodeReader ()
53+ dbr .initLicense (key )
54+
55+ # with open(path_to_param, 'r') as file:
56+ # params = file.read().replace('\n', '')
57+ # ret = dbr.setParameters(params)
58+
59+ try :
60+ image = cv2 .imread (fileName )
61+
62+ # results = dbr.decodeFile(fileName, dbr.BF_ALL)
63+ results = dbr .DecodeBuffer (image , image .shape [0 ], image .shape [1 ], image .strides [0 ])
64+
65+ if results :
66+ textResults = results ["TextResults" ]
67+ for textResult in textResults :
68+ print ("BarcodeFormat: {0}" .format (textResult ["BarcodeFormatString" ]))
69+ print ("BarcodeText: {0}" .format (textResult ["BarcodeText" ]))
70+
71+ else :
72+ print ('No Barcode Found.' )
73+ except Exception as err :
74+ print (err )
75+
76+ # %time pylibdmtxReader(IMAGE,10)
77+ # %time dynamsoftReader(IMAGE,KEY,PATH_TO_PARAM)
78+
79+ for idx , img in enumerate (glob .glob (os .path .join (PATH_TO_IMAGEs , "*.*" ))):
80+ print ('Test' , idx + 1 )
81+ print (40 * '#' )
82+ #print p
83+ # image = mpimg.imread(img) # images are color images
84+ # plt.imshow(image)
85+ # plt.show()
86+ print ('pylibdmtx 0.1.9:' )
87+ # %time
88+ # pylibdmtxReader(img,10)
89+ print ()
90+ print ('Dynamsoft Barcode Reader 7.2.0.09242:' )
91+ # %time
92+ dynamsoftReader (img ,KEY ,PATH_TO_PARAM )
93+ print (40 * '#' )
94+ print ()
0 commit comments