我想在某些单独的(x,y)点上使用相同的仿射矩阵M,就像我在cv2.warpAffine的图像上使用的那样。似乎cv2.transform是要走的路。当我尝试发送一个Nx2点的矩阵时,我得到了否定(
src = np.array([
[x1,y1],[x2,y2],[x3,y3],[x4,y4]], dtype = "float32")
print('source shape '+str(src.shape))
dst=cv2.transform(src,M)
cv2.error: /home/jeremy/sw/opencv-3.1.0/modules/core/src/matmul.cpp:1947: error: (-215) scn == m.cols || scn + 1 == m.cols in function transform
我可以使用numpy算法得到我想要的变换:
dst = np.dot(src,M[:,0:2]) +M[:,2]
print('dest:{}'.format(dst))
但是想了解最新情况。文档说cv2.transform想要多个频道等于M中的列数,但我不清楚频道是什么 - 也许是' x'频道和' y'通道,但那么第三个会是什么,不同的行会表示什么?
答案 0 :(得分:5)
Python上的OpenCV通常需要表单中的点
np.array([ [[x1, y1]], ..., [[xn, yn]] ])
documentation for cv2.transform()
中不清楚这一点,但在使用点的其他函数的文档中更清楚,例如cv2.perspectiveTransform()
,他们提到坐标位于不同的通道上:
src - 输入双通道或三通道浮点数组
变换也可以在3D中使用(使用4x4
透视变换矩阵),这样就可以解释在cv2.transform()
中使用双或三通道数组的能力