-
Notifications
You must be signed in to change notification settings - Fork 5.9k
matchLOGOS not working with Python #3589
Description
System Information
OpenCV version: 4.7.0
Operating System: CentOS 7
Python version: 3.10.12, GCC 12.3.0
Detailed description
I am trying to use matchLOGOS from opencv 4.7.0 and Python 3. But it's not going well. The documentation says it can be called like this in Python:
cv.xfeatures2d.matchLOGOS( keypoints1, keypoints2, nn1, nn2, matches1to2 ) -> None
where
keypoints1 Input keypoints of image1.
keypoints2 Input keypoints of image2.
nn1 Index to the closest BoW centroid for each descriptors of image1.
nn2 Index to the closest BoW centroid for each descriptors of image2.
matches1to2 Matches returned by the LOGOS matching strategy.
So unlike most functions, the output, matches1to2, is modified in-place and the function returns None. But I'm not getting any results, even with my 2 images are exactly the same.
The result is just matches_LOGOS = []. Or if I initialize matches_LOGOS = None I get back matches_LOGOS = None. If I don't initialize matches_LOGOS at all, an error says matches_LOGOS is not declared. I'm thinking the problem is related to the in-place nature of the function, and Python's api to cv2 isn't handling it right.
Steps to reproduce
import cv2
from sklearn.cluster import KMeans
from cv2.xfeatures2d import matchLOGOS
from skimage import data
im1 = (getattr(data,'cat')())[:,:,0].astype(np.uint8) # cat image
im2 = im1.copy() # same exact image
sift = cv2.SIFT_create()
kp1, des1 = sift.detectAndCompute(im1, None)
kp2, des2 = sift.detectAndCompute(im2, None)
# create visual_dict from des1
visualDict = KMeans(n_clusters=256, init='k-means++', tol=0.0001, n_init=10, verbose=0).fit(des1)
des1_closest = visualDict.predict(des1) # index of cluster center closest to each point in des1
des2_closest = visualDict.predict(des2) # index of cluster center closest to each point in des2
matches_LOGOS = []
matchLOGOS(kp1, kp2, des1_closest, des2_closest, matches_LOGOS )
print('total LOGOS Matches:',len(matches_LOGOS))Issue submission checklist
- I report the issue, it's not a question
- I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- I updated to the latest OpenCV version and the issue is still there
- There is reproducer code and related data files (videos, images, onnx, etc)