# FlannBasedMatcher raises (-215:Assertion failed) query.type() == type && indices.type() == CV\_32S && dists.type() == dtype in function 'runKnnSearch\_'

**URL:** <https://forum.opencv.org/t/flannbasedmatcher-raises-215-assertion-failed-query-type-type-indices-type-cv-32s-dists-type-dtype-in-function-runknnsearch/13407>\
**Category:** Python\
**Tags:** features2d\
**Created:** [June 5, 2023, 4:47am UTC](https://forum.opencv.org/t/flannbasedmatcher-raises-215-assertion-failed-query-type-type-indices-type-cv-32s-dists-type-dtype-in-function-runknnsearch/13407 "2023-06-05T04:47:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mina\_Samy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/mina_samy/32/8009_2.png) [@Mina\_Samy](https://forum.opencv.org/u/Mina_Samy)\
**Post date:** [June 5, 2023, 4:47am UTC](https://forum.opencv.org/t/flannbasedmatcher-raises-215-assertion-failed-query-type-type-indices-type-cv-32s-dists-type-dtype-in-function-runknnsearch/13407/1 "2023-06-05T04:47:11Z")

</div>

I am getting this error

```auto

`error: (-215:Assertion failed) query.type() == type && indices.type() == CV_32S && dists.type() == dtype in function 'runKnnSearch_'`

```

I am using Python 3.8, opencv-python==4.7.0

My task is to check if an icon is in a screenshot or not. If it is there return its location. I’ve found that opencv can get this job done.

My approach is:

1. Get the keypoints and descriptors using ORB and SIFT, and return which has more keypoints.

```auto
kp_orb = orb.detect(image,None)
kp_orb, des_orb = orb.compute(image, kp_orb)
kp_sift, des_sift = sift.detectAndCompute(image,None)
if (len(kp_orb) > len(kp_sift)):
    return (kp_orb,des_orb, "ORB")
return (kp_sift, des_sift, "SIFT")

```

1. Using FLANN\_KDTREE to get the matching keypoints, I got the error provided above

Here is my FLANN code block

```auto
FLANN_INDEX_KDTREE = 1
index_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5)
search_params = dict(checks=100)
flann = cv.FlannBasedMatcher(index_params,search_params)
matches = flann.knnMatch(des_query,des_target,k=2)

```

I think this gets the error because SIFT returns descriptors in a type different from what ORB returns, but I am not sure of that because I am a total beginner in this field.

Would you please tell me how to fix this error or if there is a better overall approach please provide an outline and I will make my way through.

Thank you.

---

<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:** [June 5, 2023, 7:10am UTC](https://forum.opencv.org/t/flannbasedmatcher-raises-215-assertion-failed-query-type-type-indices-type-cv-32s-dists-type-dtype-in-function-runknnsearch/13407/2 "2023-06-05T07:10:43Z")

</div>

apart from your current problems,  
this won’t work ever, as you want it,  
feature matching was NOT made for this purpose

have a look at  
[https://docs.opencv.org/4.x/de/da9/tutorial\_template\_matching.html](https://docs.opencv.org/4.x/de/da9/tutorial_template_matching.html)

---

<div class="post-metadata">

**Author:** ![Mina\_Samy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/mina_samy/32/8009_2.png) [@Mina\_Samy](https://forum.opencv.org/u/Mina_Samy)\
**Post date:** [June 6, 2023, 5:28am UTC](https://forum.opencv.org/t/flannbasedmatcher-raises-215-assertion-failed-query-type-type-indices-type-cv-32s-dists-type-dtype-in-function-runknnsearch/13407/3 "2023-06-06T05:28:26Z")

</div>

Isn’t template matching require that the size of the query image be the same as in the query image in the target image?  
I mean if the icon is taken from another machine, I cannot make sure that the size of the icon is the same in the screenshot.

Thanks for your help.
