Affine.py 文件源码

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

项目:nimo 作者: wolfram2012 项目源码 文件源码
def AffineFromPoints(src1,src2,dst1,dst2,new_size,filter=BILINEAR):
    ''' 
    An affine transform that will rotate, translate, and scale to map one 
    set of points to the other. For example, to align eye coordinates in face images.

    Find a transform (a,b,tx,ty) such that it maps the source points to the 
    destination points::

        a*x1-b*y1+tx = x2
        b*x1+a*y1+ty = y2

    The mapping between the two points creates a set of  four linear equations 
    with four unknowns. This set of equations is solved to find the transform.

    @param src1: the first link.Point in the source image.
    @param src2: the second link.Point in the source image.
    @param dst1: the first link.Point in the destination image.
    @param dst2: the second link.Point in the destination image.
    @param new_size: new size for the image.
    @param filter: PIL filter to use.
    '''

    # Compute the transformation parameters
    A = [[src1.X(),-src1.Y(),1,0],
         [src1.Y(),src1.X(),0,1],
         [src2.X(),-src2.Y(),1,0],
         [src2.Y(),src2.X(),0,1]]
    b = [dst1.X(),dst1.Y(),dst2.X(),dst2.Y()]
    A = array(A)
    b = array(b)
    result = solve(A,b)

    a,b,tx,ty = result    
    # Create the transform matrix
    matrix = array([[a,-b,tx],[b,a,ty],[0,0,1]],'d')

    return AffineTransform(matrix,new_size,filter)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号