Fingerprint comparision fails ( in 1 to 1)

I have 2 finger prints, They are of the same person/finger.

I cannot figure out what is wrong with the below code.

import os
import cv2
sample = cv2.imread(“1.jpg”, cv2.IMREAD_GRAYSCALE)
best_score = 0
filename = None
image = None
kp1, kp2, mp = None, None, None
fingerprint_image = cv2.imread(“a.jpg”, cv2.IMREAD_GRAYSCALE)

sift = cv2.SIFT_create()
keypoints_1, descriptors_1 = sift.detectAndCompute(sample, None)
keypoints_2, descriptors_2 = sift.detectAndCompute(fingerprint_image, None)

matches = cv2.FlannBasedMatcher({‘algorithm’: 1, ‘trees’: 10},
{}).knnMatch(descriptors_1, descriptors_2, k=2)

match_points =

for p, q in matches:
if p.distance < 0.1 * q.distance:
match_points.append(p)

keypoints = 0
if len(keypoints_1) < len(keypoints_2):
keypoints = len(keypoints_1)
else:
keypoints = len(keypoints_2)

if len(match_points) / keypoints * 100 > best_score:
best_score = len(match_points) / keypoints * 100
image = fingerprint_image
kp1, kp2, mp = keypoints_1, keypoints_2, match_points

print(“Score:” + str(best_score))

#result = cv2.drawMatches(sample, kp1, image, kp2, mp, None)
cv2.imshow(“result”, result)
cv2.waitKey(0)
cv2.destroyAllWindows()

img 1 : https://ibb.co/QvsSQLb
img a : https://ibb.co/k6VwhMD

it’s correct syntax :wink:
however, the ideas behind it are poorly copypasted cargo-cult code, it wont work, ‘as-is’.

  • minutiae are ‘repeating’ textures, you’d need quite a large ‘input field’ to find asymmetries (bad with feature2D things at all !)
  • SIFT tries to be 'rotation invariant. means: a < and a v result in same feature pattern (BAD here !)
  • the ratio of matches to overall features, on its own, is a poor similarity measure. the actual distance between features could be 0.1 or 10000, it does not respect this
1 Like

Lowe’s ratio test usually uses a less drastic ratio.

1 Like

Thank you very much for your reply, I wanted it to work “as-is” so that I can start tweaking and learning ( empirically).

If you don’t mind, May you please elaborate on the 3 points ( like i’m a 5 years old :face_with_peeking_eye: )

Thank you, for your reply, I think i will read more about https://www.cs.ubc.ca/~lowe/papers/ijcv04.pdf

Would you say this would point in the right direction