myqr.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:QR-Replace 作者: Metruption 项目源码 文件源码
def warpImage(background, image, parallelogram):
    '''
    @params:
        background is unchanged image
        image is image to be warped
        parallelogram is the coordinates to warp the image to, starting at upper
            left and going clockwise
    returns a new image that is the composition of background and image
        after image has been warped
    '''
    mapped = np.array([[parallelogram[0].x, parallelogram[1].x, parallelogram[2].x],
    [parallelogram[0].y, parallelogram[1].y, parallelogram[2].y], [1,1,1]])

    width, height = image.size
    original = np.array([[0, width, width],[0, 0, height]])

    #solve for affine matrix
    solution = np.dot(original, inv(mapped))
    #unroll matrix into a sequence
    affine = (solution[0][0], solution[0][1], solution[0][2], solution[1][0], solution[1][1], solution[1][2])
    transformed = image.transform(background.size, Image.AFFINE, affine)
    white = Image.new("RGBA", (width, height), "white")
    transformedMask = white.transform(background.size, Image.AFFINE, affine)
    background.paste(transformed, (0,0), transformedMask)
    return background
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号