Я пытаюсь сравнить два изображения, но постоянно получаю ошибки в python, там написано:
matches = flann.knnMatch(des1,des2, k=2)
cv2.error: OpenCV(3.4.2) /home/pi/opencv
python/opencv/modules/flann/src/miniflann.cpp:487: error: (-215:Assertion failed)
(size_t)knn <= index_->size() in function 'runKnnSearch_'```
ниже приведен код:
# Create Sift
sift = cv2.xfeatures2d.SIFT_create()
kp_1, desc_1 = sift.detectAndCompute(original, None)
index_params = dict(algorithm=0, trees=15)
search_params = dict()
**flann = cv2.FlannBasedMatcher(index_params, search_params)** >Is this correct
# Load all images into array
all_images_to_compare = []
titles = []
for f in glob.iglob("/home/pi/dataset/*"):
image = cv2.imread(f)
titles.append(f)
all_images_to_compare.append(image)
for image_to_compare, title in zip(all_images_to_compare, titles):
# 1) Check if 2 images are equals
if original.shape == image_to_compare.shape:
print("The images have same size and channels")
difference = cv2.subtract(original, image_to_compare)
b, g, r = cv2.split(difference)
if cv2.countNonZero(b) == 0 and cv2.countNonZero(g) == 0 and cv2.countNonZero(r) == 0:
print ("Similarity: 100% (equal size and channels)")
#2) Check for similarities between the 2 images
kp_2, desc_2 = sift.detectAndCompute(image_to_compare, None)
**matches = flann.knnMatch(desc_1, desc_2, k=2)** > error occurs here