【问题标题】:Combining two warpAffine, shift and rotate image结合两个warpAffine,移位和旋转图像
【发布时间】:2019-01-30 23:23:54
【问题描述】:

我目前使用以下代码序列首先移动图像,然后旋转同一图像:

M = np.float32([[1,0,20],[0,1,10]])
shifted = cv2.warpAffine(img,M,(y_size,x_size),flags=cv2.INTER_LANCZOS4)
center_of_rot = (500, 500)
M = cv2.getRotationMatrix2D(center_of_rot, 1.23, 1.0)
rotated = cv2.warpAffine(shifted, M, (y_size, x_size),flags=cv2.INTER_LANCZOS4)

我认为有可能以某种方式将两个矩阵相乘并且只做一个操作而不是两个 warpAffine,我正在寻找一些指导,因为我的数学真的很烂。

谢谢!

【问题讨论】:

    标签: python numpy opencv


    【解决方案1】:

    您必须将矩阵相乘。将第三行 [0,0,1] 添加到 2x3 矩阵。这称为齐次坐标。

    M = np.float32([[1,0,20],[0,1,10],[0,0,1]]) // shift matrix
    center_of_rot = (500, 500)
    Rot = cv2.getRotationMatrix2D(center_of_rot, 1.23, 1.0)
    Rot = np.vstack([Rot, [0,0,1]])
    TransfomMatrix = np.matmul(M, Rot)
    rotated = cv2.warpPerspective(img, TransformMatrix, (y_size, x_size),flags=cv2.INTER_LANCZOS4) //  note - warpPerspective is used here, because the matrix is now 3x3 not 3x2
    

    【讨论】:

      猜你喜欢
      • 2011-12-10
      • 1970-01-01
      • 1970-01-01
      • 2012-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多