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

I am getting this error


`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.
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

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.

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

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.