Skip to content

Instantly share code, notes, and snippets.

@fbuchinger
Created July 11, 2010 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbuchinger/471558 to your computer and use it in GitHub Desktop.
Save fbuchinger/471558 to your computer and use it in GitHub Desktop.
import sys
from PIL import Image, ImageOps
from pydmtx import DataMatrix
if __name__ == '__main__':
dmtx_image = Image.open(sys.argv[1])
dmtx_image.thumbnail((1060, 1500))
(width, height) = dmtx_image.size
dmtx_cropped = dmtx_image.crop((0,int(height*(0.667)), width, height))
dmtx_cropped = ImageOps.expand(dmtx_cropped, 20, "white") #add 20px white border around img as quiet zone
(cropped_width, cropped_height) = dmtx_cropped.size
dm_read = DataMatrix(max_count = 1, timeout = 1500) # find max 1 dmtx code, stop after 1.5 secs
dmtx_code = dm_read.decode (cropped_width, cropped_height, buffer(dmtx_cropped.tostring()))
if dmtx_code is not None:
print "Found Datamatrix code '%s' in %s" % (dmtx_code, sys.argv[1])
else:
print "No Datamatrix code found in %s" % (sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment