import cv2
import numpy as np
import sys
from IPython.display import Image
from matplotlib import pyplot as plt
import numpy
import os
img = cv2.imread('C:\\Users\\not-cropped.jpg')
gray= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
search_params = dict(checks = 50)
FLANN_INDEX_LSH = 6
index_params= dict(algorithm = FLANN_INDEX_LSH,
table_number =12 , # 12
key_size = 20, # 20
multi_probe_level = 2) #2
# Initiate STAR detector
star = cv2.xfeatures2d.StarDetector_create()
# Initiate BRIEF extractor
brief = cv2.xfeatures2d.BriefDescriptorExtractor_create()
# find the keypoints with STAR
kp_brief_o = star.detect(gray,None)
# compute the descriptors with BRIEF
kp_brief_o, des_brief_o = brief.compute(gray, kp_brief_o)
img66 = cv2.drawKeypoints(gray,kp_brief_o,None,(255,0,0),4)
plt.imshow(img66),plt.show()
##########################################################33
gray_crop = cv2.imread('C:\\Users\\cropped.jpg', 0)
kp_brief_crop = star.detect(gray_crop,None)
kp_brief_crop, des_brief_crop = brief.compute(gray_crop, kp_brief_crop)
flann = cv2.FlannBasedMatcher(index_params, search_params)
matches = flann.knnMatch(des_brief_o, des_brief_crop, k=2)
good = []
for m,n in matches:
if m.distance < 0.7*n.distance:
good.append(m)
i want to compare an image to another using star as descriptor and brief to detect descriptors, it works as intended on some images, but on others like the attached 2, it will throw an exception although the second is a crop of the first, and it would even throw that same exception when an image is totally different.
Error:
ValueError Traceback (most recent call last)
<ipython-input-56-9685f4afabba> in <module>
44
45 good = []
---> 46 for m,n in matches:
47 if m.distance < 0.7*n.distance:
48 good.append(m)
ValueError: not enough values to unpack (expected 2, got 1)
images:
main
cropped
unrelated pic where i'd still get the error