Search code examples
pythonopencvfingerprint

Incorrect image matching results despite differences (human fingerprints)


I want to use python to compared two images to check whether they are the same or not, I want to use this for fingerprint functionality in django app to validate whether the provided fingerprint is matches the one stored in the database. I have decided to use OpenCV for this purpose, utilizing ORB_create with detectAndCompute and providing the provided fingerprint to the BFMatcher. However, with the code below, when attempting to match the images, it consistently return True, while the provided images are not the same, along with the print statment "Images are the same".

def compared_fingerprint(image1, image2):

    finger1 = cv2.imread(image1, cv2.IMREAD_GRAYSCALE)
    finger2 = cv2.imread(image2, cv2.IMREAD_GRAYSCALE)

    orb = cv2.ORB_create()

    keypoints1, descriptors1 = orb.detectAndCompute(finger1, None)
    keypoints2, descriptors2 = orb.detectAndCompute(finger2, None)

    bf = cv2.BFMatcher()
    matches = bf.match(descriptors1, descriptors2)
    threshold = 0.7

    similar = len(matches) > threshold * len(keypoints1)

    if similar:
        print('Images are the same')
        return similar
    else:
        print('Images are not the same')
        return similar

result = compared_fingerprint('c.jpg', 'a.jpg')
print(result)

With the provided images, the function supposed to return the second statement, since, they are not the same, I thought, it was the threshold assign to 0.7, and when I increase the threshold to 1.7, it return the second statement saying: "Images are not the same" False, but when I try to make the images to be the same, I mean: result = compared_fingerprint('a.jpg', 'a.jpg'), it's still return "Images are not the same" False.

a.jpg

this is an a image

c.jpg

this is an c image


Solution

  • Fingerprints are matched using features specific to fingerprints. Fingerprints are mostly just ridges running in parallel, so that's boring. The interesting and identifying features are swirls (ridges curve around), ridge ends, short "island" segments (and their lengths), forks, ...

    https://en.wikipedia.org/wiki/Fingerprint#Fingerprint_verification

    Generic local feature descriptors may work but are not specific to fingerprints.

    You'll need to do the literature research to learn what feature descriptors have performed well on fingerprints.

    Features then need to match in a spatially consistent manner. Rotation and translation don't matter. Some stretching and even less shearing are tolerable. Perspective components are extrmely unlikely. If you estimate a transform, you'll need to assess how much it contorts.