Beispiel #1
0
def decode(imgcv2):
    code = ""
    try:
        st = datetime.datetime.now()
        img = Image.fromarray(imgcv2)
        if img.mode != 'RGB':
            img = img.convert('RGB')
        dm_read = DataMatrix()
        code = dm_read.decode(
            img.size[0],
            img.size[1],
            buffer(
                img.tostring()),
            timeout=80,
            maxcount=1,
            corrections=3)
        end = datetime.datetime.now()
        if dm_read.count() == 1:
            # print code, end - st
            time = end - st

            print dm_read.stats(1), "t:", str(time)[6:]
            points = dm_read.stats(1)[1]
            # print "points:", points
            # os.system("beep -f1296 -l10")
    except Exception:
        print "error decode"
        pass

    return code, points
Beispiel #2
0
def mkdmtx(msg):
    dm_write = DataMatrix()
    dm_write.encode(msg)
    pi = dm_write.image  # .resize((14, 14))
    cv_im = cv.CreateImageHeader(pi.size, cv.IPL_DEPTH_8U, 3)
    cv.SetData(cv_im, pi.tostring())
    return cv_im
Beispiel #3
0
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))
 def __init__(self):
     # The default logging level is INFO.
     # Comment this line to set debug logging off
     self.log.setLevel(logging.DEBUG) 
     # Make some generic parameters
     # You can change the Name fields on the EDM screen here
     # Hide them by making their name -1
     params = dict(int1 = 101,      int1Name = "Threshold block size",
                   int2 = 13,      int2Name = "Threshold C",
                   int3 = 3,      int3Name = "Kernel size",
                   double1 = 0.35, double1Name = "Angle cos",
                   double2 = 6.0, double2Name = "Curve epsilon",
                   double3 = 15.0, double3Name = "Length diff")
     self.dm=DataMatrix()
     AdPythonPlugin.__init__(self, params)
Beispiel #5
0
def parse_folder(folder, output_folder):

    # create output folder if it does not exist
    if not os.path.exists(output_folder):
        os.makedirs(output_folder)

    # check images in folder
    for fn in os.listdir(folder):
        if fn.lower().endswith(".jpg") and not fn.lower().startswith("crop_"):
            print "Working on %s" % fn
            fnpath = os.path.join(folder, fn)

            # Read a Data Matrix barcode
            dm = DataMatrix()
            img = Image.open(fnpath)

            # Get datetime from image exif data
            exif = get_exif(img)
            datetime = exif["DateTime"].split(" ")[0].replace(":", "")

            if DEBUG:
                print "Image date: %s" % datetime

            # only check bottom third column cell and sixth row
            w, h = img.size
            x_start = 3 * (w / 4)
            y_start = 3 * (h / 4)

            crop = img.crop((x_start, y_start, w, h))

            if DEBUG:
                #write crop for debugging purposes
                crop.save(os.path.join(folder, "crop_" + fn))

            # Detect
            identifier = dm.decode(crop.size[0], crop.size[1],
                                   buffer(crop.tobytes()))

            if identifier:
                print "Decoded shelf: %s" % identifier

                #move and rename image
                os.rename(
                    fnpath,
                    os.path.join(output_folder,
                                 identifier + "_" + datetime + ".jpg"))
            else:
                print "No value"
Beispiel #6
0
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)
Beispiel #7
0
 def __init__(self):
     self.cache = {}
     self.dm = DataMatrix()
Beispiel #8
0
# -*- coding: iso-8859-1 -*-
from pydmtx import DataMatrix
from PIL import Image, ImageDraw, ImageFont
import sys

# Generate a label image containing a DataMatrix code and shelf identifer text.
# Image files are output as PNG in the current directory.
#
# Usage: python make_dtmx.py <location> <bookshelf> <shelf>

margin = 0
fontsize = 120

dm = DataMatrix()
dm.options["shape"] = dm.DmtxSymbolRectAuto
dm.options["module_size"] = dm.DmtxSymbol8x32
dm.options["scheme"] = dm.DmtxSchemeAscii
dm.options["margin_size"] = margin
font = ImageFont.truetype("inconsolata.otf", fontsize)
dmtx_block_size = 25

# parameters - max length is 13 chars (including separators)
location = sys.argv[1]  # pysical location e.g. H12V
case = sys.argv[2]  # book case identifier e.g. 12
count = int(
    sys.argv[3])  # number of shelf identifier e.g. 4 will generate 4 images.


def makedmx(text, filename):
    # Set up Data Matrix
    dm.encode(text)
Beispiel #9
0
    calibrated = 0
    focal_length = image.width
    center = (image.width / 2, image.height / 2)
    camMatrix = np.array([[focal_length, 0, center[0]],
                          [0, focal_length, center[1]], [0, 0, 1]],
                         dtype="double")
    distCoeff = np.zeros((5, 1))

if options.dump:
    print(camMatrix)
    print(distCoeff)

display = Display()

# Timeout after 100ms, or after finding 1 'square' barcode
dm_read = DataMatrix(timeout=100, max_count=1, shape=1)

while display.isNotDone():
    if options.test:
        # re-read image
        image = Image("original.png")
    else:
        if calibrated:
            image_orig = cam.getImage()
            image = cam.undistort(image_orig)
        else:
            image = cam.getImage()

    overlay = DrawingLayer((image.width, image.height))

    dm_read.decode(image.width, image.height, buffer(image.toString()))