问题全部为:
cv2.error: OpenCV(4.2.0) /io/opencv/modules/imgproc/src/imgwarp.cpp:3391: error: (-215:Assertion failed) src.checkVector(2, CV_32F) == 4 && dst.checkVector(2, CV_32F) == 4 in function 'getPerspectiveTransform'
出现在使用cv2.getPerspectiveTransform()函数时。
如果默认传入getPerspectiveTransform函数的数组的编码是float64的则会报错,需要修改为float32编码。
报错代码
import numpy as np
import cv2
points = np.array([[131., 27.], [380., 27.], [380., 58.], [131., 58.]])
pts_std = np.array([[0., 0.], [249., 0.], [249., 31.], [0., 31.]])
M = cv2.getPerspectiveTransform(points, pts_std)
修改后
import numpy as np
import cv2
points = np.array([[131., 27.], [380., 27.], [380., 58.], [131., 58.]], dtype="float32")
pts_std = np.array([[0., 0.], [249., 0.], [249., 31.], [0., 31.]], dtype="float32")
M = cv2.getPerspectiveTransform(points, pts_std)