图像旋转:如何求非方矩阵的逆?

2024-05-14 18:39:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我剪下一个动物的图像,对齐它,修改它,然后我想把它粘贴回原始图像。因此,工作流程如下所示:

原始图像:
Original image

检测到动物:
Animal detected

动物对齐:
Animal aligned

提取的动物:
Animal extracted

改良动物:
Modified Animal

重新配餐的动物:
Repasted Animal

我有检测和校准动物的代码:

# 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

如何将猫头鹰放回原始图像


Tags: ofthe代码图像get粘贴流程cv2
1条回答
网友
1楼 · 发布于 2024-05-14 18:39:34

添加第三行[0,0,1]。这会使乘积y = A x成为一个二维齐次向量(即一个包含三个分量的向量),其前两个分量与未添加行时相同

相关问题 更多 >

    热门问题