解决AttributeError: module ‘cv2.cv2‘ has no attribute ‘estimateRigidTransform‘

问题: AttributeError: module ‘cv2.cv2’ has no attribute ‘estimateRigidTransform’
分析: 出现该问题的原因可能是opencv的版本太高,不存在estimateRigidTransform方法,查看文档后我们可以发现,该方法已被弃用,如下表述所示。

Deprecated:
Use cv::estimateAffine2D, cv::estimateAffinePartial2D instead. 
If you are using this fuction with images, extract points using
cv::calcOpticalFlowPyrLK and then use the estimation fuctions.

根据表述我们可以使用estimateAffine2DestimateAffinePartial2D两个方法代替使用,但是到底应该选择哪一个方法进行替代,还需要看estimateRigidTransform方法的第三个参数fullAffine的取值。

  • fullAffine为true表示的是六自由度的仿射变换,对应的方法为estimateAffine2D
  • fullAffine为false表示的是四自由度的仿射变换,对应的方法为estimateAffinePartial2D

注意: 使用estimateAffine2DestimateAffinePartial2D方法需要两个返回值,第一个返回值对应的是方法estimateRigidTransform的返回值,第二个返回值表示的是内点inliers,它的具体作用尚未得知。

我是直接修改的:

mat_,inlier = cv2.estimateAffine2D(org_pts, target_pts)

欢迎关注公众号:算法工程师的学习日志,获取算法工程师的学习资料。如果有技术咨询,提供有偿咨询,联系qq(1762016542)或者公众号留言

猜你喜欢

转载自blog.csdn.net/qingfengxd1/article/details/109099556#comments_21847928