'cv2.getPerspectiveTransform After the obtained matrix is transformed into point coordinates, the results obtained are incorrect
The code is as follows:
src = np.float32([[506,210],[1268,206],[1366,450],[ 258,460]])
dst = np.float32([[258, 210], [1366, 210], [1366, 460], [258, 460]])
dst = np.array(dst,dtype = 'float64')
src = np.array(src,dtype = 'float64')
matrix = cv2.getPerspectiveTransform(np.float32(src), np.float32(dst))
p = (506,210)
px = (matrix[0][0]*p[0] + matrix[0][1]*p[1] + matrix[0][2]) / ((matrix[2][0]*p[0] + matrix[2][1]*p[1] + matrix[2][2]))
py = (matrix[1][0]*p[0] + matrix[1][1]*p[1] + matrix[1][2]) / ((matrix[2][0]*p[0] + matrix[2][1]*p[1] + matrix[2][2]))
print(px,py)
s1 = np.array([[506,210,1]])
s11 = s1[:,:2]
print(s11)
print(np.dot(s1,matrix))
s2 = np.dot(s1,matrix)
s22 = s2[:,:2]
poly1 = Polygon(dst)
poly2 = Polygon(src)
ax = plt.gca()
ax.xaxis.set_ticks_position('top')
ax.invert_yaxis()
plt.plot(*poly1.exterior.xy)
plt.plot(*poly2.exterior.xy)
plt.plot([s11[0][0],ss1],[s11[0][1],ss2],'o')
plt.show()
The corresponding point of correct output should be at point 1, but the actual output is at point 2
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
