OpenCV Python - 使用RANSAC的findHomography

时间:2016-06-17 20:55:51

标签: python opencv

我尝试使用RANSAC运行findHomography(),但我收到了TypeError。当我根本没有指定方法时,我的代码会起作用,但即使method=0也会导致TypeError。

代码

    T, mask = cv2.findHomography(points_subset[i], points_subset[i+1], False, method=cv2.RANSAC)

错误

Traceback (most recent call last):
  File "stab.py", line 368, in <module>
    stabilize_video(path, video_name)
  File "stab.py", line 331, in stabilize_video
    transforms, points, frame = calc_transformations(cap)
  File "stab.py", line 113, in calc_transformations
    T, mask = cv2.findHomography(points_subset[i], points_subset[i+1], False, method=cv2.RANSAC)
TypeError: Argument given by name ('method') and position (3)

1 个答案:

答案 0 :(得分:3)

您的错误正在发生,因为您尝试两次指定method参数;一次作为位置参数,再次作为关键字参数。可以删除False参数以更正错误。如果您正在尝试使用RANSAC来查找单应性,则正确的调用如下所示:

T, mask = cv2.findHomography(points_subset[i], points_subset[i+1], method=cv2.RANSAC)
相关问题