TypeError: FlannBasedMatcher() takes no arguments
时间: 2024-02-01 19:16:03 浏览: 60
The error message "TypeError: FlannBasedMatcher() takes no arguments" indicates that you are trying to pass an argument to the FlannBasedMatcher constructor, but this class does not accept any arguments.
To solve this problem, you should remove the argument that you are passing to FlannBasedMatcher. Here is an example of how to create a FlannBasedMatcher object correctly:
```
import cv2
# Load images
img1 = cv2.imread('image1.jpg', 0)
img2 = cv2.imread('image2.jpg', 0)
# Initiate SIFT detector
sift = cv2.xfeatures2d.SIFT_create()
# Detect keypoints and compute descriptors
kp1, des1 = sift.detectAndCompute(img1, None)
kp2, des2 = sift.detectAndCompute(img2, None)
# Initiate FlannBasedMatcher
matcher = cv2.FlannBasedMatcher()
# Match descriptors
matches = matcher.knnMatch(des1, des2, k=2)
# Apply ratio test
good_matches = []
for m, n in matches:
if m.distance < 0.75 * n.distance:
good_matches.append(m)
# Draw matches
img_matches = cv2.drawMatches(img1, kp1, img2, kp2, good_matches, None, flags=cv2.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS)
cv2.imshow("Matches", img_matches)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
Here, we create a FlannBasedMatcher object without passing any arguments to it.
阅读全文