def _get_transform_matrix(src_pts, dst_pts):
#tfm = cv2.getAffineTransform(pts_src[0:3], pts_dst[0:3])
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))
# tfm = np.float32([
# [A[0,0], A[0,1], A[2, 0]],
# [A[1,0], A[1,1], A[2, 1]]
# ])
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
~fx_transform_and_crop_face.py 文件源码
python
阅读 23
收藏 0
点赞 0
评论 0
评论列表
文章目录