0

First of all, sorry for the title, I didn't know how to name it.

Now, I am using openCV to compare 2 images.

The code has been taken from here: https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_feature2d/py_matcher/py_matcher.html#flann-based-matcher

So in my code I have:

orb = cv2.ORB_create()
kp1, des1 = orb.detectAndCompute(image, None)

This is for the descriptors/keypoints to be calculated.

For the Flann matcher I have the following:

FLANN_INDEX_LSH = 6
index_params = dict(algorithm=FLANN_INDEX_LSH, trees=5)
search_params = dict(checks=50)
flann = cv2.FlannBasedMatcher(index_params, search_params)

And this is the same code for the second image:

kp2, des2 = orb.detectAndCompute(image2, None)
matches = flann.knnMatch(des1, des2, k=2)

And I also saw on some sources that this is how to achieve Lowe's ratio test:

good = []
for m_n in matches:
    if len(m_n) != 2:
        continue
    (m, n) = m_n
    if m.distance < acc * n.distance:
        good.append(m)

Later I concat both images doing this:

matches = [item for sublist in matches for item in sublist] 
#This is needed because matches is a list of lists.
img3 = cv2.drawMatches(image, kp1, target, kp2, matches[:20], None, flags=2)
img4 = cv2.drawMatches(image, kp1, target, kp2, good[:20], None, flags=2)

And I get this image as result:

enter image description here

The upper half is what matches has, and the other is good.

Could you explain me what is the difference between both please? I have looked here and there and I still don't know what I am doing to build good, and is sad just copy pasting some code without knowing what is it.

Azazel
  • 183
  • 1
  • 1
  • 10
  • What value is acc? Where did you set that? The reference uses 0.7. You could try to make it smaller to restrict more matches to get better correspondence. Or you could filter to keep only small y differences to keep only horizontal lines. – fmw42 Aug 24 '19 at 17:09
  • i set acc to 0.7 – Azazel Aug 24 '19 at 18:33

0 Answers0