naturalhistorymuseum / pylibdmtx Goto Github PK
View Code? Open in Web Editor NEWRead Data Matrix barcodes from Python 2 and 3.
License: MIT License
Read Data Matrix barcodes from Python 2 and 3.
License: MIT License
When I try to decode a 2D datamatrix (big or small) I get the message: Segmentation fault (core dumped).
The library worked fine just a few weeks ago on the same computer. Has anyone experienced this?
I have tried uninstalling and installing both pylibdmtx and libdmtx0a - no luck.
I am trying to implement live feed qrcode data matrix decoder similar to pyzbar but it doesn't work. So is there anyway to make it work with it?
Getting this error while trying to run pylibdmtx .encode() inside the official docker image python3.6 in docker environment :
File "/usr/local/lib/python3.6/site-packages/pylibdmtx/pylibdmtx.py", line 373, in encode encoder[0].image[0].pxl, ctypes.POINTER(ctypes.c_ubyte * size) ValueError: NULL pointer access
I'm trying to code simple strings into data matrix barcodes but I'm seeing different results between Python 2 and 3. I wrote a simple barcode and decode scripts from the examples.
This is in Linux (Ubuntu 18.04.1 and in both versions pylibdmtx is 0.1.9):
#Encode "2019" in a data matrix barcode and save it as "2019.png"
#Python 2.7.1
$ python barcode.py 2019
$ python decode.py 2019.png
[Decoded(data='2019', rect=Rect(left=9, top=10, width=48, height=49))]
#Python 3.6.7
$ python3 barcode.py 2019
$ python decode.py 2019.png
[Decoded(data='(\x1be\x03', rect=Rect(left=8, top=10, width=61, height=59))]
#Test decode.py between python2 and python3
$ python barcode.py 2019
#Python2
$ python decode.py 2019.png
[Decoded(data='2019', rect=Rect(left=9, top=10, width=48, height=49))]
#Python3
$ python3 decode.py 2019.png
[Decoded(data=b'2019', rect=Rect(left=9, top=10, width=48, height=49))]
barcode.py:
from PIL import Image
import pylibdmtx.pylibdmtx as dmtx
import sys
#Get what to encode from the command line
id = sys.argv[1]
encoded = dmtx.encode(id)
img = Image.frombytes('RGB', (encoded.width, encoded.height), encoded.pixels)
#Write image
img.save(id + '.png')
And decode.py:
from pylibdmtx.pylibdmtx import decode
from PIL import Image
import sys
#Get what to encode from the command line
img_file = sys.argv[1]
print(decode(Image.open(img_file)))
When I use the camera, there are only 1 ~ 2 frames. What's going on? My code is attached
from pylibdmtx import pylibdmtx
import cv2
capture = cv2.VideoCapture(0)
while(True):
ret, frame = capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
msg = pylibdmtx.decode(thresh)
cv2.imshow("dsds", thresh)
print(msg)
if msg:
print(msg[0].data.decode("utf-8"))
if cv2.waitKey(1) & 0xFF == ord('q'):
break
I have noticed that when attempting to decode a particular image (which does not contain a Datamatrix) that calling pylibdmtx.decode
will kill the Python process with exit code 40.
Run the following in a Python interpreter:
from PIL import Image
from pylibdmtx import pylibdmtx
pylibdmtx.decode(Image.open('bad_image.png'))
with the following image saved as bad_image.png
in the current working directory;
OS: Debian GNU/Linux testing (buster) x86_64
libdmtx version: 0.7.4
(installed from the Debian repositories and reported by apt info
as 0.7.4-2+b1
)
Python version: 3.6.0
pylibdmtx version: 0.1.7
PIL version: 5.0.0
An error should be raised, as the image does not contain a datamatrix
Python process exits with code 40
While this is almost certainly a bug in the underlying libdmtx
(I have already opened a bug report there), it is perhaps possible that this error could be caught before it hits libdmtx
, which would allow us to work around the issue for the time being. I have not looked in to the root cause sufficiently deeply to be able to tell if this is possible.
How do I encode non-text files (eg, .png, .exe, .mp3, etc). I'm trying to make a paper backup of some files.
I noticed that when I set decoding timeout on my RaspberryPi function decode() exits always after 0.0016s no matter what value I set (different from 0). When timeout is doesn't set or equals 0 function works fine. This is how I set timeout:
code = decode(image=cropped, timeout=1000)
OS is rasbian jessie, and python version is 3.6. Does anybody have the same problem? Maybe it's library fault, not wrapper?
Manual testing on a VM is painful and error-prone.
The current implementation of type checking in _pixel_data
does not detect images loaded by imageio
because these are a subclass of np.ndarray
.
Capitalizing the scheme makes both options unusable.
pylibdmtx/pylibdmtx/pylibdmtx.py
Line 345 in a425ec3
Should probably be changed to
ENCODING_SCHEME_PREFIX, scheme
When I run the decode function on a portrait image, the rects returned have negative heights.
If I rotate the image 90 degrees, making it landscape (height < width) the heights are positive again.
Is this an expected behaviour?
hallo
i have simple script which read datamatrix codes from images
image names are stored in txt file, one image name per line
there is around 500000+ images
when i run this script, it end after 10000 line or so
never do more
number of processed lines is different in every run
i checked if there is some memory leak, but it seams no
process take around 0.9% of memory, and it is not increasing
is there some limit of processed images by this module?
i can not find out why not all lines are processed
here is code of my script:
import argparse
import os
import cv2
from pylibdmtx.pylibdmtx import decode
import json
import time
def validate_filenames(parser, filename):
if not os.path.exists(filename):
parser.error("Invalid filename `{}`.".format(filename))
return filename
def read_file(filename, verbose=False):
root, ext = os.path.splitext(filename)
jsonfile = f'{root}.json'
errfile = f'{root}.json.invalid'
if not os.path.exists(jsonfile) and not os.path.exists(errfile):
decoded_data = decode(cv2.resize(cv2.rotate(cv2.imread(filename), cv2.ROTATE_180), (256, 128)))
if not decoded_data:
print(f'Nothing found in {filename}')
return
out = []
exc = False
for data in decoded_data:
decoded = {'data': data.data, 'rect': data.rect._asdict()}
try:
value = data.data.decode('utf8')
decoded['data'] = value
decoded['data'] = int(value)
except:
exc = True
out.append(decoded)
if not out:
print(f'Nothing found in {filename}')
return
if exc:
json.dump(out, open(errfile, 'w'))
if verbose:
print(f'Wrong data in {filename}')
else:
out = list(sorted(out, key=lambda x:x.get('data')))
json.dump(out, open(jsonfile, 'w'))
if verbose:
print(f'OK {filename}')
else:
if verbose:
print(f'Parsed file exists {filename}')
def read_filenames(contentfile, verbose=False):
with open(contentfile, 'r') as f:
filenames = f.read().split('\n')
if verbose:
print('Number of lines:', len(filenames))
for idx, filename in enumerate(filenames):
if verbose:
print(idx, filename)
read_file(filename, verbose=verbose)
def init_argparse() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
usage='%(prog)s <filenames>',
description=f'Read datamatrix codes from image files and store in json.'
)
parser.add_argument(
'files', metavar='filenames',
type=lambda f: validate_filenames(parser, f),
nargs='+',
help='Files to read.'
)
parser.add_argument(
'-v',
action='store_true',
dest='verbose',
default=False,
help='Print file names.'
)
return parser
def main() -> None:
parser = init_argparse()
args = parser.parse_args()
for filename in args.files:
root, ext = os.path.splitext(filename)
if ext == '.txt':
read_filenames(filename, verbose=args.verbose)
else:
read_file(filename, verbose=args.verbose)
if __name__ == "__main__":
main()
Hi. I installed pylibdmtx-0.1.7 and was able to run some of the sample code. However, I noticed some of the test scripts failed. Should I be concerned???
(testpy27) nvidia@tegra-ubuntu:~/pylibdmtx$ python pylibdmtx/tests/test_pylibdmtx.py
Traceback (most recent call last):
File "pylibdmtx/tests/test_pylibdmtx.py", line 122, in test_inconsistent_dimensions
decode, data
File "/usr/lib/python2.7/unittest/case.py", line 993, in assertRaisesRegexp
callable_obj(*args, **kwargs)
File "/home/nvidia/.virtualenvs/testpy27/lib/python2.7/site-packages/pylibdmtx/pylibdmtx.py", line 216, in decode
cast(pixels, c_ubyte_p), width, height, PACK_ORDER[bpp]
File "/usr/lib/python2.7/ctypes/init.py", line 499, in cast
return _cast(obj, obj, typ)
ArgumentError: argument 1: <type 'exceptions.TypeError'>: wrong type
Traceback (most recent call last):
File "pylibdmtx/tests/test_pylibdmtx.py", line 110, in test_unsupported_bits_per_pixel
decode, data
AssertionError: "Unsupported bits-per-pixel: [40] Should be one of [8, 16, 24, 32]" does not match "Unsupported bits-per-pixel [40]"
Ran 11 tests in 0.305s
FAILED (failures=1, errors=1)
(testpy27) nvidia@tegra-ubuntu:~/pylibdmtx$ python pylibdmtx/tests/test_dmtx_library.py
Traceback (most recent call last):
File "pylibdmtx/tests/test_dmtx_library.py", line 14, in
from pylibdmtx import dmtx_library
ImportError: cannot import name dmtx_library
Ran 1 test in 0.104s
OK
Im trying to import decode from pylibdmtx by:
from pylibdmtx.pylibdmtx import decode
but get this error:
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pylibdmtx\dmtx_library.py", line 38, in load
libdmtx = cdll.LoadLibrary(fname)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\ctypes_init_.py", line 451, in LoadLibrary
return self.dlltype(name)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\ctypes_init.py", line 373, in init
self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'libdmtx-32.dll' (or one of its dependencies). Try using the full path with constructor syntax.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "api.py", line 14, in
from pylibdmtx.pylibdmtx import decode
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pylibdmtx\pylibdmtx.py", line 10, in
from .wrapper import (
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pylibdmtx\wrapper.py", line 70, in
dmtxVersion = libdmtx_function('dmtxVersion', c_char_p)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pylibdmtx\wrapper.py", line 58, in libdmtx_function
return prototype((fname, load_libdmtx()))
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pylibdmtx\wrapper.py", line 39, in load_libdmtx
LIBDMTX = dmtx_library.load()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pylibdmtx\dmtx_library.py", line 40, in load
libdmtx = cdll.LoadLibrary(
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\ctypes_init.py", line 451, in LoadLibrary
return self.dlltype(name)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\ctypes_init.py", line 373, in init
self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pylibdmtx\libdmtx-32.dll' (or one of its dependencies). Try using the full path with constructor syntax.
This issue is duplicated in the original libdmtx repo, see here.
I have been struggling to read some of my data matrices which looked pretty decent in terms of quality. I did quite few enhancement like cv2.fastNlMeansDenoisingColored, cv2.threshold and so on. With these improvements I have had some success, but still missing quite few readings. It was funny that I could read some of my blurred, partly damaged data matrices, but missing good ones. It was rather a random behavior to be honest.
Until I learned that decode function takes quite a few number of parameters:
decode(
image,
timeout=None,
gap_size=None,
shrink=1,
shape=None,
deviation=None,
threshold=None,
min_edge=None,
max_edge=None,
corrections=None,
max_count=None,
)
BUT there are not documentations what these arguments are. Some surely can be guessed, but others I could not guess what values to put in. A better documentation would be really appreciated. The reason I emphasize having one that, in my case, I came across this post in stackoverflow, and shrink was one recommended to play with. I started seeing magic. I basically, out of blue, screened some values shrink = np.arange(1,10)
and I could read the data matrices that I was struggling with. The problem is that now it is not fixed shrink value, sometimes higher value, sometimes lower! I have to scan for each reading this range!
This bring to the significance of knowing more about arguments of this function!
I'm using this on a RPi4 running Ubuntu 18. This is in a jupyter notebook, python 3.7.5, but same issue running from a flask application I'm developing on the same Pi.
The following code
from pylibdmtx.pylibdmtx import encode
encoded = encode('5e78e9945f627d09ca1c28a7')
#print(dir(encoded))
bc = Image.frombytes('RGB', (encoded.width, encoded.height), encoded.pixels)
bc
Produces slightly different barcode every time, and the barcode decodes with a commercial scanner to an incomplete portion of the encode string, usually something like:
78e9
Treepoem works to generate the barcode and it is read correctly, but is quite dependency heavy and slow.
tp = treepoem.generate_barcode(barcode_type="datamatrix", data='5e78e9945f627d09ca1c28a7')
tp
I am hoping I'm somehow using the encode method wrong or there is some simple fix so I can go back to using pylibdmtx
Thanks
A few things need some love - README, pep8, docstrings
Traceback:
Traceback (most recent call last):
File "C:\Users\(edited)\env-labels\lib\site-packages\pylibdmtx\dmtx_library.py", line 51, in load
libdmtx = cdll.LoadLibrary(fname)
File "C:\Python\Python39\lib\ctypes\__init__.py", line 452, in LoadLibrary
return self._dlltype(name)
File "C:\Python\Python39\lib\ctypes\__init__.py", line 374, in __init__
self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'libdmtx-64.dll' (or one of its dependencies). Try using the full path with constructor syntax.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\(edited)\product_label.py", line 5, in <module>
from pylibdmtx.pylibdmtx import encode, decode
File "C:\Users\(edited)\env-labels\Lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py", line 142, in _import
return original_import(name, *args, **kwargs)
File "C:\Users\(edited)\env-labels\lib\site-packages\pylibdmtx\pylibdmtx.py", line 10, in <module>
from .wrapper import (
File "C:\Users\(edited)\env-labels\Lib\site-packages\shiboken2\files.dir\shibokensupport\__feature__.py", line 142, in _import
return original_import(name, *args, **kwargs)
File "C:\Users\(edited)\env-labels\lib\site-packages\pylibdmtx\wrapper.py", line 70, in <module>
_dmtxVersion = libdmtx_function('dmtxVersion', c_char_p)
File "C:\Users\(edited)\env-labels\lib\site-packages\pylibdmtx\wrapper.py", line 58, in libdmtx_function
return prototype((fname, load_libdmtx()))
File "C:\Users\(edited)\env-labels\lib\site-packages\pylibdmtx\wrapper.py", line 39, in load_libdmtx
LIBDMTX = dmtx_library.load()
File "C:\Users\(edited)\env-labels\lib\site-packages\pylibdmtx\dmtx_library.py", line 53, in load
libdmtx = cdll.LoadLibrary(str(Path(__file__).parent.joinpath(fname)))
File "C:\Python\Python39\lib\ctypes\__init__.py", line 452, in LoadLibrary
return self._dlltype(name)
File "C:\Python\Python39\lib\ctypes\__init__.py", line 374, in __init__
self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'C:\Users\(edited)\env-labels\lib\site-packages\pylibdmtx\libdmtx-64.dll' (or one of its dependencies). Try using the full path with constructor syntax.
Tried to add:
import os
os.add_dll_directory(os.getcwd())
Before libdmtx = cdll.LoadLibrary(str(Path(__file__).parent.joinpath(fname)))
to no success.
Even tried to add the exact path to libdmtx-64.dll
but did not work.
Was libdmtx-64.dll
built on Windows 10?
Which are the dependencies I would need to install?
Thanks!
pylibdmtx does have a test suite, but it is not run automatically whenever a commit is made to this repo.
Automatic testing would allow us to avoid problems like #27, and would alert us to any breaking changes made to the upstream C library.
Conf:
Raspberry Pi 4 - Raspbian GNU/Linux 10 (buster) 32 bit os, ARM
pylibdmtx (0.1.9)
libdmtx0b (0.7.5-3)
from PIL import Image
from pylibdmtx.pylibdmtx import decode, Decoded, DmtxSymbolSize
import time
img_path = "auxiliaries/peripherals/camera/test.jpg"
img = Image.open(img_path)
for t in [50, 500, 5000, 3000, None]:
started = time.time()
res = decode(img, shape=DmtxSymbolSize.DmtxSymbol8x18, timeout=t)
print(f"timeout: {t/1000 if t else None}, elapsed: {round(time.time() - started, 3)}, result: {res}")
Output on Raspberry:
timeout: 0.05, elapsed: 0.053, result: []
timeout: 0.5, elapsed: 0.502, result: [Decoded(data=b'033757', rect=Rect(left=156, top=65, width=-55, height=131))]
timeout: 5.0, elapsed: 5.003, result: [Decoded(data=b'033757', rect=Rect(left=156, top=65, width=-55, height=131))]
timeout: 3.0, elapsed: 3.001, result: [Decoded(data=b'033757', rect=Rect(left=156, top=65, width=-55, height=131))]
timeout: None, elapsed: 15.503, result: [Decoded(data=b'033757', rect=Rect(left=156, top=65, width=-55, height=131))]
Also tried it on Mac
Output on OSX:
timeout: 0.05, elapsed: 0.051, result: []
timeout: 0.5, elapsed: 0.501, result: [Decoded(data=b'033757', rect=Rect(left=156, top=65, width=-55, height=131))]
timeout: 5.0, elapsed: 5.001, result: [Decoded(data=b'033757', rect=Rect(left=156, top=65, width=-55, height=131))]
timeout: 3.0, elapsed: 3.001, result: [Decoded(data=b'033757', rect=Rect(left=156, top=65, width=-55, height=131))]
timeout: None, elapsed: 4.807, result: [Decoded(data=b'033757', rect=Rect(left=156, top=65, width=-55, height=131))]
I conclude that for such a small pic it takes less than 0.5 sec to process, but timeout is always waited (one core of cpu is maxed out until the end of the timeout).
I cannot achieve high throughput and guaranteed operation. Any ideas of what might be wrong?
jbw@broadway pylibdmtx (master) $ python2 -c 'import pylibdmtx.pylibdmtx'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "pylibdmtx/pylibdmtx.py", line 10, in <module>
from .wrapper import (
File "pylibdmtx/wrapper.py", line 9, in <module>
from . import dmtx_library
File "pylibdmtx/dmtx_library.py", line 8, in <module>
from pathlib import Path
ImportError: No module named pathlib
Seems that pathlib was introduced in Python 3.4 link to docs, however README and setup.py (and module docstrings) advertise pylibdmtx as Python 2 compatible.
numpy.ndarray.tobytes()
was introduced in numpy
1.9.0. Use numpy.ndarray.tostring()
where tobytes
is not present.
Hi, everyone!
I run this code on my Ubuntu 20.04.3 LTS:
from pylibdmtx.pylibdmtx import encode
and get the following error:
/home/petr/Documents/PycharmProjects/Gitlab_test_3/myvenv/bin/python3.9 /home/petr/Documents/PycharmProjects/Gitlab_test_3/test_03.py
Traceback (most recent call last):
File "/home/petr/Documents/PycharmProjects/Gitlab_test_3/test_03.py", line 1, in <module>
from pylibdmtx.pylibdmtx import encode
File "/home/petr/Documents/PycharmProjects/Gitlab_test_3/myvenv/lib/python3.9/site-packages/pylibdmtx/pylibdmtx.py", line 10, in <module>
from .wrapper import (
File "/home/petr/Documents/PycharmProjects/Gitlab_test_3/myvenv/lib/python3.9/site-packages/pylibdmtx/wrapper.py", line 70, in <module>
_dmtxVersion = libdmtx_function('dmtxVersion', c_char_p)
File "/home/petr/Documents/PycharmProjects/Gitlab_test_3/myvenv/lib/python3.9/site-packages/pylibdmtx/wrapper.py", line 58, in libdmtx_function
return prototype((fname, load_libdmtx()))
File "/home/petr/Documents/PycharmProjects/Gitlab_test_3/myvenv/lib/python3.9/site-packages/pylibdmtx/wrapper.py", line 39, in load_libdmtx
LIBDMTX = dmtx_library.load()
File "/home/petr/Documents/PycharmProjects/Gitlab_test_3/myvenv/lib/python3.9/site-packages/pylibdmtx/dmtx_library.py", line 47, in load
raise ImportError('Unable to find dmtx shared library')
ImportError: Unable to find dmtx shared library
Process finished with exit code 1
The rectangle object returned by the decode
function is (completely) wrong whenever the found DataMatrix code is rotated. The problem is that the returned rectangle is always supposed to be upright when, in fact, libdtmx supports also rotated codes.
Examples with one upright and one rotated DataMatrix code:
dmtxread
on the command line(base) ➜ ~ dmtxread -n -v -N 1 12345_garbage.png
--------------------------------------------------
Matrix Size: 10 x 10
Data Codewords: 3 (capacity 3)
Error Codewords: 5
Data Regions: 1 x 1
Interleaved Blocks: 1
Rotation Angle: 0
Corner 0: (1152.0, 1287.0)
Corner 1: (1201.0, 1287.0)
Corner 2: (1200.1, 1238.0)
Corner 3: (1152.0, 1238.0)
--------------------------------------------------
12345
(base) ➜ ~ dmtxread -n -v -N 1 12345_garbage_rotated.png
--------------------------------------------------
Matrix Size: 10 x 10
Data Codewords: 3 (capacity 3)
Error Codewords: 5
Data Regions: 1 x 1
Interleaved Blocks: 1
Rotation Angle: 319
Corner 0: (1191.0, 1292.9)
Corner 1: (1228.1, 1325.2)
Corner 2: (1260.5, 1287.9)
Corner 3: (1223.4, 1255.6)
--------------------------------------------------
12345
pylibdtmx
(libdmtx) ➜ ~ ipython
Python 3.7.5 (default, Oct 25 2019, 15:51:11)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.9.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from pylibdmtx.pylibdmtx import decode
In [2]: from PIL import Image
In [3]: decode(Image.open("/home/gri/12345_garbage.png"), max_count=1)
Out[3]: [Decoded(data=b'12345', rect=Rect(left=1152, top=2220, width=48, height=49))]
In [4]: decode(Image.open("/home/gri/12345_garbage_rotated.png"), max_count=1)
Out[4]: [Decoded(data=b'12345', rect=Rect(left=1191, top=2214, width=70, height=5))]
(Note how also width
and height
changed to totally incorrect values.)
The obvious solution would be to not return a tuple of left
, top
, width
, and height
coordinates, since they apply only to upright rectangles, but to return the coordinates of the four corners---as is done by the command line program.
So in these lines of the code all four points should be captured instead of only two ones.
Of course, such a change would break the interface as it is now.
If you insist on returning an upright rectangle, it should at least be the upright bounding box of the DataMatrix code crop. But I would much prefer if the python version would just return the four corner points as the command line version does.
I found I had to wrap the pylibdmtx in an external subprocess (i.e. copy the source image to a file and then have a CLI envoked script that calls pylibdmtx and writes the result to a file) because this image causes everything to just hard stop, with no error messages or exceptions raised. I always treasure this sort of test data because it should be fairly easy for someone familiar with the code to fix the problem, but it isn't something I have the knowledge to do.
Enjoy!
encoded_data = encode('A', size='10x10')
print(encoded_data.width)
print(encoded_data.height)
Returns
70
70
While I have set it to be 10x10.
I integrated the pylibdmtx into my program, and this program will process dm code every day. Recently I find it cannot read datamatrix after running for several days. But if I test the same image or restart the program, it works well again. Anyone meet the similar problem?
When i run the following simple snippet many times:
from pylibdmtx.pylibdmtx import encode
from pylibdmtx.pylibdmtx import decode
from PIL import Image
encstr = '1111111111'
encoded = encode(encstr)
img = Image.frombytes('RGB', (encoded.width, encoded.height), encoded.pixels)
print(decode(img)[0].data)
I see that the output resultat very often is different and its never the same as the input.
Am I totally misunderstanding a datamatrix concept here or are there major errors in this library?
I would like to create a script which generates datamatrixes with some additional text which is not the data encoded. The result should have a fixed size to be printed on a label.
So the first step would be to get a matrix of fixed size i guess. Is this possible with this lib?
Currently if someone executes import pylibdmtx
they get nothing in the pylibdmtx
namespace. This makes discoverability worse (e.g. tab-completion in IPython does not work), and also requires a bit more work: import pylibdmtx.pylibdmtx as pylibdmtx
or from pylibdmtx import pylibdmtx
.
I propose to import the contents of pylibdmtx.py
into __init__.py
so that the top-level API is directly accessible with import pylibdmtx
.
Using Pylibdmtx from current master
:
>>> from pylibdmtx import pylibdmtx
>>> pylibdmtx.encode(b'yolo')
Encoded(width=100, height=0, bpp=0, pixels=b'')
pylibdmtx/pylibdmtx/tests/test_pylibdmtx.py:97: DeprecationWarning: Please use assertRaisesRegex instead.
The fix for #24 broke Windows. Need to build libdmtx
DLLs to expose dtmxVersion
.
The decoded value might be NULL
(https://sourceforge.net/p/libdmtx/dmtx-wrappers/ci/master/tree/python/pydmtxmodule.c#l269) - the code does not check for this case.
Hi,
Executing the following code gives me unexpected results on MacOS:
from pystrich.datamatrix import DataMatrixEncoder
import PIL
from io import BytesIO
from pylibdmtx.pylibdmtx import decode
data = 'SomeStringWithData'
print(f'Encoding: {data}')
image_bytes = DataMatrixEncoder(data).get_imagedata(cellsize=2)
image = PIL.Image.open(BytesIO(image_bytes))
results = decode(image)
print('raw results:')
print(results)
Output on MacOS 10.13.3
:
Encoding: SomeStringWithData
raw results:
[Decoded(data=b'TpnfTusjohXjuiEbub\xb9AE\xbf}\xad|\xc81\xda\x9d\x9a\x95\xb2`\xf7`\x07\x01', rect=Rect(left=3, top=4, width=37, height=35))]
Whereas this works as expected on both Linux and Windows.
Basically it gives the raw data of the datamatrix instead of the parsed/decoded one.
I can't figure out whats going on because:
dmtxread
from dmtx-utils
DOES work on the same machine, suggesting the c library IS NOT at fault heredmtxDecodeMatrixRegion
wrapper function gives the wrong result, suggesting the c library IS at fault.I've also tried having the latest version of libdmtx
compiled from source on my search path instead of the one from homebrew
but it gives the same result.
Is this a known issue on your end maybe?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.