• Stars
    star
    145
  • Rank 254,144 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created about 8 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Read Data Matrix barcodes from Python 2 and 3.

pylibdmtx

https://img.shields.io/github/workflow/status/NaturalHistoryMuseum/pylibdmtx/Tests/master?label=tests https://coveralls.io/repos/github/NaturalHistoryMuseum/pylibdmtx/badge.svg?branch=master

Read and write Data Matrix barcodes from Python 2 and 3 using the libdmtx library.

  • Pure python
  • Works with PIL / Pillow images, OpenCV / imageio / numpy ndarrays, and raw bytes
  • Decodes locations of barcodes
  • No dependencies, other than the libdmtx library itself
  • Tested on Python 2.7, and Python 3.5 to 3.10

The older pydmtx package is stuck in Python 2.x-land.

Installation

The libdmtx DLLs are included with the Windows Python wheels. On other operating systems, you will need to install the libdmtx shared library.

Mac OS X:

brew install libdmtx

Linux:

sudo apt-get install libdmtx0a

Install this Python wrapper; use the second form to install dependencies of the read_datamatrix and write_datamatrix command-line scripts:

pip install pylibdmtx
pip install pylibdmtx[scripts]

Example usage

The decode function accepts instances of 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))]

It also accepts instances of numpy.ndarray, which might come from loading images using OpenCV.

>>> 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))]

You can also provide a tuple (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))]

The encode function generates an image containing a Data Matrix barcode:

>>> 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 error message

If you see an ugly ImportError when importing pylibdmtx on Windows you will most likely need the Visual C++ Redistributable Packages for Visual Studio 2013. Install vcredist_x64.exe if using 64-bit Python, vcredist_x86.exe if using 32-bit Python.

Limitations

Feel free to submit a PR to address any of these.

  • I took the bone-headed approach of copying the logic in pydmtx’s decode function (in pydmtxmodule.c); there might be more of libdmtx’s functionality that could usefully be exposed
  • I exposed the bare minimum of functions, defines, enums and typedefs neede to reimplement pydmtx’s decode function

Contributors

  • Vinicius Kursancew (@kursancew) - first implementation of barcode writing
  • Joseph Weston (@jbweston) - support for libdmtx 0.7.5

License

pylibdmtx is distributed under the MIT license (see LICENCE.txt). The libdmtx shared library is distributed under the Simplified BSD license (see libdmtx-LICENCE.txt).

More Repositories

1

pyzbar

Read one-dimensional barcodes and QR codes from Python 2 and 3.
Python
728
star
2

scratchpads2

Scratchpads 2.0
PHP
199
star
3

inselect

Cross-platform desktop app for the segmentation and annotation of images of museum objects
Python
120
star
4

ckanext-ldap

A CKAN extension that provides LDAP authentication.
Python
33
star
5

gouda

Reading barcodes in complex images
Python
28
star
6

ckanext-nhm

A CKAN extension for the Natural History Museum's Data Portal.
Python
22
star
7

ckanext-doi

A CKAN extension for assigning a digital object identifier (DOI) to datasets, using the DataCite DOI service.
Python
18
star
8

predicts_www

Website for the PREDICTS project
TeX
16
star
9

libdmtx-windows

Visual Studio solution for 32-bit and 64-bit DLL builds of libdmtx
C
9
star
10

semantic-segmentation

Semantic instance segmentation of specimen images using semi-supervised learning
Jupyter Notebook
9
star
11

ckanext-versioned-datastore

A CKAN extension providing a versioned datastore using MongoDB and Elasticsearch.
Python
9
star
12

linnaeus

Make a big picture from many small pictures.
Python
8
star
13

ckanpackager

A stand-alone service to pack a given CKAN resource in a ZIP file and email the link to a user.
Python
7
star
14

ckanext-dataspatial

Ckan extension to enable geospatial searches within the datastore
Python
7
star
15

ckanext-datasolr

datasolr is a Ckan extension to use Solr for datastore queries
Python
6
star
16

ckanext-ckanpackager

A CKAN extension that provides a user interface to download resources with ckanpackager.
Python
6
star
17

ALICE

Angled Label Image Capture and Extraction for high throughput insect specimen digitisation
Jupyter Notebook
5
star
18

iiif-image-server

A IIIF Image Server
Python
5
star
19

ckanext-gbif

A CKAN extension that that connects with the GBIF API.
Python
4
star
20

ckanext-gallery

CKAN extension for a dataset gallery view.
Python
4
star
21

ckanext-contact

A CKAN extension for adding popup contact forms to pages.
Python
4
star
22

ckanext-dev

CKAN extention for development tools.
Python
4
star
23

ckanext-graph

A CKAN extension that adds a graph view for resources.
Python
4
star
24

nhm-pyportal

Python wrapper for the Data Portal API.
Python
3
star
25

ckanext-iiif

CKAN IIIF extension
Python
2
star
26

splitgill

Versioned search library
Python
2
star
27

ckanext-video

A CKAN extension for embedding Youtube or Vimeo videos as views.
Python
2
star
28

KEParser

Parser for KE EMu key=value export files.
Python
2
star
29

vertebrate-georef

Code for spatial analyses on georeferenced vertebrate type data
R
2
star
30

ke2mongo

Import KE EMu data into Mongo DB
Python
2
star
31

ai-natural-sciences

CSS
2
star
32

nhm-windshaft-app

JavaScript
2
star
33

barcode-reader-dlls

Windows DLL builds of the libdmtx and zbar barcode readers
2
star
34

data-importer

Import KE EMu data into SQL
Python
2
star
35

scratchpads-evolution

Formerly called Scratchpads Re-development. Renamed to Scratchpads Evolution to represent an ongoing development approach, where real development evaluation and prototyping can happen sooner and in parallel with the current Scratchpads 2 platform.
PHP
2
star
36

ckanext-userdatasets

A CKAN extension that allows organisation members to create datasets, and edit or delete the datasets they have created.
Python
2
star
37

biodiversity-informatics-101

Biodiversity Informatics 101
Jupyter Notebook
2
star
38

ckanext-sketchfab

A CKAN extension for embedding Sketchfab models as views.
Python
2
star
39

Mobilising-Collections-Biodiversity-Data

Mobilising Collection's Biodiversity Data - NatSca Workshop 2019
1
star
40

planetary-knowledge-base

Jupyter Notebook
1
star
41

fuse

Linked Open Data Micro-services Framework
1
star
42

scratchpads.org

Code for scratchpads.org online promotional brochure site for the Scratchpads platform, not a scratchpads site itself.
HTML
1
star
43

PKB

Planetary Knowledge Base
Jupyter Notebook
1
star
44

scratchpads

The original Drupal 6.x Scratchpads
PHP
1
star
45

pkb-ocr

HTML
1
star
46

gamc

A GBIF API MIDS Calculator
Vue
1
star
47

ckanext-feedback

Feedback extension for CKAN
Python
1
star
48

ckanext-status

A CKAN extension that adds a 'status' bar to the top of the page.
Python
1
star
49

nhm-docker-ckan

CKAN Docker images for the Data Portal
Dockerfile
1
star
50

ckanext-webview

A CKAN extension for adding arbitrary URLs as resource views
Python
1
star
51

phenome-10k

Python
1
star
52

inselect-templates

Metadata template for Inselect
1
star
53

fencedine

Script used for caching of web resources. Particularly useful for caching of dynamically produced content like Google scholar search results.
PHP
1
star
54

hosting_scratchpads

Module which tweaks the Aegir website and makes it "Scratchpads Aegir".
PHP
1
star
55

versioned-datastore-tile-server

Tile server for the versioned datastore
Python
1
star
56

audioblast_ingest

Provides Urban Nature Project bioacoustic data to audioblast.org.
R
1
star
57

su2014

Transcription app for Science Uncovered 2014
JavaScript
1
star
58

scratchpads2-solanaceaesource

Custom modules for the solanaceaesource.org Scratchpad
PHP
1
star
59

recode-consultation

Open repository for public consultation on the RECODE programme requirements and community collections data management
1
star
60

syrup

Desktop application for renaming and moving image files captured by eMesozoic
Python
1
star
61

dmtx-wrappers

Visual Studio solution for 32-bit and 64-bit builds of the pydmtx Python package
C
1
star
62

ckanext-statistics

A CKAN extension for accessing download statistics
Python
1
star
63

river-dolphin-convergence

Data, analyses and manuscript for river dolphin convergence paper
PLSQL
1
star
64

lates-may-23

Python
1
star
65

ckanext-versioned-tiledmap

A CKAN extension with a map view for versioned-datastore backed resources.
JavaScript
1
star
66

nhm-windshaft-utils

JavaScript
1
star
67

smhackdown

Hot or not for museum objects
Vue
1
star
68

DMM_Development_Team_Principles

1
star
69

MarkMyBird

NHM Data Portal Dataset for MarkMyBird
1
star