跳转到主要内容

从Python 2和3读取和写入Data Matrix条形码。

项目描述

https://img.shields.io/badge/python-2.7%2C%203.5%2C%203.6%2C%203.7%2C%203.8%2C%203.9%2C%203.10-blue.svg https://badge.fury.io/py/pylibdmtx.svg https://img.shields.io/github/workflow/status/NaturalHistoryMuseum/pylibdmtx/Tests/master?label=tests https://coveralls.io/repos/github/NaturalHistoryMuseum/pylibdmtx/badge.svg?branch=master

使用libdmtx库从Python 2和3读取和写入Data Matrix条形码。

  • 纯Python

  • 与PIL / Pillow图像、OpenCV / imageio / numpy ndarray和原始字节数据一起使用

  • 解码条形码位置

  • 除了libdmtx库本身外,没有其他依赖项

  • 已在Python 2.7和Python 3.5到3.10上进行了测试

较老的pydmtx软件包卡在了Python 2.x领域。

安装

Windows Python轮盘中包含了libdmtx DLL。在其他操作系统上,您需要安装libdmtx共享库。

Mac OS X

brew install libdmtx

Linux

sudo apt-get install libdmtx0a

安装此Python包装器;使用第二种形式安装read_datamatrixwrite_datamatrix命令行脚本的依赖项

pip install pylibdmtx
pip install pylibdmtx[scripts]

示例用法

decode函数接受PIL.Image实例。

>>> from pylibdmtx.pylibdmtx import decode
>>> from PIL import Image
>>> decode(Image.open('pylibdmtx/tests/datamatrix.png'))
[Decoded(data='Stegosaurus', rect=Rect(left=5, top=6, width=96, height=95)),
 Decoded(data='Plesiosaurus', rect=Rect(left=298, top=6, width=95, height=95))]

它还接受可能来自使用OpenCV加载图像的numpy.ndarray实例。

>>> import cv2
>>> decode(cv2.imread('pylibdmtx/tests/datamatrix.png'))
[Decoded(data='Stegosaurus', rect=Rect(left=5, top=6, width=96, height=95)),
 Decoded(data='Plesiosaurus', rect=Rect(left=298, top=6, width=95, height=95))]

您还可以提供一个元组(pixels, width, height)

>>> image = cv2.imread('pylibdmtx/tests/datamatrix.png')
>>> height, width = image.shape[:2]
>>> decode((image.tobytes(), width, height))
[Decoded(data='Stegosaurus', rect=Rect(left=5, top=6, width=96, height=95)),
 Decoded(data='Plesiosaurus', rect=Rect(left=298, top=6, width=95, height=95))]

encode函数生成包含Data Matrix条形码的图像

>>> from pylibdmtx.pylibdmtx import encode
>>> encoded = encode('hello world'.encode('utf8'))
>>> img = Image.frombytes('RGB', (encoded.width, encoded.height), encoded.pixels)
>>> img.save('dmtx.png')
>>> print(decode(Image.open('dmtx.png')))
[Decoded(data=b'hello world', rect=Rect(left=9, top=10, width=80, height=79))]

Windows错误消息

如果在Windows上导入 pylibdmtx 时出现难看的 ImportError,您可能需要 Visual Studio 2013 的 Visual C++ 分发包。如果您使用的是64位Python,请安装 vcredist_x64.exe;如果您使用的是32位Python,请安装 vcredist_x86.exe

限制

欢迎提交PR来解决这些问题。

  • 我采取了复制 pydmtxdecode 函数逻辑(在 pydmtxmodule.c 中)的笨拙方法;可能有更多 libdmtx 的功能可以被有用地暴露出来

  • 我公开了最少量的函数、定义、枚举和类型定义,以便重新实现 pydmtxdecode 函数

贡献者

  • Vinicius Kursancew (@kursancew) - 首次实现条码写入

  • Joseph Weston (@jbweston) - 支持 libdmtx 0.7.5

许可证

pylibdmtx 在 MIT 许可证下分发(见 LICENCE.txt)。libdmtx 共享库在简化版BSD许可证下分发(见 libdmtx-LICENCE.txt)。

项目详情


下载文件

下载适合您平台的文件。如果您不确定要选择哪个,请了解更多关于 安装包 的信息。

源分发

此发行版没有提供源分发文件。请参阅 生成分发存档的教程

构建分发

pylibdmtx-0.1.10-py2.py3-none-win_amd64.whl (65.7 kB 查看哈希值)

上传时间 Python 2 Python 3 Windows x86-64

pylibdmtx-0.1.10-py2.py3-none-win32.whl (58.1 kB 查看哈希值)

上传时间 Python 2 Python 3 Windows x86

pylibdmtx-0.1.10-py2.py3-none-any.whl (23.2 kB 查看哈希值)

上传时间 Python 2 Python 3

支持者