(src_pts, dst_pts)
return tfm
Function:
    ----------
        get affine transform matrix 'tfm' from src_pts to dst_pts
    Parameters:
    ----------
        @src_pts: Kx2 np.array
            source points matrix, each row is a pair of coordinates (x, y)
        @dst_pts: Kx2 np.array
            destination points matrix, each row is a pair of coordinates (x, y)
    Returns:
    ----------
        @tfm: 2x3 np.array
            transform matrix from src_pts to dst_pts
Function:
    ----------
        get affine transform matrix 'tfm' from src_pts to dst_pts
    Parameters:
    ----------
Function : ---------- get affine transform matrix tfm from src_pts to dst_pts Parameters : ----------
def get_affine_transform_matrix(src_pts, dst_pts):
    """
    Function:
    ----------
        get affine transform matrix 'tfm' from src_pts to dst_pts
    Parameters:
    ----------
        @src_pts: Kx2 np.array
            source points matrix, each row is a pair of coordinates (x, y)
        @dst_pts: Kx2 np.array
            destination points matrix, each row is a pair of coordinates (x, y)
    Returns:
    ----------
        @tfm: 2x3 np.array
            transform matrix from src_pts to dst_pts
    """

    tfm = np.float32([[1, 0, 0], [0, 1, 0]])
    n_pts = src_pts.shape[0]
    ones = np.ones((n_pts, 1), src_pts.dtype)
    src_pts_ = np.hstack([src_pts, ones])
    dst_pts_ = np.hstack([dst_pts, ones])

#    #print(('src_pts_:\n' + str(src_pts_))
#    #print(('dst_pts_:\n' + str(dst_pts_))

    A, res, rank, s = np.linalg.lstsq(src_pts_, dst_pts_)

#    #print(('np.linalg.lstsq return A: \n' + str(A))
#    #print(('np.linalg.lstsq return res: \n' + str(res))
#    #print(('np.linalg.lstsq return rank: \n' + str(rank))
#    #print(('np.linalg.lstsq return s: \n' + str(s))

    if rank == 3:
        tfm = np.float32([
            [A[0, 0], A[1, 0], A[2, 0]],
            [A[0, 1], A[1, 1], A[2, 1]]
        ])
    elif rank == 2:
        tfm = np.float32([
            [A[0, 0], A[1, 0], 0],
            [A[0, 1], A[1, 1], 0]
        ])

    return tfm
def get_affine_transform_matrix ( src_pts , dst_pts ) : tfm = np . float32 ( [ [ 1 , 0 , 0 ] , [ 0 , 1 , 0 ] ] ) n_pts = src_pts . shape [ 0 ] ones = np . ones ( ( n_pts , 1 ) , src_pts . dtype ) src_pts_ = np . hstack ( [ src_pts , ones ] ) dst_pts_ = np . hstack ( [ dst_pts , ones ] ) #    #print(('src_pts_:\n' + str(src_pts_)) #    #print(('dst_pts_:\n' + str(dst_pts_)) A , res , rank , s = np . linalg . lstsq ( src_pts_ , dst_pts_ ) #    #print(('np.linalg.lstsq return A: \n' + str(A)) #    #print(('np.linalg.lstsq return res: \n' + str(res)) #    #print(('np.linalg.lstsq return rank: \n' + str(rank)) #    #print(('np.linalg.lstsq return s: \n' + str(s)) if rank == 3 : tfm = np . float32 ( [ [ A [ 0 , 0 ] , A [ 1 , 0 ] , A [ 2 , 0 ] ] , [ A [ 0 , 1 ] , A [ 1 , 1 ] , A [ 2 , 1 ] ] ] ) elif rank == 2 : tfm = np . float32 ( [ [ A [ 0 , 0 ] , A [ 1 , 0 ] , 0 ] , [ A [ 0 , 1 ] , A [ 1 , 1 ] , 0 ] ] ) return tfm