Example #1
0
 def multiply(self, other):
     out = Transform.multiply(self, other)
     return Affine(*tuple(out.matrix[0:2,0:3].flat))
Example #2
0
 def __init__(self, a=1, b=0, c=0, d=0, e=1, f=0):
     Transform.__init__(self, a, b, c, d, e, f)
Example #3
0
 def __init__(self, a=1, b=0, c=0, d=0, e=1, f=0):
     Transform.__init__(self, a, b, c, d, e, f)
Example #4
0
 def multiply(self, other):
     out = Transform.multiply(self, other)
     return Affine(*tuple(out.matrix[0:2,0:3].flat))
Example #5
0
def paper_matches(blobs):
    """ Generate matches for specific paper sizes.
    
        Yield tuples with transformations from scan pixels to print points,
        paper sizes and orientations. Print points are centered on lower right
        corner of QR code.
    """
    from dimensions import ratio_portrait_a3, ratio_portrait_a4, ratio_portrait_ltr
    from dimensions import ratio_landscape_a3, ratio_landscape_a4, ratio_landscape_ltr
    from dimensions import point_F_portrait_a3, point_F_portrait_a4, point_F_portrait_ltr
    from dimensions import point_F_landscape_a3, point_F_landscape_a4, point_F_landscape_ltr

    for (dbc_match, aed_match) in _blob_matches_primary(blobs):
        for (f_match, point_F) in _blob_matches_secondary(blobs, aed_match):
            #
            # determining paper size and orientation based on identity of point E.
            #
            if point_F is point_F_portrait_a3:
                orientation, paper_size, scale = 'portrait', 'a3', 1 / ratio_portrait_a3

            elif point_F is point_F_portrait_a4:
                orientation, paper_size, scale = 'portrait', 'a4', 1 / ratio_portrait_a4

            elif point_F is point_F_portrait_ltr:
                orientation, paper_size, scale = 'portrait', 'letter', 1 / ratio_portrait_ltr

            elif point_F is point_F_landscape_a3:
                orientation, paper_size, scale = 'landscape', 'a3', 1 / ratio_landscape_a3

            elif point_F is point_F_landscape_a4:
                orientation, paper_size, scale = 'landscape', 'a4', 1 / ratio_landscape_a4

            elif point_F is point_F_landscape_ltr:
                orientation, paper_size, scale = 'landscape', 'letter', 1 / ratio_landscape_ltr

            else:
                raise Exception('How did we ever get here?')

            #
            # find the scan location of point F
            #
            (scan_F, ) = [
                getattr(f_match, 's%d' % i) for i in (1, 2, 3)
                if getattr(f_match, 'p%d' % i) is point_F
            ]

            #
            # transform from scan pixels to homogenous print coordinates - A, C, E, F
            #
            s2h = quad2quad(aed_match.s1, aed_match.p1, dbc_match.s3,
                            dbc_match.p3, aed_match.s2, aed_match.p2, scan_F,
                            point_F)

            #
            # transform from scan pixels to printed points, with (0, 0) at lower right
            #
            h2p = Transform(scale, 0, 0, 0, scale, 0)
            s2p = s2h.multiply(h2p)

            # useful for drawing post-blobs image
            blobs_abcde = aed_match.s1, dbc_match.s2, dbc_match.s3, dbc_match.s1, aed_match.s2

            yield s2p, paper_size, orientation, blobs_abcde