我正在剪下一张动物的图像,对其进行对齐、修改,然后我想将其粘贴回原始图像中。所以工作流程是这样的:
我有检测和对齐动物的代码:
# get rotation matrix
M = cv2.getRotationMatrix2D(eyesCenter, angle, scale)
# update the translation component of the matrix
tX = w * 0.5
tY = h * LeftEye[1]
M[0, 2] += (tX - eyesCenter[0])
M[1, 2] += (tY - eyesCenter[1])
# apply the affine transformation
output = cv2.warpAffine(image, M, (w, h), flags=cv2.INTER_CUBIC)
我尝试使用
Mp = np.linalg.inv(M)
但我收到错误:
Last 2 dimensions of the array must be square
如何将猫头鹰放回原始图像?
答案 0 :(得分:1)
添加第三行 [0, 0, 1]。这会使乘积 y = A x
成为一个二维齐次向量(即一个具有三个分量的向量),其前两个分量与您没有添加行一样。