opencv图像仿射变换后原坐标点在新图像中的坐标

M = cv2.getRotationMatrix2D((cX, cY), -angle, a)
cos = np.abs(M[0, 0])
sin = np.abs(M[0, 1])

nW = int((h * sin) + (w * cos))
nH = int((h * cos) + (w * sin))

M[0, 2] += (nW / 2) - cX
M[1, 2] += (nH / 2) - cY
    cv2.warpAffine(image, M, (nW, nH),borderValue=(255,255,255))
x=371#设原坐标为(371,68)
y=68
x=int(M[0,0]*x+M[0,1]*y+M[0,2])
y=int(M[1,0]*x+M[1,1]*y+M[1,2])
point=(x,y)
    point是我根据变换矩阵M得出的新坐标,但与实际效果不符,求原因。

https://blog.csdn.net/watkinsong/article/details/10212715

    M = cv2.getAffineTransform(marker_pos, dst_temp) #输出(2,3)矩阵
    #  
    pts = np.float32(map_point).reshape([-1,2])#要映射的点
    pts = np.hstack([pts,np.ones([len(pts),1])]).T
    target_point = np.dot(M,pts)#映射后的坐标

注意一下你的x在算y的时候变了

new_x=int(M[0,0]*x+M[0,1]*y+M[0,2])
new_y=int(M[1,0]*x+M[1,1]*y+M[1,2])  

在对一个原图像中的像素的坐标进行计算仿射变换之后的坐标的时候,一定要按照仿射变换的基本原理,将原来的坐标减去仿射变换的旋转中心的坐标,这样仿射变换之后得到的坐标再加上仿射变换旋转中心坐标才是原坐标在新的仿射变换之后的图像中的正确坐标。