您误解了cv2.multiply()的目的。它用于图像相乘,并且逐点相乘,所以如果A=cv2,则相乘(B,C)则
ai,j=bi,j*ci,j
对我来说,j
要进行正确的矩阵乘法,您需要使用功能强大但复杂的cv2.gemm(),或者使用生成的转换是一个numpy数组并使用内置的dot()函数import numpy as np
import cv2
# test images
img1 = np.zeros((600,600,3),np.uint8)
img1[:] = (255,255,255)
cv2.fillConvexPoly( img1,np.array([(250,50),(350,50),(350,550),(250,550)],np.int32), (0,0,255) )
img2 = img1.copy()
# source and destination coordinates
src = np.array([[0,0],[0,480],[640,480],[640,0]],np.float32)
dst = np.array([[-97,-718],[230,472],[421,472],[927,-717]],np.float32)
# transformation matrix
retval = cv2.getPerspectiveTransform(src, dst);
# test1 is wrong, test2 is the application of the transform twice
test1 = cv2.multiply(retval.copy(),retval.copy())
test2 = cv2.gemm(retval,retval,1,None,0)
# test3 is using matrix-multiplication using numpy
test3 = retval.dot(retval)
img2 = cv2.warpPerspective(img1,test2,(640,480))
img3 = cv2.warpPerspective(img1,test3,(640,480))
img4 = cv2.warpPerspective(img1,retval,(640,480))
img4 = cv2.warpPerspective(img4,retval,(640,480))
cv2.imshow( "one application of doubled transform", img2 )
cv2.imshow( "one applications using numpy", img3 )
cv2.imshow( "two applications of single transform", img4 )
cv2.waitKey()
请注意,cv2变换是从左开始的,因此,如果要应用A然后B则必须应用B点(A)作为组合。在