简体   繁体   中英

python OpenCV(3.4.2) error: (-215:Assertion failed)

I'm trying to use the SIFT descriptors for image matching. I am planning to match one image with another.

This is the code with which I am trying to make the match

sift = cv2.xfeatures2d.SIFT_create()

kp_1, desc_1 = sift.detectAndCompute(original, None)
kp_2, desc_2 = sift.detectAndCompute(image_to_compare, None)
index_params = dict(algorithm=0, trees=5)
search_params = dict()
flann = cv2.FlannBasedMatcher(index_params, search_params)
matches = flann.knnMatch(desc_1, desc_2, k=2)

but I get the following error:

<ipython-input-6-1f81512d446c> in AlgSift(imagen, imagentocompare, umbral)
   21     search_params = dict()
   22     flann = cv2.FlannBasedMatcher(index_params, search_params)
---> 23     matches = flann.knnMatch(desc_1, desc_2, k=2)
   24 
   25 


   error: OpenCV(3.4.2) /io/opencv/modules/flann/src/miniflann.cpp:487: error: 
   (-215:Assertion failed) (size_t)knn <= index_->size() in function 
   'runKnnSearch_'

An error such as Assertion failed occurred in my case because the position of the image to be loaded was not correct. Please check your storage location and code once.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM