# Opencv and python: matchLOGOS not working

**URL:** <https://forum.opencv.org/t/opencv-and-python-matchlogos-not-working/15471>\
**Category:** Python\
**Tags:** xfeatures2d\
**Created:** [November 10, 2023, 2:18pm UTC](https://forum.opencv.org/t/opencv-and-python-matchlogos-not-working/15471 "2023-11-10T14:18:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![elephant](https://avatars.discourse-cdn.com/v4/letter/e/d2c977/32.png) [@elephant](https://forum.opencv.org/u/elephant)\
**Post date:** [November 10, 2023, 2:18pm UTC](https://forum.opencv.org/t/opencv-and-python-matchlogos-not-working/15471/1 "2023-11-10T14:18:57Z")

</div>

I am trying to use matchLOGOS from opencv 4.7.0 and Python 3. But it’s not going well. The [documentation](https://docs.opencv.org/4.7.0/db/dd9/group __xfeatures2d__ match.html) says it can be called like this in Python:

```auto
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. Here is some sample code:

```auto
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) # des1_closest[j] = cluster center label closest to des1[j] 
des2_closest = visualDict.predict(des2) # same
 
matches_LOGOS = []
matchLOGOS(kp1, kp2, des1_closest, des2_closest, matches_LOGOS )
print(matches_LOGOS)

```

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. Can someone please help? I can’t find any examples of matchLOGOS online.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [November 10, 2023, 2:50pm UTC](https://forum.opencv.org/t/opencv-and-python-matchlogos-not-working/15471/2 "2023-11-10T14:50:53Z")

</div>

i rather think, you’ve found a bug here.

are you able to (re-)build cv2, locally ?

[similar to this other issue](https://forum.opencv.org/t/no-output-from-denoise-tvl1-in-python/15042/5), the [function declaration here](https://github.com/opencv/opencv_contrib/blob/d51add39ebdb43663e717275078704143265fa08/modules/xfeatures2d/include/opencv2/xfeatures2d.hpp#L1270C1-L1273C1) should be changed to:

```auto
CV_EXPORTS_W void matchLOGOS(const std::vector<KeyPoint>& keypoints1, const std::vector<KeyPoint>& keypoints2,
                             const std::vector<int>& nn1, const std::vector<int>& nn2,
                             CV_OUT std::vector<DMatch>& matches1to2);

```

after a rebuild, the resulting py signature should look like:

`cv.xfeatures2d.matchLOGOS( keypoints1, keypoints2, nn1, nn2 [, matches1to2] ) -> result # returns matches now`

---

<div class="post-metadata">

**Author:** ![elephant](https://avatars.discourse-cdn.com/v4/letter/e/d2c977/32.png) [@elephant](https://forum.opencv.org/u/elephant)\
**Post date:** [November 10, 2023, 3:02pm UTC](https://forum.opencv.org/t/opencv-and-python-matchlogos-not-working/15471/3 "2023-11-10T15:02:58Z")

</div>

Thanks berak! I’ve never re-built cv2 locally, but I can give it a try. Do you recommend a link that explains how to do it?

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [November 10, 2023, 3:11pm UTC](https://forum.opencv.org/t/opencv-and-python-matchlogos-not-working/15471/4 "2023-11-10T15:11:16Z")

</div>

if it’s linux, [this will also build py bindings](https://docs.opencv.org/4.7.0/d7/d9f/tutorial_linux_install.html)
