Skip to content

Commit eb5b434

Browse files
committed
ugly work around
1 parent 54f4568 commit eb5b434

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

dls_barcode/datamatrix/datamatrix.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from .read import DatamatrixByteExtractor
66
from .read import ReedSolomonDecoder
77
from .read import DatamatrixByteInterpreter
8+
from pylibdmtx.pylibdmtx import decode
89

910

1011
# We predict the location of the center of each square (pixel/bit) in the datamatrix based on the
@@ -104,6 +105,12 @@ def radius(self):
104105
return self._finder_pattern.radius
105106

106107
def _read(self, gray_image, offsets):
108+
if self.radius() >= 0.2*(gray_image.shape[0]):
109+
self._read_single(gray_image)
110+
else:
111+
self._read_old(gray_image, offsets)
112+
113+
def _read_old(self, gray_image, offsets):
107114
""" From the supplied grayscale image, attempt to read the barcode at the location
108115
given by the datamatrix finder pattern.
109116
"""
@@ -137,6 +144,23 @@ def _read(self, gray_image, offsets):
137144

138145
if self._read_ok:
139146
break
147+
148+
def _read_single(self, gray_image):
149+
try:
150+
result = decode(gray_image)
151+
if len(result) > 0:
152+
d = result[0].data
153+
decoded = d.decode('UTF-8')
154+
new_line_removed = decoded.replace("\n","")
155+
self._data = new_line_removed
156+
self._read_ok = True
157+
self._is_read_performed = True
158+
self._error_message = ""
159+
else:
160+
self._read_ok = False
161+
except(Exception) as ex:
162+
self._read_ok = False
163+
self._error_message = str(ex)
140164

141165
def draw(self, img, color):
142166
""" Draw the lines of the finder pattern on the specified image. """

tests/system_tests/test_open_scan.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ def generate_test_cases(self):
5353
# Barcode data that is expected to appear in each image of the pucks
5454
side_code_old ='DF-039'
5555

56-
side_code_new ='ASAP02'
56+
side_code_new1 ='ASAP-01'
57+
58+
side_code_new2 ='ASAP-02'
5759

5860
# List of files for Puck type 1
59-
side_testcases = [('old_side.png', side_code_old),('new_side.jpg', side_code_new)]
61+
side_testcases = [('new2.jpg', side_code_new2),('new1.png', side_code_new1),('old_side.png', side_code_old)]
6062

6163
# Create a list of test cases
6264
test_cases = []
445 KB
Loading
File renamed without changes.

0 commit comments

Comments
 (0)