Problem: AttributeError: Module ‘cv2.cv2’ has no attribute ‘estimateRigidTransform’ The reason for this problem may be that the version of OpencV is too high and the estimateRigidTransform method does not exist. After checking the document, we can find that this method has been abandoned, as shown in the following statement.
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.
Copy the code
According to the statement, we can use estimateAffine2D and estimateAffinePartial2D instead, but which method should be selected instead? We also need to look at the value of fullAffine, the third parameter of the estimateRigidTransform method.
- FullAffine true represents the affine transformation of six degrees of freedom, and the corresponding method is estimateAffine2D
- FullAffine false represents the affine transformation with four degrees of freedom, and the corresponding method is estimateAffinePartial2D
Note: The estimateAffine2D and estimateAffinePartial2D methods require two return values. The first return value corresponds to the return value of the method estimateRigidTransform, and the second return value represents the inner point Inliers. Its exact role is unknown.
I modified it directly:
mat_,inlier = cv2.estimateAffine2D(org_pts, target_pts)
Copy the code