H, _ = cv2.findHomography(pts2, pts1, cv2.RANSAC) cv2.error: OpenCV(4.5.5) :-1: error: (-5:Bad argument) in function 'findHomography' > Overload resolution failed: > - srcPoints is not a numpy array, neither a scalar > - Expected Ptr<cv::UMat> for argument 'srcPoints' > - srcPoints is not a numpy array, neither a scalar > - Expected Ptr<cv::UMat> for argument 'srcPoints' 进程已结束,退出代码1
时间: 2024-03-13 18:45:34 浏览: 122
这个错误可能是由于pts1和pts2不是numpy数组导致的。请确保将pts1和pts2转换为numpy数组,如下所示:
```python
import numpy as np
# 提取匹配到的关键点的坐标
pts1 = []
pts2 = []
for match in matches:
pts1.append(kp1[match.queryIdx].pt)
pts2.append(kp2[match.trainIdx].pt)
# 转换为numpy数组
pts1 = np.array(pts1)
pts2 = np.array(pts2)
# 计算变换矩阵
H, _ = cv2.findHomography(pts2, pts1, cv2.RANSAC)
```
如果仍然存在问题,请检查pts1和pts2的形状是否正确。它们应该是形状为(N, 2)的numpy数组,其中N是关键点的数量。
阅读全文