def __call__(self, img): d = DataMatrix(timeout=self.timeout_ms, max_count=self.max_count) # PIL RGB image from BGR np.ndarray # http://stackoverflow.com/a/4661652/1773758 img = Image.fromarray(np.roll(img, 1, axis=-1)) img = img.convert('RGB') res = d.decode(img.size[0], img.size[1], buffer(img.tostring())) res = [None] * d.count() for i in xrange(0, d.count()): res[i] = Barcode('Data Matrix', d.message(1+i)) return res
def handleargc(): for filename in sys.argv[1:]: if filename.endswith('.bin'): decodedm(str1=open(filename, 'rb').read()) else: from pydmtx import DataMatrix from PIL import Image dm_read = DataMatrix() img = Image.open(sys.argv[1]) dm_read.decode(img.size[0], img.size[1], buffer(img.tostring())) #print dm_read.count() #print dm_read.stats(1) decodedm(dm_read.message(1))
from pydmtx import DataMatrix from PIL import Image # Write a Data Matrix barcode dm_write = DataMatrix() dm_write.encode("Hello, world!") dm_write.save("hello.png", "png") # Read a Data Matrix barcode dm_read = DataMatrix() img = Image.open("hello.png") print dm_read.decode(img.size[0], img.size[1], buffer(img.tostring())) print dm_read.count() print dm_read.message(1) print dm_read.stats(1)
import os from pydmtx import DataMatrix from PIL import Image #------------------------------------------------------------ # write a data matrix barcode #------------------------------------------------------------ path = os.path.abspath('.') path = os.path.join(path, 'hello.png') matrix = DataMatrix() matrix.encode("Hello, world!") matrix.save(path, "png") #------------------------------------------------------------ # read a data matrix Barcode #------------------------------------------------------------ matrix = DataMatrix() image = Image.open(path) print matrix.decode(image.size[0], image.size[1], buffer(image.tostring())) print matrix.count() print matrix.message(1) print matrix.stats(1)